feat(dotnet): .NET detection, NuGet SBOM, C# rules and config checks (#447)
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Dashboard (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Docs (push) Successful in 1m10s
CI / Deploy Agent (push) Successful in 4m42s

Minimal .NET/C# support for epic #445 (N1-N5): detection of solutions/projects and target frameworks, NuGet SBOM without build or restore (pkg:nuget purls for OSV, unresolved-dependency warning, end-of-support frameworks), own C# semgrep rule pack, .NET configuration and key-file checks, .NET build output and restored packages not counted as own code. Fixture fixtures/dotnet/framework48, docs .NET-Projekte (DE/EN).

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 #447.
This commit is contained in:
sharangandClaude Opus 5.5 committed 2026-10-05 14:38:13 +00:00
1 parent 654f387c80
commit 8926255d6f
34 files changed
+3356 -43

No files matched your search

+2
View File
@@ -43,6 +43,8 @@ export default withMermaid(defineConfig({
{ text: 'Prüfobjekte anlegen', link: '/guide/repositories' },
{ text: 'Prüfungen', link: '/guide/scanning' },
{ text: 'SPS / PLC (CODESYS)', link: '/guide/plc' },
{ text: '.NET-Projekte', link: '/guide/dotnet' },
{ text: '.NET projects (English)', link: '/guide/dotnet-en' },
{ text: 'Befunde', link: '/guide/findings' },
{ text: 'Befunde aus manuellen Tests', link: '/guide/manual-findings' },
{ text: 'Stückliste (SBOM) und Lizenzen', link: '/guide/sbom' },
+100
View File
@@ -0,0 +1,100 @@
---
title: .NET projects
---
# .NET projects
Prüfwerk checks C# codebases on the classic **.NET Framework** (4.x, old
project style) and on **.NET** (Core, 5 and later, SDK project style).
Everything is read from the files: Prüfwerk builds nothing, runs no
`dotnet restore` and downloads no packages.
## What is checked
**Detection.** Solutions (`.sln`) and projects (`.csproj`, `.vbproj`,
`.fsproj`) at any depth, with their project style (old or SDK) and target
framework(s) (`TargetFrameworkVersion`, `TargetFramework`,
`TargetFrameworks`). The target records them as detected facts:
`dotnet_runtime` (`dotnet-framework`, `dotnet`, `dotnet-standard`), every
solution as a component of its own (`dotnet_solution`) and every project
(`dotnet_project`, e.g. `Plant.Hmi/Plant.Hmi.csproj (legacy; net48)`).
**NuGet SBOM and CVEs.** Packages come from
- `packages.config` (which lists the transitive packages too),
- `<PackageReference>` in project files, with the version as an attribute, a
child element, a `VersionOverride`, or centrally from
`Directory.Packages.props`,
- `packages.lock.json` and `obj/project.assets.json` (the full resolution),
- committed package folders `packages/<Id>.<Version>/`.
Every package with an exact version gets the purl `pkg:nuget/<Id>@<Version>`
and is matched against OSV (ecosystem NuGet). A version range (`7.*`,
`[1.0,2.0)`) is listed without a purl, with the range as its requirement.
**Dependencies not fully resolved.** A project with `<PackageReference>` items
and neither `packages.lock.json` nor `obj/project.assets.json` names only its
direct packages. The scan lists it under **Nicht ausgeführt**
(`sbom_dependencies`), and the SBOM requirements of the CRA view stay **Nicht
bewertet** until a lockfile is committed.
**Recommendation:** switch lockfiles on and commit them:
```xml
<!-- in each project, or once in Directory.Build.props -->
<PropertyGroup>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
```
Then restore once (`dotnet restore`, or in Visual Studio) and commit the
`packages.lock.json` files.
**Target framework out of support.** A project targeting a .NET Framework or
.NET version Microsoft no longer ships security updates for (e.g. .NET
Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1; .NET Core 3.1; .NET 5, 6, 7) is
a finding (CWE-1104, CRA requirement dependency monitoring `cra-ai-22`). .NET
Framework 4.6.2 ends on 2027-01-12, .NET 8 and 9 on 2026-11-10; the scan
reports them from then on.
**C# code (our own Semgrep rules):** SQL built by concatenation, interpolation
or `String.Format` (CWE-89), `Process.Start` with a composed command line
(CWE-78), `BinaryFormatter` and friends or JSON.NET `TypeNameHandling` other
than `None` (CWE-502), XML parsing with DTDs or an external resolver (CWE-611),
file paths from `Request` input (CWE-22), MD5/SHA-1/DES/3DES/RC2 and ECB mode
(CWE-327), certificate validation switched off (CWE-295), and hard-coded
passwords and keys (CWE-798). The rule ids and CRA controls are listed on the
[German page](/guide/dotnet).
**Configuration** (`web.config`, `app.config`, other `*.config`): clear-text
passwords in `connectionStrings` and secret-like `appSettings` (not empty,
`***REDACTED***` or deployment placeholders; CWE-260, cra-ai-9), `<compilation
debug="true">` and `<customErrors mode="Off">` unless a `Web.Release.config`
transform fixes them (CWE-489/CWE-209, cra-ai-1), `<httpCookies>` without
`requireSSL`/`httpOnlyCookies` (CWE-614, cra-ai-10), and WCF bindings with
`security mode="None"`/`TransportCredentialOnly` or a `basicHttpBinding`
without transport security (CWE-319, cra-ai-15).
**Keys and publish profiles in the repository** (tool `secret-files`):
`.pfx`/`.p12`, `.jks`/`.keystore` and `.snk` key pairs (CWE-321, cra-ai-16),
`.publishsettings`, `.pubxml.user` and `.pubxml` with a password (CWE-260,
cra-ai-9).
## What does not count as own code
Build output and restored packages: `bin/` and `obj/` beside a project or
solution, `packages/` holding NuGet packages, `.vs/`, `.nuget/` and
`TestResults/`. SAST, patterns, secrets and lint skip them (the scan names
them under **Nicht ausgeführt**); the SBOM still reads `packages/`.
`*.Designer.cs` and generated XAML code stay own code.
## What is not checked (yet)
- No build and no Roslyn analyzers (Security Code Scan): they need a build
that runs project code.
- No data flow across methods: the C# rules see patterns within a method.
- Committed DLLs outside `packages/` (e.g. `lib/`) are not listed as
components with a hash; installers and binaries are not scanned.
- No code graph for C# (tree-sitter), no C# lint rules.
- VB.NET and F# projects are detected and their packages read, but their code
is not checked by rules.
+112
View File
@@ -0,0 +1,112 @@
---
title: .NET-Projekte
---
# .NET-Projekte
Prüfwerk prüft C#-Codebasen mit dem klassischen **.NET Framework** (4.x, alter
Projektstil) und mit **.NET** (Core, 5 und neuer, SDK-Projektstil). Alles wird
aus den Dateien gelesen: Prüfwerk baut nichts, führt kein `dotnet restore` aus
und lädt keine Pakete aus dem Netz.
## Was geprüft wird
**Erkennung.** Solutions (`.sln`) und Projekte (`.csproj`, `.vbproj`,
`.fsproj`) in jeder Verzeichnistiefe, mit Projektstil (alt oder SDK) und
Zielframework(s) (`TargetFrameworkVersion`, `TargetFramework`,
`TargetFrameworks`). Am Prüfobjekt stehen als erkannte Fakten:
`dotnet_runtime` (`dotnet-framework`, `dotnet`, `dotnet-standard`), jede
Solution als eigene Komponente (`dotnet_solution`) und jedes Projekt
(`dotnet_project`, z. B. `Plant.Hmi/Plant.Hmi.csproj (legacy; net48)`).
**NuGet-Stückliste (SBOM) und CVEs.** Die Pakete kommen aus
- `packages.config` (enthält auch die transitiven Pakete),
- `<PackageReference>` in den Projektdateien, mit der Version als Attribut,
als Unterelement, als `VersionOverride` oder zentral aus
`Directory.Packages.props`,
- `packages.lock.json` und `obj/project.assets.json` (vollständige Auflösung),
- eingecheckten Paketordnern `packages/<Id>.<Version>/`.
Jedes Paket mit fester Version erhält die purl `pkg:nuget/<Id>@<Version>` und
wird gegen OSV (Ökosystem NuGet) abgeglichen. Ein Versionsbereich (`7.*`,
`[1.0,2.0)`) steht ohne purl in der Stückliste, mit dem Bereich als
Anforderung.
**Unvollständig aufgelöste Abhängigkeiten.** Ein Projekt mit
`<PackageReference>` ohne `packages.lock.json` und ohne
`obj/project.assets.json` nennt nur seine direkten Pakete. Die Prüfung führt
es unter **Nicht ausgeführt** (`sbom_dependencies`), und die SBOM-Anforderungen
der CRA-Ansicht sind **Nicht bewertet**, bis eine Lockdatei vorliegt.
**Empfehlung:** Lockdateien einschalten und einchecken:
```xml
<!-- in jedem Projekt oder einmal in Directory.Build.props -->
<PropertyGroup>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
```
Danach einmal `dotnet restore` (bzw. in Visual Studio wiederherstellen) und die
entstandenen `packages.lock.json` einchecken.
**Zielframework ohne Support.** Ein Projekt, das ein .NET Framework oder .NET
ohne Sicherheitsupdates von Microsoft anspricht (z. B. .NET Framework 4.0,
4.5, 4.5.1, 4.5.2, 4.6, 4.6.1; .NET Core 3.1; .NET 5, 6, 7), ist ein Befund
(CWE-1104, CRA-Anforderung Dependency-Monitoring `cra-ai-22`). .NET Framework
4.6.2 endet am 12.01.2027, .NET 8 und 9 am 10.11.2026; danach meldet die
Prüfung auch sie.
**C#-Code (eigene Semgrep-Regeln).**
| Regel | Was | CWE | CRA |
|---|---|---|---|
| `cra-ai-20-csharp-sql-string` | SQL per Verkettung, Interpolation oder `String.Format` in `SqlCommand`, `CommandText`, `ExecuteSqlCommand`, `FromSqlRaw`, `SqlQuery` | CWE-89 | cra-ai-20 |
| `cra-ai-20-csharp-process-start` | `Process.Start`/`ProcessStartInfo` mit zusammengesetzter Kommandozeile | CWE-78 | cra-ai-20 |
| `cra-ai-20-csharp-unsafe-deserialization` | `BinaryFormatter`, `NetDataContractSerializer`, `LosFormatter`, `SoapFormatter`, `ObjectStateFormatter`, JSON.NET `TypeNameHandling` ≠ `None` | CWE-502 | cra-ai-20 |
| `cra-ai-20-csharp-xxe` | `XmlDocument`/`XmlTextReader` ohne `XmlResolver = null`/`DtdProcessing.Prohibit`, `DtdProcessing.Parse`, `XmlUrlResolver` | CWE-611 | cra-ai-20 |
| `cra-ai-20-csharp-path-traversal` | Dateipfad aus `Request`-Eingaben (`File.*`, `Path.Combine`, `FileStream`) | CWE-22 | cra-ai-20 |
| `cra-ai-13-csharp-broken-hash-or-cipher` | MD5, SHA-1, DES, 3DES, RC2 | CWE-327 | cra-ai-13 |
| `cra-ai-13-csharp-ecb-mode` | `CipherMode.ECB` | CWE-327 | cra-ai-13 |
| `cra-ai-15-csharp-cert-validation-disabled` | Zertifikatsprüfung abgeschaltet (`ServerCertificateValidationCallback … => true`, `DangerousAcceptAnyServerCertificateValidator`) | CWE-295 | cra-ai-15 |
| `cra-ai-8-csharp-hardcoded-credential` | Passwort/Schlüssel als String-Literal | CWE-798 | cra-ai-8 |
**Konfiguration** (`web.config`, `app.config`, weitere `*.config`):
| Regel | Was | CWE | CRA |
|---|---|---|---|
| `dotnet-config-cleartext-password` | `Password=`/`Pwd=` im Klartext in `connectionStrings`; Passwort-/Schlüssel-Einträge in `appSettings` (nicht: leer, `***REDACTED***`, Platzhalter wie `#{…}#`, `${…}`, `__…__`) | CWE-260 | cra-ai-9 |
| `dotnet-config-debug-compilation` | `<compilation debug="true">` (außer eine `Web.Release.config` entfernt es) | CWE-489 | cra-ai-1 |
| `dotnet-config-custom-errors-off` | `<customErrors mode="Off">` (außer die Release-Transformation setzt es) | CWE-209 | cra-ai-1 |
| `dotnet-config-insecure-cookies` | `<httpCookies>` ohne `requireSSL="true"` oder `httpOnlyCookies="true"` | CWE-614 | cra-ai-10 |
| `dotnet-config-wcf-insecure-binding` | WCF-Binding mit `security mode="None"` oder `TransportCredentialOnly`, `basicHttpBinding` ohne Transportsicherheit (Named Pipes ausgenommen) | CWE-319 | cra-ai-15 |
**Schlüssel und Veröffentlichungsprofile im Repository** („Geheimnis im
Repository“, Werkzeug `secret-files`): `.pfx`/`.p12`, `.jks`/`.keystore`
(cra-ai-16, CWE-321), Strong-Name-Schlüsselpaare `.snk` (nur Schlüsselpaare;
eine Datei mit nur dem öffentlichen Schlüssel ist kein Befund),
`.publishsettings`, `.pubxml.user` und `.pubxml` mit Passwort (cra-ai-9,
CWE-260).
## Was nicht als eigener Code zählt
Build-Ausgaben und wiederhergestellte Pakete sind nicht Ihr Code: `bin/` und
`obj/` neben einem Projekt oder einer Solution, `packages/` mit
NuGet-Paketen, `.vs/`, `.nuget/` und `TestResults/`. SAST, Muster, Geheimnisse
und Lint überspringen sie (die Prüfung nennt sie unter **Nicht ausgeführt**);
die Stückliste liest `packages/` trotzdem. `*.Designer.cs` und generierter
XAML-Code bleiben eigener Code.
## Was (noch) nicht geprüft wird
- Kein Build, keine Roslyn-Analyzer (Security Code Scan): sie bräuchten einen
Build mit Ausführung von Projektcode.
- Keine Datenflussanalyse über Methoden hinweg: die C#-Regeln sehen Muster
innerhalb einer Methode.
- Eingecheckte DLLs außerhalb von `packages/` (z. B. `lib/`) werden nicht als
Komponenten mit Hash erfasst; Installer und Binärdateien werden nicht
gescannt.
- Kein Code-Graph für C# (tree-sitter), keine C#-Lint-Regeln.
- VB.NET- und F#-Projekte werden erkannt und ihre Pakete gelesen, aber ihr
Code nicht mit Regeln geprüft.
+4
View File
@@ -31,6 +31,10 @@ Prüfwerk builds the SBOM during each scan:
**Nicht ausgeführt** and the SBOM requirements of the CRA view are
**Nicht bewertet**: an app whose dependencies are unknown is not shown as
clean.
- **.NET / NuGet** -- `packages.config`, `<PackageReference>` (also with
central versions in `Directory.Packages.props`), `packages.lock.json`,
`obj/project.assets.json` and committed `packages/<Id>.<Version>/` folders,
read without a build; see [.NET-Projekte](/guide/dotnet).
- **Libraries copied into a firmware tree** -- microcontroller projects carry
their RTOS, TCP/IP stack and TLS library as source, with no manifest. Prüfwerk
recognises **FreeRTOS**, **FreeRTOS+TCP**, **lwIP**, **Mbed TLS**, **wolfSSL**