fix(sast): run only our own semgrep rules, no registry rules or metrics #441

Merged
sharang merged 1 commits from feat/no-registry-rules into main 2026-10-05 13:03:44 +00:00
Owner

Stacked on #440: the base is feat/mobile-sbom, and it gets retargeted to main once #440 is merged.

Why

  • Licence. The Semgrep registry rules (--config=auto, p/kotlin, p/swift and so on) fall under the Semgrep Rules License v1.0 (since 13.12.2024): "You may use the rules only for your own internal business purposes… This license does not allow you to… make them available to others as a service" (https://semgrep.dev/legal/rules-license). Semgrep's licensing page adds: "Vendors cannot use Semgrep-maintained rules in competing products or SaaS offerings."
  • Data flow. --config=auto refuses to run with metrics off. Tested locally: "Cannot create auto config when metrics are off". So every customer scan reported to Semgrep.
  • The engine stays. Semgrep CE is LGPL-2.1.

Change

  • pipeline/semgrep.rs:
    • Runs only rules/cra_semgrep.yaml, with --metrics=off --disable-version-check.
    • If the rules can't be staged, the stage fails instead of running with nothing. Before, the fallback was "auto only".
    • SEMGREP_RULES is no longer passed through from the environment.
  • 8 new rules of our own for Python and JS/TS, so the coverage the registry rules gave the fixtures doesn't silently go away:
Rule Control CWE
cra-ai-20-python-shell-command (os.system, os.popen, subprocess(..., shell=True) with a variable) cra-ai-20 78
cra-ai-20-python-sql-string (execute with +, %, f-string or .format) cra-ai-20 89
cra-ai-20-python-unsafe-deserialization (pickle, marshal, yaml.load without SafeLoader) cra-ai-20 502
cra-ai-20-node-shell-command (child_process exec/execSync with a variable) cra-ai-20 78
cra-ai-20-node-reflected-input (taint: req.query/params/body into res.send/write) cra-ai-20 79
cra-ai-8-python-hardcoded-credential cra-ai-8 798
cra-ai-15-python-cleartext-http, cra-ai-15-node-cleartext-http (http:// except localhost) cra-ai-15 319

The annotated hit and no-hit cases are in rules/cra_semgrep.py and rules/cra_semgrep.js. semgrep --test compliance-agent/rules passes 8/8.

  • Control map:
    • Every semgrep binding lists exactly our rule IDs and only the languages those rules cover.
    • Before, cra-ai-8, 9, 13, 15, 16 and 20 claimed Java, Go, Ruby, PHP, C# and Kotlin on the strength of registry rules. The CRA view could therefore say "Kein Verstoß gefunden" for code nothing had checked. Now it says Keine Prüfregel für den gefundenen Code.
    • cra-ai-9 is now bound to gitleaks only.
    • The cra-ai-20 check text now also names injection.
  • Nightly harness: registry_rules is gone. Every semgrep finding is now deterministic and is compared exactly. Two expect blocks (archive-order-intake) now name our rule IDs.
  • Docs: tools, scanning, control-mapping, the design doc and the README.

What is no longer found (honest list)

  • Java, Go, Ruby, PHP, C# and Kotlin get no Semgrep findings at all. For mobile apps (Java, Kotlin, Swift) mobsfscan follows in the next PR.
  • Gone from the fixtures:
    • registry secret patterns (gitleaks still finds them);
    • Express CSRF middleware hints;
    • a yarn "minimal age gate" note;
    • SQLAlchemy raw queries;
    • the DES cipher via pycryptodome (cra-ai-14-python-weak-cipher still finds DES).
  • Taint analysis for Python goes beyond our patterns: Flask parameters into subprocess are now found only when the command is built in the call itself.

Checks

  • fmt, plus clippy with the CI flags on the agent and control-map.
  • Agent lib tests: 492. control-map: 12. Nightly harness unit tests: 4.
  • Offline proof: semgrep with HTTP(S)_PROXY=127.0.0.1:9 over fixtures/ and examples/ produces findings and no errors.
  • Local nightly on the staging image with this binary, all targets: both bless and compare pass. The planted flaws are found again, now by our own rules:
    • Python fixtures: shell, credential and deserialisation;
    • JS fixtures: shell and reflected input;
    • cra-vuln-demo: SQL, shell, two credentials and http.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

**Stacked on #440**: the base is `feat/mobile-sbom`, and it gets retargeted to main once #440 is merged. ## Why - **Licence.** The Semgrep registry rules (`--config=auto`, `p/kotlin`, `p/swift` and so on) fall under the **Semgrep Rules License v1.0** (since 13.12.2024): "You may use the rules only for your own internal business purposes… This license does not allow you to… make them available to others as a service" (https://semgrep.dev/legal/rules-license). Semgrep's licensing page adds: "Vendors cannot use Semgrep-maintained rules in competing products or SaaS offerings." - **Data flow.** `--config=auto` refuses to run with metrics off. Tested locally: "Cannot create auto config when metrics are off". So every customer scan reported to Semgrep. - **The engine stays.** Semgrep CE is LGPL-2.1. ## Change - **`pipeline/semgrep.rs`:** - Runs only `rules/cra_semgrep.yaml`, with `--metrics=off --disable-version-check`. - If the rules can't be staged, the stage fails instead of running with nothing. Before, the fallback was "auto only". - `SEMGREP_RULES` is no longer passed through from the environment. - **8 new rules of our own** for Python and JS/TS, so the coverage the registry rules gave the fixtures doesn't silently go away: | Rule | Control | CWE | |---|---|---| | `cra-ai-20-python-shell-command` (`os.system`, `os.popen`, `subprocess(..., shell=True)` with a variable) | cra-ai-20 | 78 | | `cra-ai-20-python-sql-string` (`execute` with `+`, `%`, f-string or `.format`) | cra-ai-20 | 89 | | `cra-ai-20-python-unsafe-deserialization` (`pickle`, `marshal`, `yaml.load` without SafeLoader) | cra-ai-20 | 502 | | `cra-ai-20-node-shell-command` (`child_process` `exec`/`execSync` with a variable) | cra-ai-20 | 78 | | `cra-ai-20-node-reflected-input` (taint: `req.query/params/body` into `res.send/write`) | cra-ai-20 | 79 | | `cra-ai-8-python-hardcoded-credential` | cra-ai-8 | 798 | | `cra-ai-15-python-cleartext-http`, `cra-ai-15-node-cleartext-http` (`http://` except localhost) | cra-ai-15 | 319 | The annotated hit and no-hit cases are in `rules/cra_semgrep.py` and `rules/cra_semgrep.js`. `semgrep --test compliance-agent/rules` passes 8/8. - **Control map:** - Every semgrep binding lists exactly our rule IDs and only the languages those rules cover. - Before, cra-ai-8, 9, 13, 15, 16 and 20 claimed Java, Go, Ruby, PHP, C# and Kotlin on the strength of registry rules. The CRA view could therefore say "Kein Verstoß gefunden" for code nothing had checked. Now it says *Keine Prüfregel für den gefundenen Code*. - cra-ai-9 is now bound to gitleaks only. - The cra-ai-20 `check` text now also names injection. - **Nightly harness:** `registry_rules` is gone. Every semgrep finding is now deterministic and is compared exactly. Two `expect` blocks (archive-order-intake) now name our rule IDs. - **Docs:** tools, scanning, control-mapping, the design doc and the README. ## What is no longer found (honest list) - **Java, Go, Ruby, PHP, C# and Kotlin get no Semgrep findings at all.** For mobile apps (Java, Kotlin, Swift) mobsfscan follows in the next PR. - **Gone from the fixtures:** - registry secret patterns (gitleaks still finds them); - Express CSRF middleware hints; - a yarn "minimal age gate" note; - SQLAlchemy raw queries; - the DES cipher via pycryptodome (`cra-ai-14-python-weak-cipher` still finds DES). - Taint analysis for Python goes beyond our patterns: Flask parameters into subprocess are now found only when the command is built in the call itself. ## Checks - fmt, plus clippy with the CI flags on the agent and control-map. - Agent lib tests: 492. control-map: 12. Nightly harness unit tests: 4. - Offline proof: semgrep with `HTTP(S)_PROXY=127.0.0.1:9` over `fixtures/` and `examples/` produces findings and no errors. - **Local nightly on the staging image with this binary, all targets:** both bless and compare pass. The planted flaws are found again, now by our own rules: - Python fixtures: shell, credential and deserialisation; - JS fixtures: shell and reflected input; - cra-vuln-demo: SQL, shell, two credentials and http. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang changed target branch from feat/mobile-sbom to main 2026-10-01 18:45:42 +00:00
sharang added 1 commit 2026-10-01 18:45:42 +00:00
fix(sast): run only our own semgrep rules, no registry rules or metrics
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 9m42s
46b22e5589
The Semgrep registry rules (`--config=auto`, `p/...`) are licensed under the
Semgrep Rules License v1.0: internal business use only, not a service for
others. `auto` also refuses to run with metrics off, so every customer scan
reported to Semgrep. Semgrep now runs only rules/cra_semgrep.yaml, with
--metrics=off and --disable-version-check, and fails the stage if the rules
cannot be staged.

So that Python and JavaScript/TypeScript targets keep their core coverage,
eight rules of our own replace what the registry found in the fixtures:
shell commands and SQL built from variables, unsafe deserialisation,
request input echoed into an Express response (cra-ai-20), hard-coded
credentials in Python (cra-ai-8) and plain http:// requests (cra-ai-15).
Annotated cases live next to the rules (semgrep --test).

The control map's semgrep bindings now list exactly our rule ids and the
languages those rules cover. Before, they claimed Java, Go, Ruby, PHP, C#
and Kotlin on the strength of registry rules, so the CRA view could call
such code free of violations although nothing checked it; it now says
"Keine Prüfregel für den gefundenen Code".

The nightly harness drops `registry_rules`: every semgrep finding is now
deterministic and compared exactly. All baselines reblessed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang force-pushed feat/no-registry-rules from 3ad6cc538b to 46b22e5589 2026-10-01 18:45:42 +00:00 Compare
sharang merged commit a66b7a5991 into main 2026-10-05 13:03:44 +00:00
Sign in to join this conversation.