Skip to content

Fix: guard Categories access in extract_capec_names (Issue #2487)#2517

Open
immortal71 wants to merge 3 commits intoOWASP:masterfrom
immortal71:fix/capec-categories-2487
Open

Fix: guard Categories access in extract_capec_names (Issue #2487)#2517
immortal71 wants to merge 3 commits intoOWASP:masterfrom
immortal71:fix/capec-categories-2487

Conversation

@immortal71
Copy link
Copy Markdown
Contributor

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.

Copilot AI review requested due to automatic review settings March 5, 2026 03:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/Category is missing or malformed, then continue processing.

Comment thread scripts/capec_map_enricher.py Outdated
Comment thread scripts/capec_map_enricher.py Outdated
Comment thread scripts/capec_map_enricher.py Outdated
@immortal71
Copy link
Copy Markdown
Contributor Author

@sydseter the pr is ready for review !!

@rewtd
Copy link
Copy Markdown
Collaborator

rewtd commented Mar 5, 2026

@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?

@immortal71
Copy link
Copy Markdown
Contributor Author

@rewtd done, is this good to go ?

@sydseter
Copy link
Copy Markdown
Collaborator

@immortal71 You have merge conflicts here.

@immortal71
Copy link
Copy Markdown
Contributor Author

@sydseter giveme some time I will resolve the conflict

@immortal71
Copy link
Copy Markdown
Contributor Author

@sydseter is this good to go ?

@sydseter
Copy link
Copy Markdown
Collaborator

sydseter commented Apr 7, 2026

@immortal71 you have a reformating issue.

@sydseter
Copy link
Copy Markdown
Collaborator

sydseter commented Apr 8, 2026

@immortal71 There are some conflicts here after I merged some of your other work.

@immortal71
Copy link
Copy Markdown
Contributor Author

@sydseter is this good to go !!

@sydseter
Copy link
Copy Markdown
Collaborator

sydseter commented Apr 9, 2026

@immortal71 you have a test failure.

@immortal71
Copy link
Copy Markdown
Contributor Author

@sydseter is this good to go ?

@sydseter
Copy link
Copy Markdown
Collaborator

@immortal71 your commits are lacking a verified signature.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the changes in this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert these changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread copi.owasp.org/test/copi_web/plugs/rate_limiter_plug_test.exs Outdated
Comment thread scripts/capec_map_enricher.py Outdated
@immortal71 immortal71 force-pushed the fix/capec-categories-2487 branch from 7d7d10c to f9b3553 Compare April 24, 2026 15:46
@immortal71
Copy link
Copy Markdown
Contributor Author

@sydseter is this good to go ?? I have implemented as you have suggested !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants