|
1 |
| ---- |
2 |
| -title: "Breaking change: 'dotnet restore' audits transitive packages" |
3 |
| -description: Learn about a breaking change in the .NET 9 SDK where 'dotnet restore' also produces security vulnerability warnings for transitive packages by default. |
4 |
| -ms.date: 11/14/2024 |
5 |
| ---- |
6 |
| -# 'dotnet restore' audits transitive packages |
7 |
| - |
8 |
| -The [`dotnet restore` command](../../../tools/dotnet-restore.md), which restores the dependencies and tools of a project, now produces security vulnerability warnings for transitive packages by default. |
9 |
| - |
10 |
| -## Previous behavior |
11 |
| - |
12 |
| -In .NET 8, [NuGetAudit](../8.0/dotnet-restore-audit.md) was introduced to emit warnings for packages with known security vulnerabilities. By default, only direct package references were audited, however, it was possible to change the `NuGetAuditMode` property to include all packages. |
13 |
| - |
14 |
| -## New behavior |
15 |
| - |
16 |
| -Starting in .NET 9, `NuGetAuditMode` defaults to `all` if it hasn't been explicitly set. This setting means that *transitive packages* (dependencies of packages your project directly references) with known vulnerabilities now cause warnings to be reported. |
17 |
| -If your project treats warnings as errors, this behavior can cause restore failures. |
18 |
| - |
19 |
| -## Version introduced |
20 |
| - |
21 |
| -.NET 9 Preview 6 |
22 |
| - |
23 |
| -## Type of breaking change |
24 |
| - |
25 |
| -This change is a [behavioral change](../../categories.md#behavioral-change). |
26 |
| - |
27 |
| -## Reason for change |
28 |
| - |
29 |
| -Packages with known vulnerabilities might cause your app to be exploitable, even if your project does not directly reference or use the vulnerable package. |
30 |
| -New features in .NET 9 also make it easier to investigate the package graph and to suppress advisories that aren't relevant to how your app uses the vulnerable package. |
31 |
| - |
32 |
| -## Recommended action |
33 |
| - |
34 |
| -- To explicitly reduce the probability of this change breaking your build due to warnings, you can consider your usage of `<TreatWarningsAsErrors>` and use `<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>` to ensure known security vulnerabilities are still allowed in your environment. |
35 |
| - |
36 |
| -- Use tools such as `dotnet nuget why` to find the top-level package that caused the transitive package with the known vulnerability to be included, and try to upgrade it to see if the transitive vulnerability goes away. If not, promote the transitive package to a top-level package by adding a `PackageReference` for it, and upgrade it to a newer version. |
37 |
| - |
38 |
| -- If you want to suppress a specific advisory, you can add `<NuGetAuditSuppress Include="url" />` item to your project file, where `url` is the URL reported in NuGet's warning message. |
39 |
| - |
40 |
| - ```xml |
41 |
| - <ItemGroup> |
42 |
| - <NuGetAuditSuppress Include="url" /> |
43 |
| - </ItemGroup> |
44 |
| - ``` |
45 |
| - |
46 |
| -- If you want to only be warned of direct package references with known vulnerabilities, you can set `<NuGetAuditMode>` to `direct` in your project file. |
47 |
| - |
48 |
| - ```xml |
49 |
| - <PropertyGroup> |
50 |
| - <NuGetAuditMode>direct</NuGetAuditMode> |
51 |
| - </PropertyGroup> |
52 |
| - ``` |
53 |
| - |
54 |
| -## See also |
55 |
| - |
56 |
| -- [Audit for security vulnerabilities (`dotnet restore`)](../../../tools/dotnet-restore.md#audit-for-security-vulnerabilities) |
57 |
| -- [Auditing package dependencies for security vulnerabilities](/nuget/concepts/auditing-packages) |
58 |
| -- [NuGetAudit 2.0: Elevating Security and Trust in Package Management](https://devblogs.microsoft.com/nuget/nugetaudit-2-0-elevating-security-and-trust-in-package-management/) |
| 1 | +--- |
| 2 | +title: "Breaking change: 'dotnet restore' audits transitive packages" |
| 3 | +description: Learn about a breaking change in the .NET 10 SDK where 'dotnet restore' also produces security vulnerability warnings for transitive packages by default. |
| 4 | +ms.date: 03/28/2025 |
| 5 | +--- |
| 6 | +# 'dotnet restore' audits transitive packages |
| 7 | + |
| 8 | +The [`dotnet restore` command](../../../tools/dotnet-restore.md), which restores the dependencies of a project, now produces security vulnerability warnings for transitive packages by default when the project targets .NET 10 or a later version. |
| 9 | + |
| 10 | +## Previous behavior |
| 11 | + |
| 12 | +[NuGetAudit](../8.0/dotnet-restore-audit.md) was introduced in .NET 8 to emit warnings for packages with known security vulnerabilities. |
| 13 | +By default, only direct package references were audited, however, it was possible to change the `NuGetAuditMode` property to include all packages. |
| 14 | + |
| 15 | +In .NET 9 preview 6, NuGetAuditMode's default was changed to `all` for all projects, and this change was reverted back to `direct` in the .NET 9.0.101 SDK. |
| 16 | + |
| 17 | +## New behavior |
| 18 | + |
| 19 | +When projects target .NET 10 or higher, then `NuGetAuditMode` defaults to `all` if it hasn't been explicitly set. |
| 20 | +This setting means that *transitive packages* (dependencies of packages your project directly references) with known vulnerabilities now cause warnings to be reported. |
| 21 | +If your project treats warnings as errors, this behavior can cause restore failures. |
| 22 | + |
| 23 | +If your project targets .NET 9 or lower, the default for `NuGetAuditMode` remains `direct`. |
| 24 | + |
| 25 | +## Version introduced |
| 26 | + |
| 27 | +.NET 10 Preview 3 |
| 28 | + |
| 29 | +## Type of breaking change |
| 30 | + |
| 31 | +This change is a [behavioral change](../../categories.md#behavioral-change). |
| 32 | + |
| 33 | +## Reason for change |
| 34 | + |
| 35 | +Packages with known vulnerabilities might cause your app to be exploitable, even if your project does not directly reference or directly use the vulnerable package. |
| 36 | + |
| 37 | +## Recommended action |
| 38 | + |
| 39 | +- To prevent audit warnings being treated as errors, even when using `<TreatWarningsAsErrors>`, you can use `<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904;$(WarningsNotAsErrors)</WarningsNotAsErrors>`. |
| 40 | + |
| 41 | +- Use tools such as `dotnet nuget why` to find the top-level package that caused the transitive package with the known vulnerability to be included, and try to upgrade it to see if the transitive vulnerability goes away. If not, promote the transitive package to a top-level package by adding a `PackageReference` for it, and upgrade it to a newer version. |
| 42 | + |
| 43 | +- If you want to suppress a specific advisory, you can add `<NuGetAuditSuppress Include="url" />` item to your project file, where `url` is the URL reported in NuGet's warning message. |
| 44 | + |
| 45 | + ```xml |
| 46 | + <ItemGroup> |
| 47 | + <NuGetAuditSuppress Include="url" /> |
| 48 | + </ItemGroup> |
| 49 | + ``` |
| 50 | + |
| 51 | +- If you want to only be warned of direct package references with known vulnerabilities, you can set `<NuGetAuditMode>` to `direct` in your project file. |
| 52 | + |
| 53 | + ```xml |
| 54 | + <PropertyGroup> |
| 55 | + <NuGetAuditMode>direct</NuGetAuditMode> |
| 56 | + </PropertyGroup> |
| 57 | + ``` |
| 58 | + |
| 59 | +## See also |
| 60 | + |
| 61 | +- [Audit for security vulnerabilities (`dotnet restore`)](../../../tools/dotnet-restore.md#audit-for-security-vulnerabilities) |
| 62 | +- [Auditing package dependencies for security vulnerabilities](/nuget/concepts/auditing-packages) |
| 63 | +- [NuGetAudit 2.0: Elevating Security and Trust in Package Management](https://devblogs.microsoft.com/nuget/nugetaudit-2-0-elevating-security-and-trust-in-package-management/) |
0 commit comments