feat(sast): vendored MIT semgrep packs and a guard against registry rules (#492) #504

Merged
sharang merged 1 commits from feat/492-vendor-semgrep-packs into main 2026-10-06 12:22:51 +00:00
Owner

Closes #492.

What

Three MIT-licensed semgrep packs run next to our own rules, in the same invocation (--metrics=off, local files only), in compliance-agent/rules/vendor/<source>/ with LICENSE, NOTICE, UPSTREAM:

Source Pin Rules in pack
GitLab sast-rules (MIT files only) v2.10.1 53bf5cf6df3c51b6c02110f5a638b5e6213666cd 148 (C#, Java, JS/TS, Python, 1 Go)
0xdea semgrep-rules (MIT) dae50da6e6e629750f1daec73a01ef9206a372ab 35 (C/C++)
elttam semgrep-rules (MIT) 244268562cc92d33f54b8a60a187df5520f91b26 34 (Java, Go, Struts/Spring XML)

upstream/ keeps the selected files verbatim (with their semgrep --test cases), pack.yaml is what runs (ids prefixed gitlab- / 0xdea- / elttam-), rules.json indexes it for the tests. scripts/vendor-semgrep-rules.py regenerates everything at the pins.

Licence and provenance

  • GitLab: only files whose header says License: MIT (c) GitLab Inc.. Not vendored: c/ (every file says GPL-2.0, generated from flawfinder), go/ except crypto/rule-tlsversion (Apache-2.0 gosec ports), scala/, rules/lgpl, rules/lgpl-cc (Commons Clause), rules/gitlab (EE). So the issue's "GitLab C and Go" are not covered by GitLab; C comes from 0xdea.
  • elttam's LICENSE says "Copyright (c) 2020 Semgrep" (MIT text of the template repo its first commit came from); noted in its NOTICE.
  • Spot-check: every candidate rule compared (message similarity and identical pattern bodies) with semgrep/semgrep-rules. Not vendored: 8 GitLab rules (mustache-escape, start-process-with-no-shell, subprocess-popen-shell-true, ssh-nohost-key-verification, flask app-debug, marshal, dill, crypto-encrypt-ec) and elttam's Kubernetes rules (registry-derived). The 0xdea command-injection message only resembles a registry one through the MITRE CWE-78 text; kept.

Noise budget

Run over the nightly fixtures, the three public samples and FreeRTOS-Kernel, lwIP, OpenRA, eShopOnWeb, requests, express, spring-petclinic. Dropped from the pack (reasons in NOTICE): 0xdea missing-return (1514 hits), typos (989), interesting-api-calls (718), signed-unsigned-conversion (221), suspicious-assert (176), format-string-bugs (61, macro-joined literal formats), argv-envp-access, mismatched-memory-management, write-into-stack-buffer, integer-truncation, missing-default-in-switch, missing-break-in-switch, pointer-subtraction, high-entropy-assignment; GitLab python_assert_rule-assert-used. Also left out: elttam entrypoint enumerators, ORM-leak hints, three files whose upstream tests fail on semgrep 1.177, one join-mode rule.

CPU time of the semgrep run (agent settings, semgrep 1.177): FreeRTOS-Kernel 70 s → 136 s, lwIP 18 s → 68 s, OpenRA 42 s → 96 s, nowinandroid 8 s → 13 s. Within the 600 s stage timeout.

Control map, ids, guard

  • One vendored semgrep binding per control (cra-ai-1, 7, 8, 10, 13, 15, 16, 20), by CWE (CWE-489 deliberately not, so a stray debug finding still does not bind cra-ai-1) (by id for elttam's CWE-less rules), with exactly the languages of the rules behind it. Test: every vendored rule maps to a control whose binding claims its languages.
  • Ids stay bare through bare_rule_id (#473); fingerprint() is untouched.
  • semgrep_args() builds the invocation. Tests fail if a --config is anything but a staged local pack (auto, p/, r/, a URL), and if the agent source, scripts/, docker/, .gitea/ or Dockerfile.agent names a registry config.

Checks

cargo fmt, cargo clippy -p compliance-agent --all-targets -- -D warnings, cargo test -p compliance-agent -p control-map --lib (the .NET fixture test now also expects the GitLab SQL rule), semgrep --test compliance-agent/rules 237/237.

Nightly: I could not run it locally (it needs the built image). Baselines with C, Python, C# or JS code (e.g. fw-c-sensor-node, py-, archive-, git-cra-vuln-demo) will change; they need a bless dispatch after the image is deployed. Staging check: test plan §23. The plan on main had a stray conflict-marker line (||||||| parent of 8c986d6 …) committed above §20; this PR removes it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB

Closes #492. ## What Three MIT-licensed semgrep packs run next to our own rules, in the same invocation (`--metrics=off`, local files only), in `compliance-agent/rules/vendor/<source>/` with `LICENSE`, `NOTICE`, `UPSTREAM`: | Source | Pin | Rules in pack | |---|---|---| | GitLab sast-rules (MIT files only) | v2.10.1 `53bf5cf6df3c51b6c02110f5a638b5e6213666cd` | 148 (C#, Java, JS/TS, Python, 1 Go) | | 0xdea semgrep-rules (MIT) | `dae50da6e6e629750f1daec73a01ef9206a372ab` | 35 (C/C++) | | elttam semgrep-rules (MIT) | `244268562cc92d33f54b8a60a187df5520f91b26` | 34 (Java, Go, Struts/Spring XML) | `upstream/` keeps the selected files verbatim (with their `semgrep --test` cases), `pack.yaml` is what runs (ids prefixed `gitlab-` / `0xdea-` / `elttam-`), `rules.json` indexes it for the tests. `scripts/vendor-semgrep-rules.py` regenerates everything at the pins. ## Licence and provenance - GitLab: only files whose header says `License: MIT (c) GitLab Inc.`. **Not vendored:** `c/` (every file says GPL-2.0, generated from flawfinder), `go/` except `crypto/rule-tlsversion` (Apache-2.0 gosec ports), `scala/`, `rules/lgpl`, `rules/lgpl-cc` (Commons Clause), `rules/gitlab` (EE). So the issue's "GitLab C and Go" are not covered by GitLab; C comes from 0xdea. - elttam's LICENSE says "Copyright (c) 2020 Semgrep" (MIT text of the template repo its first commit came from); noted in its NOTICE. - Spot-check: every candidate rule compared (message similarity and identical pattern bodies) with semgrep/semgrep-rules. Not vendored: 8 GitLab rules (mustache-escape, start-process-with-no-shell, subprocess-popen-shell-true, ssh-nohost-key-verification, flask app-debug, marshal, dill, crypto-encrypt-ec) and elttam's Kubernetes rules (registry-derived). The 0xdea command-injection message only resembles a registry one through the MITRE CWE-78 text; kept. ## Noise budget Run over the nightly fixtures, the three public samples and FreeRTOS-Kernel, lwIP, OpenRA, eShopOnWeb, requests, express, spring-petclinic. Dropped from the pack (reasons in NOTICE): 0xdea `missing-return` (1514 hits), `typos` (989), `interesting-api-calls` (718), `signed-unsigned-conversion` (221), `suspicious-assert` (176), `format-string-bugs` (61, macro-joined literal formats), `argv-envp-access`, `mismatched-memory-management`, `write-into-stack-buffer`, `integer-truncation`, `missing-default-in-switch`, `missing-break-in-switch`, `pointer-subtraction`, `high-entropy-assignment`; GitLab `python_assert_rule-assert-used`. Also left out: elttam entrypoint enumerators, ORM-leak hints, three files whose upstream tests fail on semgrep 1.177, one join-mode rule. CPU time of the semgrep run (agent settings, semgrep 1.177): FreeRTOS-Kernel 70 s → 136 s, lwIP 18 s → 68 s, OpenRA 42 s → 96 s, nowinandroid 8 s → 13 s. Within the 600 s stage timeout. ## Control map, ids, guard - One vendored `semgrep` binding per control (cra-ai-1, 7, 8, 10, 13, 15, 16, 20), by CWE (CWE-489 deliberately not, so a stray debug finding still does not bind cra-ai-1) (by id for elttam's CWE-less rules), with exactly the languages of the rules behind it. Test: every vendored rule maps to a control whose binding claims its languages. - Ids stay bare through `bare_rule_id` (#473); `fingerprint()` is untouched. - `semgrep_args()` builds the invocation. Tests fail if a `--config` is anything but a staged local pack (`auto`, `p/`, `r/`, a URL), and if the agent source, `scripts/`, `docker/`, `.gitea/` or `Dockerfile.agent` names a registry config. ## Checks `cargo fmt`, `cargo clippy -p compliance-agent --all-targets -- -D warnings`, `cargo test -p compliance-agent -p control-map --lib` (the .NET fixture test now also expects the GitLab SQL rule), `semgrep --test compliance-agent/rules` 237/237. **Nightly:** I could not run it locally (it needs the built image). Baselines with C, Python, C# or JS code (e.g. fw-c-sensor-node, py-*, archive-*, git-cra-vuln-demo) will change; they need a `bless` dispatch after the image is deployed. Staging check: test plan §23. The plan on main had a stray conflict-marker line (`||||||| parent of 8c986d6 …`) committed above §20; this PR removes it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang force-pushed feat/492-vendor-semgrep-packs from 9d5ee362cf to d5bdb29f78 2026-10-06 11:45:25 +00:00 Compare
sharang force-pushed feat/492-vendor-semgrep-packs from d5bdb29f78 to 8cbacddb60 2026-10-06 12:03:51 +00:00 Compare
sharang added 1 commit 2026-10-06 12:05:44 +00:00
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
e1c625591a
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
sharang force-pushed feat/492-vendor-semgrep-packs from 8cbacddb60 to e1c625591a 2026-10-06 12:05:44 +00:00 Compare
sharang merged commit d406741907 into main 2026-10-06 12:22:51 +00:00
Sign in to join this conversation.