feat(sast): DevSkim for .NET without a build (#494) (#506)
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy MCP (push) Skipped
CI / Deploy Docs (push) Successful in 1m19s
CI / Deploy Dashboard (push) Successful in 5m25s
CI / Deploy Agent (push) Successful in 8m23s

Legacy .NET Framework code often cannot be built outside the customer's
Windows toolchain, so no Roslyn analyser applies. DevSkim (MIT, Microsoft)
matches its rules on the source text and now runs as the sast_dotnet stage
on every tree with C# or VB.NET code: .cs, .vb, Razor/ASP.NET pages and
.config files, skipping bin/, obj/, packages/ and vendor directories
(anchored at the tree root).

- Only DevSkim's own rules at Critical/Important/Moderate (its ManualReview
  and BestPractice hints are not findings); DS205000 (NuGet feed mapping),
  DS184626 (controller base class) and DS440000 (generic twin of DS440020)
  are left out, and two that flood real C# (OpenRA, eShopOnWeb): DS148264
  matches any method named Random (71 hits in OpenRA), DS126858 the bare
  words md5/sha1, identifiers included (35). DS168931 and our own semgrep
  rules still cover broken hashes and System.Random. What remains: 3 hits
  in OpenRA (test vectors), 14 Low http:// hits in eShopOnWeb seed data;
  each run took about 2 s.
- SARIF is read with import::sarif::parse; findings are normalised like the
  other scanners (relative path, whole source line as snippet, one finding
  per rule/file/line), severity from DevSkim's own Critical/Important/
  Moderate (its SARIF level says "error" for both of the first two).
- DevSkim's SARIF names no CWE, so pipeline/devskim.rs gives each rule one;
  the control map binds the devskim tool by CWE to cra-ai-1, 8, 10, 13, 14,
  15, 16 and 20 for csharp and vb. A test checks every mapped rule reaches a
  control. A failed run is a sast_dotnet skip, so those controls read "not
  assessed" instead of clean.
- languages.rs now records VB.NET (vb).

Image: the CLI is published as a .NET tool on nuget.org only (no release
binaries). Dockerfile.agent pins the 1.0.100 nupkg by sha256 and the .NET
10.0.12 runtime (no SDK) by sha512, keeps only the linux-x64 natives, and
runs it through docker/devskim.sh with invariant globalisation (no ICU).
The tools stage grows from 1.525 GB to 1.623 GB (+98.5 MB: runtime 80 MB,
DevSkim 16 MB). Checked in that image as the unprivileged user with an empty
environment and --network none: it runs offline. tool-versions.json lists
devskim and dotnet-runtime.

Fixtures: fixtures/dotnet/legacy-sample, a small vulnerable C#/VB.NET
library with a Web.config (SSL 3, certificate validation off, DES, XXE,
BinaryFormatter in VB.NET, tracing, cookies without Secure), and nightly
targets for it and for framework48; their baselines need a bless run after
deploy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit was merged in pull request #506.
This commit is contained in:
sharangandClaude Opus 5.5 committed 2026-10-06 12:51:10 +00:00
1 parent e51a790d59
commit 34e3f6cf6a
18 files changed
+902 -3

No files matched your search

