CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy MCP (push) Skipped
CI / Deploy Docs (push) Successful in 1m12s
CI / Deploy Dashboard (push) Successful in 7m8s
CI / Deploy Agent (push) Successful in 9m1s
The scan phase "CRA-Anforderungen zuordnen" could read as legal advice. It is now "Bezug zu CRA-Themen ermitteln (technischer Hinweis)"; the finding detail says "CRA-Themen, auf die dieser Befund hinweist" and "CRA-Themen (Anhang I)"; the CRA status page and the CRA tiles say "Technische Hinweise, keine rechtliche Bewertung". The docs use the same wording. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
170 lines
20 KiB
Markdown
170 lines
20 KiB
Markdown
# Compliance Control Mapping
|
||
|
||
::: info Technical hint, not a legal assessment
|
||
The link between a finding and a CRA topic is a technical hint from the scan.
|
||
It is not a legal assessment and not a conformity assessment.
|
||
:::
|
||
|
||
Control mapping connects the scanner's raw output — deterministic tool findings and the code itself — to the **compliance controls** each piece of evidence supports. A hardcoded credential stops being just "CWE-798 from semgrep" and becomes evidence for *"cra-ai-8: no default passwords"* and, at scale, master control *`mc-31761` hardcoded_secrets_detection*. Findings carry those references (`control_refs`) into the dashboard and out over the MCP server as OSCAL, so the compliance report is built from real, grounded findings rather than a questionnaire.
|
||
|
||
## The core principle: tools detect, the LLM judges
|
||
|
||
The design has one rule, borrowed from the ZeroFalse / IRIS line of research: **deterministic tools are the detectors; the LLM is only ever a grounded false-positive filter, never the thing that finds the issue.**
|
||
|
||
- A tool (semgrep, gitleaks, syft/osv, the PLC linter; the DAST agents today, with **Nuclei and ZAP planned** as deterministic web/OT detectors underneath them — see [Tools & Scanners](/reference/tools#planned-integrations-decided-2026-08-31-not-yet-in-the-code)) detects.
|
||
- An **authored, human-reviewed lookup table** (`control-map`) maps that detection to the control(s) it's evidence for.
|
||
- The LLM enters last, to *confirm or refute* the mapping against the actual code — and every surviving verdict is anchored to a verbatim snippet by the grounding gate. The judge decides the mapping, never whether a finding exists: a refuted finding is kept for a person to review, not hidden (#367).
|
||
|
||
This keeps hallucination out of detection. The LLM supplies cross-language, cross-stack pattern *recognition*; the surrounding machinery supplies determinism.
|
||
|
||
## Coverage model
|
||
|
||
Every control lands in one of three buckets, recorded in the `control-map` LUT (`control-map/data/cra_control_map.json`) and never decided by an LLM:
|
||
|
||
| Bucket | Meaning |
|
||
| --- | --- |
|
||
| `covered` | An existing tool's scan surfaces findings for this control |
|
||
| `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**. 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.
|
||
- **DevSkim** for C# and VB.NET (#494), bound **by CWE** (each DevSkim rule gets its CWE in `pipeline/devskim.rs`; its SARIF carries none): `cra-ai-1` (tracing), `8`, `10` (cookies without Secure), `13`, `14` (DPAPI without entropy), `15`, `16` and `20` (deserialisation, XXE).
|
||
- **Yocto recipe lint** (oelint-adv and our `yocto-config` rules), bound **by rule id** with the language `bitbake`: `cra-ai-1` (debug and root-login image features, sshd root/password logins, a distro without `security_flags.inc`), `cra-ai-8` (empty-password image features, passwords in `EXTRA_USERS_PARAMS`) `cra-ai-6` (downloads without a checksum, `AUTOREV`, git tags) and `cra-ai-2` (network access in tasks, `http://` fetches). `cra-ai-2` stays not code-checkable; these are its only bindings, so the CRA status assesses it only where the scanned languages include `bitbake` (a Yocto layer tree), and shows it as not code-checkable everywhere else.
|
||
- **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. A not-code-checkable control with a binding that applies to the scanned languages is assessed like a covered one there; today that is only `cra-ai-2` on Yocto layer trees.
|
||
|
||
### Languages, and what the CRA status may claim
|
||
|
||
Each binding in the control map names the **languages** its rules run on (`languages`, empty for language-independent tools such as gitleaks, syft and osv). A test keeps these in step with the rule pack. Each scan run records the source languages it saw outside vendor code (`ScanRun.languages`).
|
||
|
||
The CRA status calls a covered control **"checked, no findings"** only when one of its bindings applies to those languages *and* no tool it relies on failed in that scan (a skipped `sast`, `sast_c_cpp`, `sast_mobile`, `sast_dotnet`, `recipe_lint` or `cve_lookup` stage). Otherwise the control is **not checked**, with the reason: not scanned yet, no rule for the languages found, a tool that did not complete, or languages unknown (a run from before they were recorded). A C-only firmware repo therefore never reads "checked, no findings" for controls only Python rules check (#368, #387).
|
||
|
||
At scale, the **master-controls** corpus (breakpilot's deduped clusters, exported as OSCAL) currently provides **~2,882 code-checkable controls** (2,143 `network` + 739 `source_code`), matched semantically.
|
||
|
||
## The three mapping paths
|
||
|
||
```mermaid
|
||
flowchart TD
|
||
T[Deterministic tools\nsemgrep · gitleaks · syft/osv · DAST · PLC linter] --> F[Findings]
|
||
F --> B["Stage 5b — LUT triage\ncontrols_for(tool, cwe / rule_id)"]
|
||
F --> C["Stage 5c — Semantic\nembed region+intent → top-K master controls"]
|
||
R[Repo source] --> D["Stage 5d — Grounded surface\nretrieve surface for absence-based controls"]
|
||
B --> J{{Grounded LLM judge\ntemp 0 · verbatim snippet}}
|
||
C --> J
|
||
D --> J
|
||
J -->|snippet grounds in region| S[Stamp control_refs]
|
||
J -->|refuted| X[5b: finding kept as needs review\n5c/5d: nothing added]
|
||
J -->|no verdict: model down or unreadable| U[Left as it is]
|
||
```
|
||
|
||
All three paths converge on the same **grounded judge** and the same **grounding gate**. They differ only in how candidate (finding/region, control) pairs are produced.
|
||
|
||
### Stage 5b — deterministic LUT triage
|
||
|
||
The default path. A tool finding is matched to controls via `control_map.controls_for_finding(tool, cwe, rule_id)`; the judge then confirms each mapped control against the code region. Outcomes:
|
||
|
||
- `Confirmed([ids])`: stamp them.
|
||
- `NeedsReview`: the judge refuted every mapped control it could check. The finding stays, with the status **needs review** ("Zu prüfen") and a rationale, for a person to decide.
|
||
- `Undecided`: no verdict (the model was unreachable, its answer unreadable, or a control has no requirement text). The finding is left as it is.
|
||
- `Unmapped`: keep it untagged.
|
||
|
||
The general LLM triage before it (stage 5) follows the same rule: a finding it dismisses or confirms with low confidence is kept as needs review, never deleted. Runs whenever a catalog is available — either `BREAKPILOT_BASE_URL` points at a breakpilot-compliance backend, or a catalog snapshot is present (see [snapshot-only mode](#snapshot-only-mode)).
|
||
|
||
### Stage 5c — semantic retrieval (master-controls scale)
|
||
|
||
Master controls carry no CWE, so they can't be LUT-mapped. Instead we map by *similarity*: embed every control's requirement text once (cached), then for each finding retrieve the top-K nearest controls and hand them to the judge. Gated behind `BREAKPILOT_SEMANTIC_MAPPING` (default on; off on staging and production until the master-controls catalog is shipped, see #382). See [Semantic retrieval](#semantic-retrieval-in-detail).
|
||
|
||
### Stage 5d — grounded surface checks (absence-based controls)
|
||
|
||
Some controls are violated by an *absence* — no rate limiting on login, no security logging, no signature check on an update. There's no pattern for semgrep to match, so we deterministically retrieve the code **surface** the control governs (a login route, a logging setup, update/download code) by identifier/route terms, and let the judge decide whether the control holds there. Produces net-new, already-grounded findings. It reads C and C++ as well, with embedded terms (`crc32`, `ota_`, `bootloader`, `hal_flash`, `secure_boot`, `ecdsa`, `syslog`), and skips vendor code so the HAL and middleware don't fill its cap (#376). Gated behind `BREAKPILOT_GROUNDED_CHECKS` (default on).
|
||
|
||
## The grounding gate
|
||
|
||
No matter the path, a verdict becomes a finding only if it survives `compliance_core::control_check::ground`:
|
||
|
||
1. The judge runs at **temperature 0** with a closed prompt and must quote the offending code **verbatim** into `snippet`.
|
||
2. That snippet must appear **literally** in the retrieved region — otherwise the verdict is dropped.
|
||
3. The finding's line is **recomputed from the match**; the model's own line number is never trusted.
|
||
4. Verdicts are cached by content hash, so re-scans reproduce.
|
||
|
||
The model is allowed to be smart; it is never trusted.
|
||
|
||
## Semantic retrieval in detail
|
||
|
||
1. **Embed the corpus once.** Each control's requirement text is embedded with `bge-multilingual-gemma2` (3584-dim — multilingual matters, the master controls are in German while code is English). The embedding backend caps input arrays at 25 per request, so `embed()` chunks at 16; the whole `ControlIndex` is persisted to `snapshot_dir` keyed by a **corpus hash**, so only the first scan after a catalog change pays the embedding cost.
|
||
2. **Build the query from the finding's intent, not just the code.** The retrieval query is `finding.title + finding.description + region`, not the raw region. This is the single most important tuning: two findings in one file share overlapping windows and, on the code alone, embed alike and collapse onto the same controls. The finding's own words ("brute-force protection" vs "weak hash") carry the discriminating signal. The raw region still goes to the judge for grounding.
|
||
3. **Retrieve → judge → ground.** Top-K nearest by cosine, each judged against the region, each grounded.
|
||
|
||
## Worked examples
|
||
|
||
Both examples are from the live end-to-end verification (`c5_semantic_live.rs`) against the real ~2,882-control corpus.
|
||
|
||
### Example 1 — a small auth file (the tuning story)
|
||
|
||
Two findings in one `auth.py`: a weak `hashlib.md5(password)` hash and a login endpoint with no brute-force protection.
|
||
|
||
| Finding | Region-only retrieval | Intent-enriched retrieval |
|
||
| --- | --- | --- |
|
||
| Weak md5 hash | 19874, 20683, 23149, 29985 | **`mc-23149`** (eliminate weak unsalted hashes) at rank 1, + `mc-21634` salted hashing |
|
||
| Login w/o brute-force protection | *identical 4, reordered* | newly surfaces **`mc-19984`** brute_force_protection + **`mc-23186`** account_lockout |
|
||
|
||
Region-only retrieval gave both findings the *same* four password-hashing controls — the brute-force finding never found its real controls because its window is saturated with `password` tokens. Enriching the query with the finding's intent fixed it: the brute-force finding now pulls the correct rate-limiting / lockout controls out of the 2,882.
|
||
|
||
### Example 2 — four topically distinct vulnerabilities
|
||
|
||
| Finding | Top matched controls | Family |
|
||
| --- | --- | --- |
|
||
| SQL injection (string-concat query) | `sql_injection_prevention`, `sql_injection`, `parameterized_queries`, input_sanitization | input-validation ✓ |
|
||
| Hardcoded API credential | `hardcoded_secrets_detection`, credential_scanning, secrets_detection | credentials ✓ |
|
||
| TLS verification disabled (`verify=False`) | `https_enforcement`, `configuration_verification`, transport config | transport-encryption ✓ |
|
||
| Insecure deserialization (`pickle.loads`) | `deserialization`, `deserialization_testing`, `deserialization_security` | deserialization ✓ |
|
||
|
||
Every finding maps to its exact control family, with the most specific control often at the top, and the four sets are distinct.
|
||
|
||
## Known limitations
|
||
|
||
- **Absence findings are weak for semantic retrieval.** Similarity matches what code *is about*, not what it *lacks*; a "missing rate limiting" finding embeds like login code. This is exactly why the grounded surface path (Stage 5d) exists — it decides presence/absence at a retrieved surface rather than by embedding distance.
|
||
- **Generic catch-all controls co-occur.** `mc-20890 secure_development_security_code_review` appears in the top-K for many code-security findings because it is semantically near almost all of them. It's harmless (the judge grounds it, and it never crowds out the specific controls — the SQLi example didn't get it) but is a candidate for future down-weighting.
|
||
- **Corpus classification noise.** The master-controls `verification_method` classification is imperfect — e.g. a documentation control (`eu_declaration_accuracy`) is currently tagged `source_code`. That's a corpus-side data-quality issue, separate from the mapping engine.
|
||
|
||
## Emitting over MCP — closing the loop
|
||
|
||
Findings don't just land in the dashboard; they flow to breakpilot-compliance as OSCAL over the scanner's MCP server, so the compliance report is assembled from real, control-tagged findings.
|
||
|
||
- The MCP server exposes an **`oscal_assessment`** tool: given a `repo_id`, it emits a standard OSCAL 1.1 assessment-results document for that repo's findings — mapped findings target their controls via the stamped `control_refs`, and unmapped findings are reported **as-is** (as observations), so nothing is lost.
|
||
- breakpilot pulls it: `POST /v1/cra/oscal-from-scanner` calls `oscal_assessment` over MCP (Streamable HTTP + bearer) and consumes the pre-computed OSCAL — rather than pulling raw findings and re-assessing.
|
||
|
||
**Operational note — tenant context over HTTP.** The MCP server is multi-tenant; the bearer token resolves a tenant whose per-tenant database the tools query. rmcp's Streamable HTTP transport runs each session's tool calls in a `tokio::spawn`ed task, and `task_local`s do **not** cross a spawn — so binding the tenant in a per-request middleware `task_local` leaves tool handlers with no context (every call fails `no tenant context`). The fix is to bind the tenant to the **per-session server instance** at creation (the factory runs in the request scope before the spawn), not to a per-request task_local. Until this was fixed, the loop silently failed over HTTP and consumers fell back to demo data.
|
||
|
||
## Configuration
|
||
|
||
| Variable | Effect |
|
||
| --- | --- |
|
||
| `BREAKPILOT_BASE_URL` | breakpilot-compliance root; enables live control ingest. **Unset** falls back to the catalog snapshots in `BREAKPILOT_SNAPSHOT_DIR`; with neither, control mapping is off and findings carry no `control_refs`. |
|
||
| `BREAKPILOT_SEMANTIC_MAPPING` | Stage 5c (semantic master-controls mapping). **Default on** (validated live). |
|
||
| `BREAKPILOT_GROUNDED_CHECKS` | Stage 5d (grounded surface checks). **Default on** (validated live). |
|
||
| `BREAKPILOT_SNAPSHOT_DIR` | Where OSCAL catalog snapshots and the cached control-embedding index live. |
|
||
|
||
The semantic and grounded passes default **on** now that both are validated live; each is still a no-op if no catalog is reachable, so they only ever add coverage.
|
||
|
||
**On staging and production** (`platform/orca-platform` service files): `BREAKPILOT_BASE_URL` is unset, so the agent runs in [snapshot-only mode](#snapshot-only-mode) on the CRA catalog baked into the image. The LUT triage (5b) and the grounded surface checks (5d) run; `BREAKPILOT_SEMANTIC_MAPPING=false`, so the semantic pass (5c) does not, and PLC findings get no CRA control refs until the master-controls catalog is shipped (#281, #382).
|
||
|
||
### Snapshot-only mode
|
||
|
||
The catalog loader already snapshots the exact bytes it fetches (`oscal-catalog-<framework>.json` under `BREAKPILOT_SNAPSHOT_DIR`) and falls back to that snapshot when the backend is unreachable. Snapshot-only mode is the same path without ever having been online: the agent image ships `compliance-agent/controls/snapshot/oscal-catalog-cra.json` (CRA Annex I, 40 controls, built by breakpilot-compliance's `build_cra_catalog`), and the entrypoint copies it into `BREAKPILOT_SNAPSHOT_DIR` if no file of that name is there yet. With `BREAKPILOT_BASE_URL` unset the deterministic LUT triage (5b) and the grounded surface checks (5d) therefore run and findings carry CRA `control_refs`, while the semantic pass (5c) stays a no-op because `master-controls` is DB-derived and is not shipped — set `BREAKPILOT_SEMANTIC_MAPPING=false` in that environment to skip its warning.
|
||
|
||
Refresh the committed snapshot from a live backend with `scripts/refresh-oscal-snapshot.sh` (see its header); a fetched snapshot always wins over the baked one, because the entrypoint only copies what is absent. The live verifications live in `compliance-agent/tests/c5_semantic_live.rs` and `grounded_surface_live.rs` (ignored; run with `--ignored`).
|
||
|
||
## Appendix — the master-controls data pipeline
|
||
|
||
The master-controls corpus is produced by breakpilot-compliance and pulled as an OSCAL catalog from `GET /api/compliance/v1/oscal/catalog?framework=master-controls`. Two operational lessons are worth recording, because they cost real time to diagnose:
|
||
|
||
- **The catalog is served from `breakpilot_db`, not `postgres`.** Diagnostics run against the wrong database will look clean while the app serves something else entirely. Confirm the app's datname (`pg_stat_activity`) before trusting any count or `EXPLAIN`.
|
||
- **A constraint-less dump triplicated the master-control tables.** Restored without their PK/unique constraints, `master_controls` / `mc_verification` / `master_control_members` accumulated identical rows 3× (the same artifact migration `158` fixed for `doc_check_controls`). That inflated the catalog to ~26k dup'd controls and, with the indexes also missing, drove the export query to a >120s / 502. The fix (breakpilot migration `160`) ctid-dedups each table by its natural key and restores the constraints + indexes so it can't recur; the export query was also rewritten set-based (a single windowed pass instead of a per-row correlated subquery). After dedup: 41,850 → 13,950 master controls, catalog **25,938 → 2,882** code-checkable, endpoint **502 → 200 in ~3s**.
|