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

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