+2 -1
View File
@@ -29,6 +29,7 @@ For the **CRA** framework (40 controls) the split is **21 covered · 0 needs_too
- 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).
- **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.
@@ -36,7 +37,7 @@ For the **CRA** framework (40 controls) the split is **21 covered · 0 needs_too
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 **"no violation found"** 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` or `cve_lookup` stage). Otherwise the control is **not assessed**, 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 "no violation found" for controls only Python rules check (#368, #387).
The CRA status calls a covered control **"no violation found"** 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` or `cve_lookup` stage). Otherwise the control is **not assessed**, 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 "no violation found" 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.
+30
View File
@@ -102,6 +102,36 @@ Not reported: the app-wide "missing protection" hints (no certificate pinning,
no root or jailbreak detection, no screenshot protection). They name no place in
the code and are heuristics. Dart code (Flutter) has no rules yet.
## DevSkim -- .NET Without a Build
[DevSkim](https://github.com/microsoft/DevSkim) (MIT, Microsoft) runs on trees
with C# or VB.NET code (#494). Legacy .NET Framework solutions often cannot be
built outside the customer's Windows toolchain, which rules out the Roslyn
analysers; DevSkim matches its rules on the source text instead. It reads `.cs`,
`.vb`, Razor and ASP.NET pages (`.cshtml`, `.vbhtml`, `.razor`, `.aspx`,
`.ascx`, `.asmx`, `.asax`, `.master`) and `.config` files, and finds:
- broken hash classes and ciphers (`MD5CryptoServiceProvider`, `SHA1Managed`,
DES, 3DES, RC2, ECB);
- certificate validation switched off, outdated or hard-coded TLS versions,
plain `http://` URLs;
- unsafe deserialisers (`BinaryFormatter`, `NetDataContractSerializer`,
`SoapFormatter` …) and XML parsers that resolve external entities;
- tokens and private keys in source;
- `Web.config`: cookies without `Secure`, tracing switched on.
Only DevSkim's own rules at severity Critical, Important or Moderate are used;
its ManualReview and BestPractice hints are not reported, nor two rules that
flooded real C# code with false positives (any method named `Random`, the bare
words md5/sha1 in identifiers); our own Semgrep rules cover weak hashes and
`System.Random` precisely. `bin/`, `obj/`,
`packages/` and vendor directories are skipped. DevSkim's SARIF names no CWE,
so Prüfwerk gives each rule one, which ties it to its CRA control. The CLI runs
in the agent image on the .NET runtime, offline: nothing about the code leaves
the scan. Its findings are **Codeanalyse (SAST)** findings with the tool name
`devskim`; a run that fails is listed under *Nicht ausgeführt* as
`sast_dotnet`, and the controls it checks are then not assessed.
## Vendor Code Exclusion
Firmware projects carry their silicon vendor's SDK (HAL, CMSIS, board support)
@@ -23,6 +23,7 @@ together on stage in one pass before the next prod promotion.
| #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 |
| #494 | DevSkim: .NET SAST without a build (C#, VB.NET, .config) |
**Customer-visible on the next prod rescan** is marked **[visible]**: these
change what a customer sees on their existing targets, without them doing
@@ -495,6 +496,28 @@ alerts (e.g. the log4j/gson target of check 19).
- **[visible]** SBOM-Qualität card on the SBOM page, the score on cra-ai-23,
`sbom-quality.json` in the evidence pack. Expect a low BSI grade until the
export carries CycloneDX 1.6 and the TR's fields.
### 25. #494 DevSkim for .NET
- **Do:** upload `fixtures/dotnet/legacy-sample` and `fixtures/dotnet/framework48`
as **Archiv** and scan.
- **Expect:** Codeanalyse findings with the tool `devskim`: in the legacy
sample SSL 3 pinned (DS440020, DS144436), certificate validation off
(DS126187), DES (DS106864), `XmlUrlResolver` (DS132783),
`BinaryFormatter` in the VB file (DS425070), and in `Web.config`
tracing (DS450002) and cookies without Secure (DS450001); each with a CWE
and a CRA control (cra-ai-15, 13, 20, 1, 10). In framework48 the
`BinaryFormatter` in `OrderService.svc.cs`; nothing from `packages/` or
`bin/`. Severities follow DevSkim's (Critical High, Important Medium).
**Nicht ausgeführt** has no `sast_dotnet` entry; a Python-only target gets
no DevSkim run at all.
- **Log:** `DevSkim failed` must not appear. The image's
`/opt/pruefwerk/tool-versions.json` lists `devskim` 1.0.100 and
`dotnet-runtime` 10.0.12.
- **Offline:** the scan runs with the agent's egress as before; DevSkim opens
no connection (checked with `--network none`).
- **[visible]** on the next prod rescan: C# and VB.NET targets get new
Codeanalyse findings from DevSkim, and VB.NET code is now counted as a
language (controls DevSkim checks are assessed for it).
## After the pass