Skip to content

cwe: remove prohibited vulnerability-mapping entries on refresh#992

Open
Bornunique911 wants to merge 3 commits into
OWASP:mainfrom
Bornunique911:fix/cwe-prohibited-mapping-filter-main
Open

cwe: remove prohibited vulnerability-mapping entries on refresh#992
Bornunique911 wants to merge 3 commits into
OWASP:mainfrom
Bornunique911:fix/cwe-prohibited-mapping-filter-main

Conversation

@Bornunique911

Copy link
Copy Markdown
Contributor

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 as Prohibited.

Problem

PR #939 improved CWE filtering, but the current logic is still incomplete.

The merged code filters primarily from the XML @Status field on imported weaknesses. That misses entries whose import exclusion is driven by the CWE vulnerability-mapping metadata instead, especially:

  • prohibited entries with Mapping_Notes -> Usage = Prohibited
  • prohibited category entries such as CWE-16
  • stale prohibited CWE rows already present in the database from earlier imports

As a result, prohibited CWE entries can remain visible after refresh.

Fix

This PR updates the CWE parser to:

  • treat Mapping_Notes -> Usage = Prohibited as the authoritative exclusion signal
  • still skip explicitly prohibited status entries
  • inspect both Weaknesses and Categories
  • delete stale prohibited CWE rows already stored in the local database before completing the refresh

It also adds regression coverage for both:

  • prohibited weakness entries
  • stale prohibited category entries such as CWE-16

The 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-16 is a concrete live example of that gap.

This PR keeps the scope narrow:

  • filter prohibited entries using upstream mapping metadata
  • remove stale prohibited CWE rows on refresh
  • add regression coverage

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

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1616803d-d42a-4320-a2da-d1cf1a4b1373

📥 Commits

Reviewing files that changed from the base of the PR and between 07cb4c2 and d980da9.

📒 Files selected for processing (2)
  • application/utils/external_project_parsers/parsers/cwe.py
  • scripts/update-cwe.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • scripts/update-cwe.sh
  • application/utils/external_project_parsers/parsers/cwe.py

Summary by CodeRabbit

  • Bug Fixes

    • CWE imports now detect and remove prohibited or stale category entries.
    • Prohibited weaknesses and categories are skipped during processing based on status or usage notes.
    • Related links and embeddings are cleaned up when prohibited CWE entries are removed.
  • Tests

    • Added coverage verifying removal of stale prohibited CWE categories.
  • Chores

    • Improved dependency setup checks and clarified CWE importer status messaging.

Walkthrough

The 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.

Changes

CWE prohibited-entry handling

Layer / File(s) Summary
Prohibited-entry detection and deletion
application/utils/external_project_parsers/parsers/cwe.py
Adds helpers to flatten catalog entries, read mapping usage, identify prohibited entries, collect IDs, and delete matching CWE nodes and linked records.
Registration filtering and cleanup
application/utils/external_project_parsers/parsers/cwe.py
Removes prohibited IDs before registration and skips prohibited weaknesses while continuing allowed-entry updates and relationship handling.
Parser validation and update command
application/tests/cwe_parser_test.py, scripts/update-cwe.sh
Tests prohibited weaknesses and stale categories; the update script checks runtime dependencies and reports skipped prohibited mappings.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: robvanderveer, northdpole, paoga87, pa04rth

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: removing prohibited CWE entries during refresh.
Description check ✅ Passed The description matches the code changes and explains the filtering and stale-row cleanup correctly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between a55e380 and 06a5c64.

📒 Files selected for processing (3)
  • application/tests/cwe_parser_test.py
  • application/utils/external_project_parsers/parsers/cwe.py
  • scripts/update-cwe.sh

Comment thread application/utils/external_project_parsers/parsers/cwe.py
Comment thread application/utils/external_project_parsers/parsers/cwe.py Outdated
Comment thread scripts/update-cwe.sh Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 06a5c64 and 07cb4c2.

📒 Files selected for processing (2)
  • application/utils/external_project_parsers/parsers/cwe.py
  • scripts/update-cwe.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • application/utils/external_project_parsers/parsers/cwe.py

Comment thread scripts/update-cwe.sh Outdated
Comment thread scripts/update-cwe.sh Outdated
@Bornunique911
Bornunique911 force-pushed the fix/cwe-prohibited-mapping-filter-main branch from e6c3f13 to 06a5c64 Compare July 23, 2026 18:28
Bornunique911 and others added 2 commits July 24, 2026 00:03
…nd improve update script and fixed linting issue.
Signed-off-by: Bornunique911 <69379200+Bornunique911@users.noreply.github.com>
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.

1 participant