In the .NET 10 SDK, what does NuGetAudit check during restore, how do NuGetAuditMode and NuGetAuditLevel default, and how do you fail CI on findings?
answer
- on by default since the .NET 8 SDK
- NuGetAuditLevel low
- mode all only for net10.0 and later
- NU1901 low to NU1904 critical
- NuGetAuditSuppress takes the advisory URL
basics
~20 sRestore compares every audited package against advisories from the audit sources and warns NU1901 to NU1904 by severity. NuGetAudit is true and NuGetAuditLevel is low by default; NuGetAuditMode is all for net10.0+ projects and direct otherwise. Add NU1903;NU1904 to WarningsAsErrors to fail CI.
solid answer
~40 s**NuGetAudit** runs inside restore: NuGet downloads vulnerability data from the **audit sources** (the `<auditSources>` in nuget.config, or the package sources when none are set; nuget.org's data comes from the GitHub Advisory Database) and warns **NU1901** (low), **NU1902** (moderate), **NU1903** (high) or **NU1904** (critical). Defaults in `NuGet.targets`: `NuGetAudit=true`, `NuGetAuditLevel=low`, and `NuGetAuditMode=all` (direct **and transitive**) only when the project targets .NET 10 or later — `direct` otherwise; if any target framework of a multi-targeted project selects `all`, all do. To gate CI, add `NU1903;NU1904` to `WarningsAsErrors`; with `TreatWarningsAsErrors`, use `WarningsNotAsErrors` to keep low findings advisory. A reviewed false positive gets `<NuGetAuditSuppress Include="advisory URL" />`. Fix transitive findings with `dotnet nuget why`, then upgrade the parent or reference the package directly.
code
xml · 12 lines<!-- Directory.Build.props -->
<Project>
<PropertyGroup>
<NuGetAuditLevel>low</NuGetAuditLevel>
<!-- fail the build on high and critical advisories only -->
<WarningsAsErrors>$(WarningsAsErrors);NU1903;NU1904</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<!-- reviewed: not reachable in our usage, see risk register -->
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-xxxx-xxxx-xxxx" />
</ItemGroup>
</Project>go deeper
Recall that restore warns about vulnerable packages with NU1901 to NU1904 and that you fix them by upgrading the package.
Explain the three properties and their defaults, the .NET 10 change to transitive auditing, the warning codes, and how WarningsAsErrors gates a build.
Run audit in a regulated pipeline: audit sources for internal-only feeds, gating by severity code, tracing transitive findings with dotnet nuget why, and governed suppressions.
Own the vulnerability policy: severity thresholds, exception approval, how fast fixes must land, and how audit evidence is retained for regulators.
## What NuGetAudit is Since the .NET 8 SDK (NuGet 6.8), **restore audits packages**: after resolving the graph, NuGet fetches a vulnerability database from its audit sources and reports every audited package version that has a known advisory. No extra tool is involved; it happens on every `dotnet restore`, `build` or `test` that restores. ## The settings and their defaults The defaults are set in `NuGet.targets`: | Property | Default | Values | |---|---|---| | `NuGetAudit` | `true` | `true`, `false` | | `NuGetAuditLevel` | `low` | `low`, `moderate`, `high`, `critical` | | `NuGetAuditMode` | `all` when the project targets .NET 10 or later, otherwise `direct` | `direct`, `all` | The mode default is the .NET 10 change people trip over. A project targeting `net10.0` is now warned about **transitive** packages too; the same code targeting `net8.0` or `net9.0` is still audited on direct references only. In a multi-targeted project, if any target framework selects `all`, audit uses `all` for every target framework. Teams that turned warnings into errors can see a .NET 10 upgrade fail restore because of a transitive advisory they never saw before. ## Warning codes - **NU1901 / NU1902 / NU1903 / NU1904** — a package with a low, moderate, high or critical advisory. - **NU1900** — an error talking to a source while fetching vulnerability data. - **NU1905** — a configured audit source offers no vulnerability database. ## Where the data comes from Restore downloads each source's `VulnerabilityInfo` resource. By default that means the package sources themselves. A bank whose only package source is an internal feed may get no advisory data at all — and because NU1905 is suppressed when no `<auditSources>` are configured, nothing warns about the gap. `nuget.config` can therefore name separate **audit sources**: ```xml <auditSources> <clear /> <add key="nuget.org" value="https://data.nuget.org/v3/index.json" /> </auditSources> ``` `data.nuget.org` serves only vulnerability data, so it can be allowed through a firewall that blocks package downloads from `api.nuget.org`. ## Reading a finding Each warning carries everything needed to act on it: the code, the package id and version, the severity and the advisory URL — for example `warning NU1902: Package 'NuGet.Protocol' 5.11.2 has a known moderate severity vulnerability`, followed by a GitHub advisory link. The URL is also the key for a suppression, and the package id is the input to `dotnet nuget why` when the package is not one you reference directly. Because the data is downloaded during restore, a branch that built cleanly yesterday can warn today without any code change: a new advisory was published, not a new bug written. ## Making CI fail — deliberately Audit findings are warnings. A regulated pipeline usually gates on the serious ones: 1. Add `<WarningsAsErrors>$(WarningsAsErrors);NU1903;NU1904</WarningsAsErrors>` in `Directory.Build.props`, so high and critical findings fail the build while low and moderate stay visible. 2. If the repository already uses `TreatWarningsAsErrors`, do the reverse: `WarningsNotAsErrors` with the codes you want to keep advisory, so a newly published advisory does not break every branch overnight. 3. Keep `NuGetAuditLevel` at `low` so the report stays complete; gating is done by code, not by hiding findings. ## Handling a finding - **Direct package:** move to a fixed version. NuGet 7 added `dotnet package update --vulnerable`, which upgrades packages with known vulnerabilities. - **Transitive package:** run `dotnet nuget why <project> <package>` to find the top-level package that brings it in and upgrade that; if none fixes it, add a direct reference to a patched version (or a central pin under Central Package Management). - **Not exploitable in your use:** add `<NuGetAuditSuppress Include="https://github.com/advisories/..." />` with the advisory URL from the warning. It suppresses that advisory everywhere in the project, for every package that shares it, so treat it as a recorded, reviewed exception. - **Reporting:** `dotnet package list --vulnerable --include-transitive` lists vulnerable packages on demand, and `--format json` makes it machine-readable for evidence; `--outdated` and `--deprecated` answer the neighbouring questions (newer versions, deprecated packages), and only one of the three can be used per run. Switching audit off with `NuGetAudit=false`, or dropping to `NuGetAuditMode=direct` on a .NET 10 project, hides the risk rather than removing it, and in a bank needs the same sign-off as any suppressed advisory.
- Why might the same solution show more audit warnings after retargeting from net8.0 to net10.0?NuGetAuditMode defaults to `all` only for projects targeting .NET 10 or later, so the retargeted projects start auditing transitive packages that were invisible under the `direct` default. The vulnerabilities were there before; the default now reports them.
- When would you set auditSources instead of relying on the package sources?When the package sources do not publish vulnerability data — typically a single internal feed — or when nuget.org is deliberately not a package source. Pointing `<auditSources>` at nuget.org's data endpoint keeps the audit complete without allowing package downloads from it.
- NuGetAudit only runs when you call dotnet package list --vulnerable.
- In .NET 10, every project audits transitive packages whatever its target framework.
- NuGetAuditLevel defaults to high, so low-severity advisories are hidden.
- NU1903 and NU1904 fail the build by default without any configuration.
- NuGetAuditSuppress silences an advisory for one package version only.
Assumes NuGet 7 in the .NET 10 SDK: NuGetAuditMode now defaults to all only for projects targeting net10.0 or later (direct otherwise), and NuGet 7.0 added dotnet package update --vulnerable; NuGetAudit itself has run during restore since NuGet 6.8 and the .NET 8 SDK.