cwe: remove prohibited vulnerability-mapping entries on refresh#992
cwe: remove prohibited vulnerability-mapping entries on refresh#992Bornunique911 wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Summary by CodeRabbit
WalkthroughThe CWE parser detects prohibited weaknesses and categories, removes matching stale database entries, skips prohibited weaknesses during registration, and preserves allowed-entry processing. Tests and the update script reflect the new behavior. ChangesCWE prohibited-entry handling
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@application/utils/external_project_parsers/parsers/cwe.py`:
- Around line 133-138: Update delete_cwe_entries so its final
cache.session.commit() is wrapped in the same IntegrityError handling pattern
used by add_node: catch the commit failure, roll back the session, and handle
the error without aborting the surrounding register_cwe/parse flow. Keep the
successful deletion log unchanged.
- Around line 107-139: Update delete_cwe_entries to remove every embedding
associated with each entry, rather than deleting only the single result returned
by cache.get_embeddings_for_doc. Iterate through all matching embeddings and
delete each one before deleting the node, preserving the existing link cleanup
and commit flow.
In `@scripts/update-cwe.sh`:
- Around line 18-21: Update the dependency bootstrap in update-cwe.sh to install
the repository’s existing requirements.txt when pytest is unavailable, replacing
the nonexistent requirements-dev.txt reference; preserve the current pytest
check and installation flow.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro Plus
Run ID: 6d5333a1-abeb-4b7c-9b3f-b966a3517b86
📒 Files selected for processing (3)
application/tests/cwe_parser_test.pyapplication/utils/external_project_parsers/parsers/cwe.pyscripts/update-cwe.sh
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/update-cwe.sh`:
- Around line 32-33: Update the status message before the cre.py invocation to
state that entries marked PROHIBITED by either `@Status` or Mapping_Notes -> Usage
are skipped, covering both weaknesses and categories.
- Around line 18-20: Update the dependency bootstrap sentinel in the script’s
Python import check to use an explicit marker or a runtime dependency required
by cre.py, rather than pytest from requirements-dev.txt. Ensure the check
succeeds after installing requirements.txt and prevents repeated installation
attempts before the parser runs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro Plus
Run ID: 14db9b6a-9e48-45c0-b13d-aa066c96d1ca
📒 Files selected for processing (2)
application/utils/external_project_parsers/parsers/cwe.pyscripts/update-cwe.sh
🚧 Files skipped from review as they are similar to previous changes (1)
- application/utils/external_project_parsers/parsers/cwe.py
e6c3f13 to
06a5c64
Compare
…nd improve update script and fixed linting issue.
Signed-off-by: Bornunique911 <69379200+Bornunique911@users.noreply.github.com>
Summary
Follow-up to merged PR #939.
This PR fixes the remaining prohibited-CWE import gap by filtering against the upstream CWE vulnerability-mapping field (
Mapping_Notes -> Usage = Prohibited) and removing stale prohibited CWE entries that may already exist in the local database.A concrete example is
CWE-16, which is still reachable on OpenCRE even though the upstream CWE entry marks its vulnerability mapping asProhibited.Problem
PR #939 improved CWE filtering, but the current logic is still incomplete.
The merged code filters primarily from the XML
@Statusfield on imported weaknesses. That misses entries whose import exclusion is driven by the CWE vulnerability-mapping metadata instead, especially:Mapping_Notes -> Usage = ProhibitedCWE-16As a result, prohibited CWE entries can remain visible after refresh.
Fix
This PR updates the CWE parser to:
Mapping_Notes -> Usage = Prohibitedas the authoritative exclusion signalWeaknessesandCategoriesIt also adds regression coverage for both:
CWE-16The refresh script message is updated as well so it reflects the actual filtering rule.
Review Note For Maintainer
This is a small corrective follow-up to merged PR #939.
I verified that prohibited CWE entries can still remain visible after refresh because the current filter does not fully honor the upstream vulnerability-mapping field (
Mapping_Notes -> Usage = Prohibited) and does not remove stale prohibited rows already present in the DB.CWE-16is a concrete live example of that gap.This PR keeps the scope narrow:
Tested locally with:
/home/born/Important_Stuff/OpenCRE/venv/bin/python -m pytest application/tests/cwe_parser_test.py -k 'prohibited or register_CWE' -q