feat(dotnet): .NET detection, NuGet SBOM, C# rules and config checks #447

Merged
sharang merged 3 commits from feat/dotnet-minimal into main 2026-10-05 14:38:14 +00:00
Owner

Minimal .NET/C# support for epic #445: stories N1–N5. N6 (tree-sitter graph, lint) is out of scope.

What

  • N1 detection (pipeline/dotnet/mod.rs, classify/dotnet.rs): finds .sln and .csproj/.vbproj/.fsproj at any depth, tells old from SDK project style, and reads TargetFramework(s)/TargetFrameworkVersion. The target records them as facts: dotnet_runtime (framework / dotnet / standard), each solution as a component (dotnet_solution), and each project with its style and frameworks (dotnet_project). language.rs is untouched; the parallel session owns it.

  • N2 NuGet SBOM (pipeline/sbom/nuget.rs): reads packages.config, <PackageReference> (version as attribute, child element, VersionOverride or central Directory.Packages.props), packages.lock.json, obj/project.assets.json and packages/<Id>.<Version>/. No build and no restore. Packages get pkg:nuget/<id>@<version> purls, which feed the existing OSV stage. Syft duplicates are skipped. A version range gets no purl and keeps the range as version_requirement.

    • A <PackageReference> project without a lockfile or assets file raises the #440 sbom_dependencies warning, so the CRA view leaves the SBOM requirements not assessed. A packages.config project already lists its transitive packages, so it does not raise it.
    • A target framework past Microsoft's end of support is a finding (dotnet-lifecycle, CWE-1104, cra-ai-22). The dates come from Microsoft's lifecycle pages, so .NET 8/9 (2026-11-10) and 4.6.2 (2027-01-12) are flagged once those dates pass.
  • N3-lite C# rules: a new pack rules/cra_semgrep_csharp.yaml with test cases in rules/cra_semgrep_csharp.cs. It covers:

    • SQL injection (CWE-89), Process.Start with a built command line (CWE-78), BinaryFormatter/NetDataContractSerializer/LosFormatter/SoapFormatter and TypeNameHandling other than None (CWE-502), XXE (CWE-611) and path traversal from Request (CWE-22): cra-ai-20
    • MD5/SHA-1/DES/3DES/RC2 and ECB mode (CWE-327): cra-ai-13
    • certificate validation switched off (CWE-295): cra-ai-15
    • hard-coded credentials (CWE-798): cra-ai-8

    We wrote these rules ourselves; nothing comes from a registry or third-party pack. semgrep.rs now runs every bundled pack. A test keeps the list equal to rules/*.yaml. The first pack keeps its staged name, so existing check_ids and fingerprints do not change.

  • N4 config checks (pipeline/dotnet/config.rs, run in the pattern stage):

    • *.config (scanner dotnet-config):
      • clear-text Password=/Pwd= in connection strings and secret-like appSettings, skipping empty values and placeholders such as ***REDACTED*** (CWE-260, cra-ai-9)
      • compilation debug="true" and customErrors mode="Off", unless a Web.Release.config transform fixes them (cra-ai-1)
      • httpCookies without requireSSL/httpOnlyCookies (cra-ai-10)
      • WCF bindings with security mode None/TransportCredentialOnly, and basicHttpBinding without transport security (cra-ai-15)
    • Committed .pfx/.p12/.jks/.keystore, .snk key pairs, .publishsettings, .pubxml.user and .pubxml with a password are reported as secret-files (cra-ai-16 / cra-ai-9).
    • All three scanner names count as completed for the #443 auto-resolve.
  • N5 (vendor.rs, a block added at the end): these are not counted as own code:

    • bin/ and obj/ next to a project or solution
    • packages/ holding restored NuGet packages (folder named <Id>.<Version> with a .nupkg or lib/), so a JavaScript monorepo's packages/ stays own code
    • .vs/, .nuget/, TestResults/
  • New control-map bindings for each rule. dotnet-lifecycle is treated as a component tool.

  • Fixture fixtures/dotnet/framework48 (.NET Framework 4.8, old project style, packages.config with Newtonsoft.Json 12.0.1 → GHSA-5crp-9r3c-p9vr, web.config with a clear-text password and WCF security None, C# with 4 rule hits). It is tested in pipeline/dotnet/fixture_tests.rs; the semgrep part runs only when semgrep is installed.

  • Docs: docs/guide/dotnet.md (DE) and dotnet-en.md (EN), recommending RestorePackagesWithLockFile.

Not in this PR

  • N6 (tree-sitter C#, lint, C# prompts)
  • Roslyn / Security Code Scan
  • DLLs by hash outside packages/, and notes for installers and binaries
  • Dashboard labels for the new scanner names
  • A nightly target for the fixture: it needs a blessed baseline

Checks

cargo fmt --check, clippy -D warnings (agent, control-map), cargo test -p compliance-agent -p control-map --lib, semgrep --test compliance-agent/rules (17/17)

🤖 Generated with Claude Code

https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB

Minimal .NET/C# support for epic #445: stories N1–N5. N6 (tree-sitter graph, lint) is out of scope. ## What - **N1 detection** (`pipeline/dotnet/mod.rs`, `classify/dotnet.rs`): finds `.sln` and `.csproj`/`.vbproj`/`.fsproj` at any depth, tells old from SDK project style, and reads `TargetFramework(s)`/`TargetFrameworkVersion`. The target records them as facts: `dotnet_runtime` (framework / dotnet / standard), each solution as a component (`dotnet_solution`), and each project with its style and frameworks (`dotnet_project`). `language.rs` is untouched; the parallel session owns it. - **N2 NuGet SBOM** (`pipeline/sbom/nuget.rs`): reads `packages.config`, `<PackageReference>` (version as attribute, child element, `VersionOverride` or central `Directory.Packages.props`), `packages.lock.json`, `obj/project.assets.json` and `packages/<Id>.<Version>/`. No build and no restore. Packages get `pkg:nuget/<id>@<version>` purls, which feed the existing OSV stage. Syft duplicates are skipped. A version range gets no purl and keeps the range as `version_requirement`. - A `<PackageReference>` project without a lockfile or assets file raises the #440 `sbom_dependencies` warning, so the CRA view leaves the SBOM requirements not assessed. A `packages.config` project already lists its transitive packages, so it does not raise it. - A target framework past Microsoft's end of support is a finding (`dotnet-lifecycle`, CWE-1104, cra-ai-22). The dates come from Microsoft's lifecycle pages, so .NET 8/9 (2026-11-10) and 4.6.2 (2027-01-12) are flagged once those dates pass. - **N3-lite C# rules**: a new pack `rules/cra_semgrep_csharp.yaml` with test cases in `rules/cra_semgrep_csharp.cs`. It covers: - SQL injection (CWE-89), `Process.Start` with a built command line (CWE-78), `BinaryFormatter`/`NetDataContractSerializer`/`LosFormatter`/`SoapFormatter` and `TypeNameHandling` other than None (CWE-502), XXE (CWE-611) and path traversal from `Request` (CWE-22): cra-ai-20 - MD5/SHA-1/DES/3DES/RC2 and ECB mode (CWE-327): cra-ai-13 - certificate validation switched off (CWE-295): cra-ai-15 - hard-coded credentials (CWE-798): cra-ai-8 We wrote these rules ourselves; nothing comes from a registry or third-party pack. `semgrep.rs` now runs every bundled pack. A test keeps the list equal to `rules/*.yaml`. The first pack keeps its staged name, so existing check_ids and fingerprints do not change. - **N4 config checks** (`pipeline/dotnet/config.rs`, run in the pattern stage): - `*.config` (scanner `dotnet-config`): - clear-text `Password=`/`Pwd=` in connection strings and secret-like `appSettings`, skipping empty values and placeholders such as `***REDACTED***` (CWE-260, cra-ai-9) - `compilation debug="true"` and `customErrors mode="Off"`, unless a `Web.Release.config` transform fixes them (cra-ai-1) - `httpCookies` without `requireSSL`/`httpOnlyCookies` (cra-ai-10) - WCF bindings with security mode `None`/`TransportCredentialOnly`, and `basicHttpBinding` without transport security (cra-ai-15) - Committed `.pfx`/`.p12`/`.jks`/`.keystore`, `.snk` key pairs, `.publishsettings`, `.pubxml.user` and `.pubxml` with a password are reported as `secret-files` (cra-ai-16 / cra-ai-9). - All three scanner names count as completed for the #443 auto-resolve. - **N5** (`vendor.rs`, a block added at the end): these are not counted as own code: - `bin/` and `obj/` next to a project or solution - `packages/` holding restored NuGet packages (folder named `<Id>.<Version>` with a `.nupkg` or `lib/`), so a JavaScript monorepo's `packages/` stays own code - `.vs/`, `.nuget/`, `TestResults/` - New control-map bindings for each rule. `dotnet-lifecycle` is treated as a component tool. - Fixture `fixtures/dotnet/framework48` (.NET Framework 4.8, old project style, `packages.config` with Newtonsoft.Json 12.0.1 → GHSA-5crp-9r3c-p9vr, `web.config` with a clear-text password and WCF security None, C# with 4 rule hits). It is tested in `pipeline/dotnet/fixture_tests.rs`; the semgrep part runs only when semgrep is installed. - Docs: `docs/guide/dotnet.md` (DE) and `dotnet-en.md` (EN), recommending `RestorePackagesWithLockFile`. ## Not in this PR - N6 (tree-sitter C#, lint, C# prompts) - Roslyn / Security Code Scan - DLLs by hash outside `packages/`, and notes for installers and binaries - Dashboard labels for the new scanner names - A nightly target for the fixture: it needs a blessed baseline ## Checks `cargo fmt --check`, clippy `-D warnings` (agent, control-map), `cargo test -p compliance-agent -p control-map --lib`, `semgrep --test compliance-agent/rules` (17/17) 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang force-pushed feat/dotnet-minimal from d95f76a0e0 to 75713d09b6 2026-10-05 13:48:40 +00:00 Compare
sharang force-pushed feat/dotnet-minimal from 75713d09b6 to fef7912b29 2026-10-05 14:01:39 +00:00 Compare
sharang force-pushed feat/dotnet-minimal from fef7912b29 to 3f9183e54e 2026-10-05 14:14:12 +00:00 Compare
sharang added 3 commits 2026-10-05 14:28:11 +00:00
Minimal .NET/C# support for epic #445 (N1-N5; N6 out of scope):

- N1: solutions and .csproj/.vbproj/.fsproj at any depth, old vs SDK
  style, TargetFramework(s)/TargetFrameworkVersion; recorded as target
  facts (dotnet_runtime, dotnet_solution, dotnet_project).
- N2: NuGet components from packages.config, PackageReference (attribute,
  child element, VersionOverride, Directory.Packages.props),
  packages.lock.json, obj/project.assets.json and packages/<Id>.<Version>/
  with pkg:nuget purls for OSV. PackageReference projects without lockfile
  or assets are reported as unresolved (sbom_dependencies). Target
  frameworks past Microsoft's end of support are findings (CWE-1104).
- N3-lite: own semgrep rule pack cra_semgrep_csharp.yaml (SQLi, command
  injection, deserialization, XXE, path traversal, weak crypto/ECB, TLS
  validation off, hard-coded credentials) with semgrep --test cases;
  semgrep.rs runs every bundled pack.
- N4: web.config/app.config checks (clear-text passwords, debug,
  customErrors, httpCookies, WCF security) and committed key/publish files.
- N5: bin/obj beside projects, NuGet packages/, .vs, .nuget, TestResults
  are not own code.

Control map bindings, fixtures/dotnet/framework48 with a test, and docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
fix(sast): stage every rule pack under a per-call unique tmp name
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 9m24s
64ddaf37c1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang force-pushed feat/dotnet-minimal from 3f9183e54e to 64ddaf37c1 2026-10-05 14:28:11 +00:00 Compare
sharang merged commit 8926255d6f into main 2026-10-05 14:38:14 +00:00
sharang deleted branch feat/dotnet-minimal 2026-10-05 14:38:14 +00:00
Sign in to join this conversation.