Fix: guard Categories access in extract_capec_names (Issue #2487)#2517
Fix: guard Categories access in extract_capec_names (Issue #2487)#2517immortal71 wants to merge 3 commits intoOWASP:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds defensive handling in extract_capec_names to avoid crashing when CAPEC catalog JSON is missing or has malformed Categories data, while still extracting names from Attack_Pattern entries.
Changes:
- Guard access to
catalog["Categories"]["Category"]with presence/type checks. - Emit warnings (instead of raising) when
Categories/Categoryis missing or malformed, then continue processing.
|
@sydseter the pr is ready for review !! |
|
@immortal71 there are a couple of good suggestions by @copilot code review[agent] that are worth implementing. Could you look at expanding the test coverage to cover the abuse cases that your code corrects? |
|
@rewtd done, is this good to go ? |
|
@immortal71 You have merge conflicts here. |
|
@sydseter giveme some time I will resolve the conflict |
|
@sydseter is this good to go ? |
|
@immortal71 you have a reformating issue. |
|
@immortal71 There are some conflicts here after I merged some of your other work. |
|
@sydseter is this good to go !! |
|
@immortal71 you have a test failure. |
|
@sydseter is this good to go ? |
|
@immortal71 your commits are lacking a verified signature. |
There was a problem hiding this comment.
Please revert the changes in this file.
7d7d10c to
f9b3553
Compare
|
@sydseter is this good to go ?? I have implemented as you have suggested !! |
Problem: scripts/capec_map_enricher.py raised an unhandled KeyError when the CAPEC JSON lacked the top-level 'Categories' section.\n\nFix: Add defensive checks to ensure 'Categories' and 'Category' exist and that 'Category' is a list before iterating. When absent or malformed, the function logs a warning and continues extracting names from 'Attack_Pattern' entries.\n\nTests: Unit tests covering missing/malformed Categories already exist and passed locally.