feat(output-types): tag known-exploited vulnerabilities with kev (#1319) - #1321
Conversation
…reelabz#1319) Download the CISA KEV catalog once (cached to the data dir, like wordlists / payloads) and tag any emitted Vulnerability whose CVE id is known-exploited with the `kev` tag, enabling `vulnerability.tags ~= 'kev'` queries. - Add secator/kev.py: lazily download + parse the CISA KEV feed and expose a memoized set of KEV CVE ids; empty set on offline/failure so tagging is a safe no-op. - Tag in Vulnerability.__post_init__ so it applies to vulns from every task, not just CVE-enriched ones. - Unit tests in tests/unit/test_kev.py.
WalkthroughAdds lazy CISA KEV catalog loading with process-level caching, extracts normalized CVE identifiers, and automatically adds the ChangesKEV vulnerability tagging
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Vulnerability
participant KEVLookup
participant CISACatalog
Vulnerability->>KEVLookup: initialize and request KEV identifiers
KEVLookup->>CISACatalog: load catalog JSON
CISACatalog-->>KEVLookup: return CVE records
KEVLookup-->>Vulnerability: return cached CVE set
Vulnerability->>Vulnerability: append kev for matching ID
Possibly related issues
Poem
🚥 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.
🧹 Nitpick comments (1)
tests/unit/test_kev.py (1)
16-46: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd direct loader and cache tests.
These tests mock
_load_kev_cve_ids(), so regressions indownload_file()delegation, JSON parsing, malformed-feed fallback, or memoization still pass. Add focusedget_kev_cve_ids()tests that patchsecator.kev.download_fileand verify a valid fixture, malformed JSON fallback, and a single loader call across two lookups.🤖 Prompt for 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. In `@tests/unit/test_kev.py` around lines 16 - 46, Add focused tests for get_kev_cve_ids() that mock secator.kev.download_file and cover valid JSON parsing, malformed-feed fallback to an empty set, and memoization by asserting two lookups trigger only one download. Keep the existing Vulnerability tag tests unchanged and reset the cache between cases so each test remains isolated.
🤖 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.
Nitpick comments:
In `@tests/unit/test_kev.py`:
- Around line 16-46: Add focused tests for get_kev_cve_ids() that mock
secator.kev.download_file and cover valid JSON parsing, malformed-feed fallback
to an empty set, and memoization by asserting two lookups trigger only one
download. Keep the existing Vulnerability tag tests unchanged and reset the
cache between cases so each test remains isolated.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8f376e03-8136-4503-a4dd-b6bf6d3245c9
📒 Files selected for processing (3)
secator/kev.pysecator/output_types/vulnerability.pytests/unit/test_kev.py
|
Let me know if you need any explain on the code or modify it |
|
Hi @juandresrodca ! Sorry I just returned from vacations. |
Closes #1319.
Adds kev tagging for known-exploited vulnerabilities, following the recipe in the issue.
notes
the network. Fails open: offline / download error / malformed feed → empty set, so
tagging is always a safe no-op.
self.idagainst the CVE list per the recipe; matching CVEs found inreferences/extra_datacould be a follow-up.expose the URL / a toggle in
Config, if you'd prefer.(https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json),
cached to the data dir via the existing download_file() helper (same path as
wordlists/payloads), and exposes a memoized get_kev_cve_ids() returning the set
of KEV CVE ids — built as {v['cveId'] for v in KEV_DATA['vulnerabilities']}.
when its id (the CVE id) is in the KEV set. Done here so it applies to vulns from
every task, not just CVE-enriched ones — which lights up the already-documented
vulnerability.tags ~= 'kev' cheatsheet query.
Testing
secator test unit --test test_kev (6 passed); flake8 clean. Existing
test_output_types still green.
Summary by CodeRabbit
New Features
kevtag.Bug Fixes