feat(sast): vendored MIT semgrep packs and a guard against registry rules (#492)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 9m17s

Our ~35 own rules left whole languages without SAST findings. Three
permissively licensed community packs now run next to them, on the same
semgrep invocation (--metrics=off, local files only):

- GitLab sast-rules v2.10.1 (53bf5cf6): 148 rules for C#, Java,
  JavaScript/TypeScript, Python and one Go rule; only files whose header says
  "License: MIT (c) GitLab Inc.". Not vendored: c/ (every file GPL-2.0,
  generated from flawfinder), go/ apart from one file (Apache-2.0 gosec
  ports), scala/, rules/lgpl, rules/lgpl-cc (Commons Clause), rules/gitlab (EE).
- 0xdea semgrep-rules (dae50da6, MIT): 35 C/C++ rules.
- elttam semgrep-rules (24426856, MIT; its LICENSE carries the Semgrep
  template's copyright line): 34 rules for Java, Go and Struts/Spring XML.

Each pack lives in compliance-agent/rules/vendor/<source>/ with LICENSE,
NOTICE (provenance, what was left out and why) and UPSTREAM (pinned commit):
upstream/ holds the selected files unchanged with their tests, pack.yaml the
rules the agent runs, ids prefixed per source (gitlab-, 0xdea-, elttam-),
rules.json an index for the tests. scripts/vendor-semgrep-rules.py
regenerates all of it deterministically.

Provenance: every candidate rule was compared with the Semgrep registry
(semgrep/semgrep-rules, read only for the comparison). Eight GitLab Python/JS
rules with the same message or the same patterns are not vendored, nor are
elttam's Kubernetes rules (registry-derived). Also left out: elttam's
entrypoint enumerators, its ORM-leak hints, three files whose upstream
tests fail on semgrep 1.177 and a join-mode rule.

Noise budget: run over the nightly fixtures, the public samples and
FreeRTOS-Kernel, lwIP, OpenRA, eShopOnWeb, requests, express and
spring-petclinic. 15 rules that flood real code (0xdea missing-return 1514
hits, typos 989, interesting-api-calls 718, signed-unsigned-conversion 221,
suspicious-assert 176, format-string-bugs 61 ...; GitLab assert-used) are
dropped from the pack, each listed with its reason in NOTICE. CPU time of
the semgrep run roughly doubles on C-heavy trees (FreeRTOS-Kernel 70 s ->
136 s, lwIP 18 s -> 68 s), well inside the 10-minute stage timeout.

Ids stay bare (#473 logic covers the vendored ids, fingerprint() unchanged).
The control map gets one vendored semgrep binding per control, by CWE (by
rule id for the few elttam rules without one), with exactly the languages of
the rules behind it; a test checks every vendored rule maps to a control
that claims its languages.

Guard: semgrep_args() builds the one invocation; a test fails if any
--config is not a staged local pack, or is auto, p/, r/ or a URL, and
another scans the agent source, scripts, docker/, CI and Dockerfile.agent for
a registry config.

Nightly baselines with C, Python, C# or JS code change and need a bless run
after the image is deployed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-10-06 14:04:03 +02:00
1 parent 9bf7aad5b1
commit e1c625591a
473 files changed
+50690 -116

No files matched your search

+2 -1
View File
@@ -22,11 +22,12 @@ Every control lands in one of three buckets, recorded in the `control-map` LUT (
| `needs_tooling` | Code-checkable, but no off-the-shelf tool digs it out — we author a detector or use the grounded surface check |
| `not_code_checkable` | A design/process property — out of static-scan scope |
For the **CRA** framework (40 controls) the split is **21 covered · 0 needs_tooling · 19 not_code_checkable**. Every semgrep binding names our own rules only: the Semgrep registry rules are not run (their licence allows internal use only, not a service for others), so a binding covers exactly the languages its rules are written for. The originally uncovered controls were resolved as a hybrid:
For the **CRA** framework (40 controls) the split is **21 covered · 0 needs_tooling · 19 not_code_checkable**. The Semgrep registry rules are not run (their licence allows internal use only, not a service for others): every semgrep binding names our own rules or, since #492, the vendored MIT packs (GitLab, 0xdea, elttam), so a binding covers exactly the languages its rules are written for. The originally uncovered controls were resolved as a hybrid:
- **Custom semgrep detectors**, shipped in the binary and matched back to controls **by rule id** so a broad CWE can't over-attribute:
- for Python and JavaScript/TypeScript: `cra-ai-1`, `7`, `10`, `14` (secure-by-default, weak password hashing, insecure session cookies, weak data-at-rest ciphers), `cra-ai-20` (shell commands and SQL built from variables, request input echoed into a response), `cra-ai-8` (hard-coded credentials, Python) and `cra-ai-15` (plain `http://` requests);
- for C and C++ firmware: `cra-ai-8`, `13`, `16`, `20` (hard-coded credentials including `#define` macros, broken hash/cipher, `rand()`, unbounded string functions and non-literal format strings), next to cppcheck for memory safety.
- **Vendored semgrep packs** (GitLab, 0xdea, elttam; #492), bound **by CWE** like off-the-shelf tools, on a semgrep binding of their own per control whose `languages` are exactly those of the vendored rules under those CWEs (a test checks every vendored rule maps to a control that claims its languages). The few elttam rules without a CWE are bound by rule id. Because these bindings are `semgrep` bindings, a CWE they list also attaches our own semgrep findings with that CWE to the control.
- **mobsfscan** for Android and iOS apps, bound **by CWE** (a mobsfscan binding only ever attaches mobsfscan findings): `cra-ai-1` (debuggable, exported components, outdated `minSdkVersion`), `7`, `8`, `9`, `13`, `14`, `15` (cleartext, TLS, App Transport Security), `16` and `20`. Each binding lists only the languages mobsfscan has rules for under those CWEs, so `cra-ai-1` covers Java and Kotlin (its manifest checks) but not Swift.
- **8 grounded surface checks** (`cra-ai-6`, `11`, `12`, `24`, `27`, `28`, `29`, `30`): the absence-based controls (no rate limiting, no security logging, no update-signature check…) that have no syntactic pattern.
- **Marked not_code_checkable** (`cra-ai-2`, `3`, `4`, `5`, among the 19): minimal attack surface, secure architecture, least privilege, tamper protection.
+25 -5
View File
@@ -6,7 +6,8 @@ Prüfwerk uses a combination of open-source scanners and AI-powered analysis to
[Semgrep](https://semgrep.dev/) is an open-source static analysis engine (LGPL-2.1) that finds vulnerabilities by matching patterns in source code.
Prüfwerk runs the engine with **its own CRA rules only**:
Prüfwerk runs the engine with **its own CRA rules** and **three vendored,
MIT-licensed community rule packs**. Its own rules:
- Python and JavaScript/TypeScript: secure defaults, weak password hashing,
insecure session cookies, weak ciphers for data at rest, shell commands and
@@ -19,13 +20,32 @@ Prüfwerk runs the engine with **its own CRA rules only**:
Keychain. The Objective-C rule is a text pattern, as Semgrep cannot parse
Objective-C.
The vendored packs (#492), each pinned to an upstream commit and shipped
in the agent with its licence and a NOTICE (`compliance-agent/rules/vendor/`):
| Source | Licence | Rules | Languages |
|---|---|---|---|
| [GitLab SAST rules](https://gitlab.com/gitlab-org/security-products/sast-rules) v2.10.1 | MIT (only files with GitLab's MIT header) | 148 | C#, Java, JavaScript/TypeScript, Python, one Go rule |
| [0xdea semgrep-rules](https://github.com/0xdea/semgrep-rules) | MIT | 35 | C, C++ |
| [elttam semgrep-rules](https://github.com/elttam/semgrep-rules) | MIT | 34 | Java, Go, Struts/Spring XML |
Their rule ids carry the source as a prefix (`gitlab-…`, `0xdea-…`,
`elttam-…`), and they count for the CRA controls by CWE. Rules that match a
Semgrep registry rule, review hints and rules that flood real firmware and
library code with false positives (measured on FreeRTOS, lwIP and the nightly
fixtures) are left out; each pack's NOTICE lists them with the reason. Not
vendored at all: GitLab's C rules (GPL-2.0, generated from flawfinder), its
gosec-derived Go rules (Apache-2.0) and its LGPL/Commons Clause/EE
directories, and elttam's Kubernetes rules (derived from registry rules).
The rules of the Semgrep registry (`--config=auto`, `p/...`) are not used:
their licence (Semgrep Rules License v1.0) allows internal use only, not a
service offered to others, and `auto` cannot run without sending metrics to
Semgrep. Semgrep runs with `--metrics=off` and no version check, so nothing
about your code leaves the scan. Code in other languages gets no Semgrep
findings; the CRA view says so (*Keine Prüfregel für den gefundenen Code*)
instead of reporting it as clean.
Semgrep. A test fails if the agent's semgrep run, a script or the CI ever
names a registry config. Semgrep runs with `--metrics=off` and no version
check, so nothing about your code leaves the scan. Code in a language no rule
covers gets no Semgrep findings; the CRA view says so (*Keine Prüfregel für
den gefundenen Code*) instead of reporting it as clean.
Semgrep produces **Codeanalyse (SAST)** findings with file paths, line numbers, and rule descriptions.
@@ -20,6 +20,7 @@ together on stage in one pass before the next prod promotion.
| #467 (follow-up) | npm and Maven licenses from their public registries |
| #491 | Findings keyed by the code they flag, not its line number |
| #491 (PLC) | PLC findings keyed the same way |
| #492 | Vendored MIT semgrep packs (GitLab, 0xdea, elttam); guard against registry rules |
| #495 | Binary depth: PE/ELF hardening, signatures, .NET references, CPE/purl candidates, Intel HEX checks |
| #498 (1/4) | VEX status on CVE alerts, OpenVEX and CycloneDX VEX, a valid CycloneDX SBOM |
@@ -451,6 +452,29 @@ alerts (e.g. the log4j/gson target of check 19).
validates (before, vulnerabilities sat inside the components); the
evidence pack gains the two VEX files.
### 23. #492 Vendored semgrep packs
- **Do:** upload `fixtures/nightly/firmware/c-sensor-node` and
`fixtures/dotnet/framework48` as **Archiv**, and a small Java or Python tree
with an obvious weakness (e.g. `Cipher.getInstance("DES")`,
`yaml.load(data)` or `requests.get(url, verify=False)`).
- **Expect:** besides the `cra-ai-*` findings, Codeanalyse findings with the
tool `semgrep` and rule ids `gitlab-…` (Java/Python/C#, e.g.
`gitlab-csharp_injection_rule-SQLInjection` in `OrderService.svc.cs`) and
`0xdea-raptor-…` (C, e.g. `0xdea-raptor-insecure-api-strcpy-strcat`,
`0xdea-raptor-unchecked-ret-malloc` in the sensor node), each with a CWE and
a CRA control (cra-ai-13/15/16/20 …). The Java/Python tree's CRA view now
shows those controls as checked instead of *Keine Prüfregel für den
gefundenen Code*. No rule id contains `tmp.` or a path.
- **Expect:** the SAST stage still completes on a large tree (the Android
public sample from the nightly), no `sast` skip.
- **Log:** nothing new; `Semgrep failed` must not appear.
- **[visible]** on the next prod rescan: Java, Python, C#, JavaScript and C/C++
targets get new Codeanalyse findings from the vendored rules, and controls
for Java/Go code move from "no rule for the languages found" to assessed.
In managed repositories new High findings go through LLM triage and open
tracker issues on that first rescan (#451).
## After the pass
- The nightly job on `main` is green with the new mobile targets.