Add CWE ID filtering support in MatchOptions#2
Conversation
- Add cwe_ids field to MatchOptions struct - Implement with_cwes() constructor for easy CWE filtering - Add extract_cwes_from_advisory() helper for CWE extraction - Update advisory_passes_filters() with CWE matching logic - Add comprehensive unit tests for CWE filtering - Update test script with CLI arguments and optional tools - Fix clippy warnings (unnecessary_map_or, dead_code) - Add test_cwe example for developer testing Closes Vulnera-rs#1
There was a problem hiding this comment.
Pull request overview
This pull request adds CWE (Common Weakness Enumeration) ID filtering support to the vulnerability advisory matching system, enabling security teams to filter advisories by specific vulnerability categories like XSS, SQL injection, or deserialization issues.
Changes:
- Added
cwe_idsfield toMatchOptionsstruct with case-insensitive filtering logic - Implemented
extract_cwes_from_advisory()to parse CWEs fromdatabase_specific.cwe_ids - Added 10 comprehensive unit tests covering various CWE filtering scenarios
- Enhanced test script with CLI arguments and optional tool handling
- Added example demonstrating CWE filtering usage
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/manager.rs | Core CWE filtering implementation including MatchOptions extension, filtering logic, CWE extraction helper, and comprehensive unit tests |
| scripts/test.sh | Enhanced test script with verbose mode, optional tool checks, and CLI argument parsing |
| examples/test_cwe.rs | Demonstration example showing various CWE filtering patterns and combinations |
| README.md | Documentation updates with CWE filtering examples and reference table of common CWE IDs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@M9nx |
M9nx
left a comment
There was a problem hiding this comment.
Good catch! Fixed in the latest commit - changed to cargo test --lib cwe which correctly matches all CWE-related tests (test_cwe_filter_, test_extract_cwes_, etc.).
- Normalize CWE IDs to 'CWE-XXX' format (e.g., '79' → 'CWE-79') - Handle case variations (cwe-79 → CWE-79) - Add normalize_cwe_id() helper function - Add 6 new tests for normalization scenarios - Update README with normalization documentation All 77 tests passing.
3b33124 to
1294ccf
Compare
|
Done! Added both user input and advisory CWEs are normalized before comparison, so "79" will correctly match "CWE-79" in advisories (and vice versa). |
- Remove #[allow(dead_code)] attribute - Add test_cwe_filter_with_enrichment_severity test - Add test_cwe_filter_with_enrichment_kev test - Verify CWE filtering works with enrichment data (severity, KEV status) All 15 CWE tests passing.
- Run cargo fmt to ensure consistent formatting All CI checks should pass now.
|
Fixed! Changes: - |
Summary
Adds the ability to filter vulnerability advisories by Common Weakness Enumeration (CWE) identifiers, enabling security teams to focus on specific vulnerability categories (e.g., injection flaws, XSS, deserialization issues).
Changes
Core Implementation
cwe_idsfield toMatchOptionsstruct for CWE-based filteringwith_cwes()constructor for convenient single-purpose filteringextract_cwes_from_advisory()helper to extract CWEs fromdatabase_specific.cwe_idsadvisory_passes_filters()with case-insensitive CWE matching logicTesting & Quality
test_cweexample for developer testing (cargo run --example test_cwe)unnecessary_map_or,dead_code)Documentation & Tooling
-v,--skip-optional,-h)Usage Example
Testing
Files Changed
src/manager.rsexamples/test_cwe.rsscripts/test.shREADME.mdCloses #1