You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Similar to the other NuGet audit configuration properties, `NuGetAuditSuppress` items can be defined at the project or repository level.
94
-
95
-
`NuGetAuditSuppress` is available for PackageReference projects starting from [NuGet 6.11, Visual Studio 17.11, and the .NET 8.0.400 SDK](../release-notes/NuGet-6.11.md).
96
-
It is available for packages.config from [Visual Studio 17.12 and NuGet 6.12](../release-notes/NuGet-6.12.md).
80
+
|[NuGet 7.0 and Visual Studio 2026](../release-notes/NuGet-7.0.md)| NuGet AuditSources support in the Visual Studio Package Manager UI |
97
81
98
82
### Warning codes
99
83
@@ -113,90 +97,49 @@ Alternatively, if you want to keep low and moderate vulnerabilities as warnings,
113
97
> [!NOTE]
114
98
> MSBuild properties for message severity such as `NoWarn` and `TreatWarningsAsErrors` are not supported for packages.config projects.
115
99
116
-
## Running NuGet Audit in CI
117
-
118
-
### Separating Errors from Warnings with a Dedicated Auditing Pipeline
119
-
120
-
You can use MSBuild's conditional statements to configure a dedicated CI pipeline for running audits, without audit warnings being treated as errors in other pipelines or on local builds.
121
-
Depending on your CI system and team processes, you can have failed runs of the audit pipeline email the team, or you may have a dashboard where you can show a badge of the most recent run of the pipeline.
100
+
#### Excluding advisories
122
101
123
-
Like many things in programming, there are multiple ways to achieve the outcome.
124
-
One option is to treat NuGet Audit warnings as errors only in an audit pipeline.
102
+
You can exclude advisories by adding a new `NuGetAuditSuppress` MSBuild item for each advisory.
103
+
Define a `NuGetAuditSuppress` item with the `Include=` metadata set to the advisory URL you wish to suppress.
The property name `AuditPipeline` is only an example, and you can customize it as you wish, as long as the name is the same in both the MSBuild condition and the command line.
143
-
MSBuild also uses environment variables when reading a property that has not yet been defined, so an environment variable is an alternative to the command line parameter.
144
-
145
-
By using conditions to selectively cause NuGet Audit warnings to fail a restore, you can have a dedicated pipeline to check packages for known vulnerabilities, while preventing new security advisories from blocking your bug fixes at inconvenient times.
146
-
Keeping NuGet Audit warnings enabled for local builds allows developers to get a non-blocking notification about new security advisories and can encourage upgrading package versions to fix the vulnerabilities more quickly than waiting for someone to check the audit pipeline status.
147
-
148
-
### Ensure restore audited projects
149
-
150
-
NuGet in MSBuild 17.13 and .NET 9.0.200 added output properties `RestoreProjectCount`, `RestoreSkippedCount` and `RestoreProjectsAuditedCount` on the restore task.
151
-
This can be used to enforce that audit ran during a restore.
152
-
Note that these output properties are not available with [static graph restore](../reference/msbuild-targets.md#restoring-with-msbuild-static-graph-evaluation).
153
-
154
-
Since MSBuild is a scripting language, this can be achieved a number of different ways, but also has the same restrictions as MSBuild has.
155
-
One example is to create a file *Directory.Solution.targets* in the same directory as your solution file, whose contents has a target similar to the following.
156
-
Note that *Directory.Build.props* is commonly used, but is imported by projects.
157
-
However, NuGet's restore target and task runs at the solution level, so needs to be in MSBuild's solution extensibility file, not the project/build file.
Text=""Restore did not audit every project in the solution. Expected: $(RestoreProjectCount) Found: $(RestoreProjectsAuditedCount)"" />
167
-
</Target>
168
-
</Project>
169
-
```
111
+
Similar to the other NuGet audit configuration properties, `NuGetAuditSuppress` items can be defined at the project or repository level.
170
112
171
-
Depending on your use-case, you may wish to use condition `'$(RestoreProjectCount)' != '$([MSBuild::Add($(RestoreProjectsAuditedCount), $(RestoreSkippedCount))'` on the error message, to account for projects that restore skipped because they were already up to date.
172
-
Similarly, think about if you want this error to happen everywhere, or only in CI pipelines, and what environment variables are defined in your CI environment, and factor this into the target's condition.
173
-
Again, since MSBuild is a scripting language, you can use any of its capabilities to customize your repo however you want.
174
-
Viewing [MSBuild's metaproj](/visualstudio/msbuild/how-to-build-specific-targets-in-solutions-by-using-msbuild-exe#troubleshooting) and [binlogs](/visualstudio/msbuild/msbuild-command-line-reference#switches-for-loggers) are useful to develop and troubleshoot solution level targets.
113
+
`NuGetAuditSuppress` is available for PackageReference projects starting from [NuGet 6.11, Visual Studio 17.11, and the .NET 8.0.400 SDK](../release-notes/NuGet-6.11.md).
114
+
It is available for packages.config from [Visual Studio 17.12 and NuGet 6.12](../release-notes/NuGet-6.12.md).
175
115
176
-
## `dotnet list package --vulnerable`
116
+
##### When to exclude advisories
177
117
178
-
Once a project is successfully restored, [`dotnet list package`](/dotnet/core/tools/dotnet-list-package) has a `--vulnerable` argument to filter the packages based on which packages have known vulnerabilities.
179
-
Note that `--include-transitive` is not default, so should be included.
118
+
In scenarios where you have analyzed a specific advisory and have determined that it either does not apply to your scenario, or you are comfortable with the risks it imposes, you can choose to exclude specific advisories from the audit report.
119
+
Note that this would completely suppress the advisories, even for packages that share the advisory that may not be part of your project.
120
+
`NuGetAuditSuppress` should be considered a last resort for managing advisories.
180
121
181
122
## Actions when packages with known vulnerabilities are reported
182
123
183
124
Getting a warning about packages with known vulnerabilities is only part of the process.
184
125
Once discovered, action needs to be taken to remove the potential vulnerability from your solution.
185
126
186
-
The easiest case is when a package you reference directly has the known vulnerability.
187
-
In this situation, update the package version to one that fixes the vulnerability.
127
+
The easiest case is when a package you reference directly has the known vulnerability.
128
+
In this situation, update the package version to one that fixes the vulnerability.
188
129
189
130
Package vulnerabilities may be reported in both direct and transitive package references.
190
131
The action you take to resolve may be different because of that.
191
132
192
133
### Security vulnerabilities found with updates
193
134
194
-
If security vulnerabilities are found and updates are available for the package, you can either:
135
+
If security vulnerabilities are found and updates are available for the package, you can do one of the following:
195
136
196
137
- Edit the `.csproj` or other package version location (`Directory.Packages.props`) with a newer version containing a security fix.
197
138
- Use the NuGet package manager user interface in Visual Studio to update the individual package.
198
139
- Run the `dotnet package update --vulnerable` command to update all vulnerable packages in a project to the first version without known vulnerabilities.
199
140
- Run the `dotnet package update` or `dotnet package add` commands with the respective package ID to update to the latest version. Use [`dotnet add package` when using .NET 9 or earlier](/dotnet/core/whats-new/dotnet-10/sdk#more-consistent-command-order).
141
+
- Use the NuGet Model Context Protocol (MCP) server that has the ability to update packages in your project to versions that resolve known vulnerabilities.
142
+
See [Fixing package vulnerabilities](NuGet-MCP-Server.md#fixing-package-vulnerabilities) for more information.
200
143
201
144
#### Transitive Packages
202
145
@@ -254,10 +197,6 @@ If you mouse hover over a package in the package list, the tooltip will include
254
197
255
198

256
199
257
-
### Use Copilot to update packages
258
-
NuGet has released a Model Context Protocol (MCP) server that has the ability to update packages in your project to versions that resolve known vulnerabilities.
259
-
See [Fixing package vulnerabilities](NuGet-MCP-Server.md#fixing-package-vulnerabilities) for more information.
260
-
261
200
### Security vulnerabilities found with no updates
262
201
263
202
In the case that a known vulnerability exists in a package without a security fix, you can do the following.
@@ -290,7 +229,67 @@ On NuGet.org, you can navigate to the package details page and click `Report pac
290
229
If no security vulnerabilities are found, this means that packages with known vulnerabilities were not found in your package graph at the present moment of time you checked.
291
230
Since the advisory database can be updated at any time, we recommend regularly checking your `dotnet restore` output and ensuring the same in your continuous integration process.
292
231
293
-
## Summary
232
+
## Running NuGet Audit in CI
233
+
234
+
### Separating Errors from Warnings with a Dedicated Auditing Pipeline
235
+
236
+
You can use MSBuild's conditional statements to configure a dedicated CI pipeline for running audits, without audit warnings being treated as errors in other pipelines or on local builds.
237
+
Depending on your CI system and team processes, you can have failed runs of the audit pipeline email the team, or you may have a dashboard where you can show a badge of the most recent run of the pipeline.
238
+
239
+
Like many things in programming, there are multiple ways to achieve the outcome.
240
+
One option is to treat NuGet Audit warnings as errors only in an audit pipeline.
Then in your pipeline, you run restore specifying the property used by the condition.
251
+
For example, using GitHub Actions syntax:
294
252
295
-
Security auditing features are crucial for maintaining the security and integrity of software projects.
296
-
These features provide you with an additional layer of protection against security vulnerabilities and ensures that you can use open source packages with confidence.
253
+
```yml
254
+
- name: Restore with NuGet Auditing
255
+
run: dotnet restore -p:AuditPipeline=true
256
+
```
257
+
258
+
The property name `AuditPipeline` is only an example, and you can customize it as you wish, as long as the name is the same in both the MSBuild condition and the command line.
259
+
MSBuild also uses environment variables when reading a property that has not yet been defined, so an environment variable is an alternative to the command line parameter.
260
+
261
+
By using conditions to selectively cause NuGet Audit warnings to fail a restore, you can have a dedicated pipeline to check packages for known vulnerabilities, while preventing new security advisories from blocking your bug fixes at inconvenient times.
262
+
Keeping NuGet Audit warnings enabled for local builds allows developers to get a non-blocking notification about new security advisories and can encourage upgrading package versions to fix the vulnerabilities more quickly than waiting for someone to check the audit pipeline status.
263
+
264
+
### Ensure restore audited projects
265
+
266
+
NuGet in MSBuild 17.13 and .NET 9.0.200 added output properties `RestoreProjectCount`, `RestoreSkippedCount` and `RestoreProjectsAuditedCount` on the restore task.
267
+
This can be used to enforce that audit ran during a restore.
268
+
Note that these output properties are not available with [static graph restore](../reference/msbuild-targets.md#restoring-with-msbuild-static-graph-evaluation).
269
+
270
+
Since MSBuild is a scripting language, this can be achieved a number of different ways, but also has the same restrictions as MSBuild has.
271
+
One example is to create a file *Directory.Solution.targets* in the same directory as your solution file, whose contents has a target similar to the following.
272
+
Note that *Directory.Build.props* is commonly used, but is imported by projects.
273
+
However, NuGet's restore target and task runs at the solution level, so needs to be in MSBuild's solution extensibility file, not the project/build file.
Text=""Restore did not audit every project in the solution. Expected: $(RestoreProjectCount) Found: $(RestoreProjectsAuditedCount)"" />
283
+
</Target>
284
+
</Project>
285
+
```
286
+
287
+
Depending on your use-case, you may wish to use condition `'$(RestoreProjectCount)' != '$([MSBuild::Add($(RestoreProjectsAuditedCount), $(RestoreSkippedCount))'` on the error message, to account for projects that restore skipped because they were already up to date.
288
+
Similarly, think about if you want this error to happen everywhere, or only in CI pipelines, and what environment variables are defined in your CI environment, and factor this into the target's condition.
289
+
Again, since MSBuild is a scripting language, you can use any of its capabilities to customize your repo however you want.
290
+
Viewing [MSBuild's metaproj](/visualstudio/msbuild/how-to-build-specific-targets-in-solutions-by-using-msbuild-exe#troubleshooting) and [binlogs](/visualstudio/msbuild/msbuild-command-line-reference#switches-for-loggers) are useful to develop and troubleshoot solution level targets.
291
+
292
+
## `dotnet list package --vulnerable`
293
+
294
+
[`dotnet list package`](/dotnet/core/tools/dotnet-list-package) has a `--vulnerable` argument to filter the packages based on which packages have known vulnerabilities.
295
+
Note that `--include-transitive` is not default, so should be included.
0 commit comments