Files
pruefwerk/docs/guide/dotnet-en.md
T
sharangandClaude Opus 5.5 d8c52192d9
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Dashboard (push) Successful in 6m14s
CI / Deploy Agent (push) Successful in 8m21s
CI / Deploy Docs (push) Successful in 52s
CI / Deploy MCP (push) Successful in 3m28s
fix(sbom): .NET assemblies from DLL metadata mapped to NuGet ids (#460) (#474)
Syft names a DLL without a .deps.json by its version resource: product
name and file version. As a purl that is no NuGet package, so OSV
matched nothing: pkg:nuget/DotNetZip%20Library@1.9.1.5 has no advisory,
pkg:nuget/DotNetZip@1.9.1.5 has GHSA-7378-6268-4278.

Syft's dotnet-portable-executable-entry components are now mapped, in
this order:

- a DLL inside packages/<Id>.<Version>/ is that package
- a curated alias table, by assembly name (file name) and then product
  name (DotNetZip Library -> DotNetZip, Json.NET -> Newtonsoft.Json,
  Apache log4net -> log4net, Xceed Toolkit for WPF ->
  Extended.Wpf.Toolkit, empira MigraDoc -> PDFsharp-MigraDoc), with how
  the package's file versions relate to its versions (Newtonsoft.Json:
  first three parts; EntityFramework: unrelated, so the DLL only
  confirms a manifest entry)
- the assembly name, when it is a valid NuGet id and not one of the
  tree's own projects (project name or <AssemblyName>), whose names are
  not sent to OSV or nuget.org
- otherwise no purl, and the scan records the assembly as not matched
  against OSV

Alias before file name: DotNetZip ships Ionic.Zip.dll, and Ionic.Zip is
a different package. Versions go through nuget_license's
normalise_version (4.1.0.0 -> 4.1.0, +build dropped); a non-zero fourth
part stays (1.9.1.5 is a real NuGet version).

One package found in several DLLs, or in a DLL and a manifest, is one
entry: SbomEntry gains `evidence` (the manifests and DLLs it was read
from), and merge_nuget compares normalised versions and merges the
evidence instead of dropping it. Native pe-binary components are left
as they are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
2026-10-05 22:54:44 +00:00

128 lines
6.4 KiB
Markdown

---
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.
**Packages from DLLs.** Syft also reads DLLs (in `bin/`, `lib/`, committed
anywhere) and names them by their version resource: product name and file
version (`DotNetZip Library 1.9.1.5`, `Json.NET 13.0.1.25517`). Those are
mapped to the NuGet package: a DLL inside `packages/<Id>.<Version>/` is that
package; known product and assembly names map through a curated table
(`DotNetZip Library` → `DotNetZip`, `Json.NET` → `Newtonsoft.Json`, …);
otherwise the assembly name (file name) is the id. Versions are normalised as
NuGet files them (`4.1.0.0` → `4.1.0`, `+build` metadata dropped). The DLLs
of the tree's own projects (project name or `<AssemblyName>`) get no purl. A
DLL that cannot be mapped stays in the SBOM without a purl and is listed in
the scan as not matched against OSV. One package found in several places
(manifest and DLL, several DLLs) is one SBOM entry, with every place as
evidence.
**Licenses of NuGet packages.** First from the `.nuspec` of a restored package
(`packages/<Id>.<Version>/`): `<license type="expression">` as an SPDX
expression, `<license type="file">` as `LicenseRef-file`, an older
`<licenseUrl>` as an SPDX id when it points at a well-known license (MIT,
Apache-2.0, BSD, MS-PL, LGPL, …), otherwise as the URL. What is still missing
is looked up on nuget.org (the registration API on `api.nuget.org`, package id
and version only, no packages). Packages a `nuget.config` maps to another
source with `<packageSourceMapping>` are never looked up; when a `nuget.config`
lists another source without a mapping, nothing of that tree is looked up, as
a package id may be an internal one. Answers are cached for all tenants
(public data). `NUGET_LICENSE_LOOKUP=false` turns the lookup off for a
deployment.
**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.