Skip to content

Conversation

@trevnorris
Copy link

Enrich OpenGrep SAST alerts with actionable metadata

This PR is the result of the hackathon.

Problem: OpenGrep alerts were bare-bones — just a rule ID, a one-liner message, severity, and line numbers. No CWE/OWASP references, no file path in the location, no fix guidance, and no detailed report for the dashboard.

Meanwhile, TruffleHog and Trivy alerts already had rich detailedReport markdown and full metadata. This made OpenGrep findings harder to triage and less useful to consumers (PR comments, Jira tickets, dashboard).

What changed:

  1. CWE catalog — Added a 946-entry lookup table (cwe_catalog.py) so alerts include human-readable CWE names and descriptions, not just numeric IDs. Includes a generator script for future updates.
  2. Alert metadata extraction — The OpenGrep connector now pulls cwe, owasp, subcategory, fix, and references from Semgrep's extra.metadata into alert props. Auto-generates clickable reference URLs from CWE/OWASP IDs.
  3. detailedReport markdown — Alerts now include a structured markdown report (matching the TruffleHog/Trivy pattern) so the dashboard can display actionable finding details with severity, CWE/OWASP links, vulnerability class, and remediation guidance.
  4. Rule enrichment — All 499 SAST rules now carry subcategory, vulnerability_class, and OWASP metadata. Every sparse rule message (403 of them under 60 chars) was rewritten to follow a What/Why/How pattern. Fix metadata went from 2/499 to 279/499 rules (100% coverage of critical+high severity).
  5. Dataflow traces — Enabled --dataflow-traces in the OpenGrep CLI invocation. Taint-mode alerts now include source-to-sink flow paths in both props.dataflowTrace and the detailedReport markdown.
  6. File path in location — Added the path key to alert.location so the normalizer, notifiers, and all downstream consumers can resolve file paths correctly.

trevnorris and others added 8 commits February 9, 2026 11:51
…kdown

Extract cwe, owasp, subcategory, fix, and references from extra.metadata
into alert props. Auto-generate clickable reference URLs from CWE/OWASP
IDs. Build a detailedReport markdown blob (matching TruffleHog/Trivy
pattern) so the dashboard can display actionable finding details.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- scripts/update_cwe_catalog.py: Fetches full MITRE CWE catalog (Research
  Concepts view), maps each entry to a vulnerability category and OWASP
  Top 10 2021 classification, and generates a Python dict at
  socket_basics/core/connector/opengrep/cwe_catalog.py
- 946 entries covering all software CWEs including 2 synthetic entries
  for deprecated pillar CWEs still referenced by our rules
- All 90 CWEs used in our rules are properly categorized
- Re-run `python scripts/update_cwe_catalog.py` to update when MITRE
  publishes new entries
- docs/alert-quality-improvement-plan.md: Phased implementation plan
  for improving alert quality across connector, rules, and messages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- CWE coverage: 498/499 rules (js-react-missing-key has no CWE), not 499
- Top 20 CWEs cover 68% of rules by count, not ~80%
- Severity breakdown: Critical 95, High 184, Medium 159, Low 61
- Critical+High fix target: 279 rules, not ~220
- Phase 1 scope clarified: applies to alerts with a CWE (498/499)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phase 1 of alert quality improvement:
- Import CWE_CATALOG and look up each alert's CWE at scan time
- Add vulnerabilityName and vulnerabilityCategory to alert props
- Add enrichedDescription from CWE catalog when rule message is sparse
- Extract additional metadata: vulnerability_class, likelihood, impact,
  technology, framework
- Add "What is CWE-X?" explainer section to detailedReport markdown

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…OWASP

Phase 2 of alert quality improvement:
- subcategory: 103/499 -> 499/499 (derived from CWE for missing rules)
- vulnerability_class: 0/499 -> 499/499 (new field, mapped from subcategory)
- owasp: 93/499 -> 441/499 (mapped from CWE, 58 rules have no natural mapping)
- references: 1/499 -> 42/499 (framework-specific docs for 41 rules)
- scripts/enrich_rules.py: reproducible script for future rule enrichment

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…h rules

Phase 3 of alert quality improvement:
- Messages < 60 chars: 403 -> 0 (all now follow What/Why/How pattern)
- Fix metadata: 2/499 -> 279/499 (100% of critical+high rules)
- Fix text is language-specific with concrete API recommendations
- scripts/rewrite_messages.py: reproducible script for future updates

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phase 4 of alert quality improvement:
- Pass --dataflow-traces to OpenGrep CLI for taint source-to-sink data
- Extract dataflow_trace into alert props.dataflowTrace with source,
  sink, and intermediate variable information
- Add "Data Flow" section to detailedReport markdown for taint alerts
- Handle list/dict variants in trace structure defensively

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The location dict was missing the file path, which all downstream consumers
(normalizer, base notifier, and all OpenGrep notifiers) expect under 'path'.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@trevnorris trevnorris requested a review from a team as a code owner February 9, 2026 18:59
@trevnorris trevnorris self-assigned this Feb 10, 2026
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