Skip to content

Commit 920c2a2

Browse files
authored
Add updating vulnerable packages guidance to the docs (#3493)
1 parent 373837d commit 920c2a2

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

docs/concepts/Auditing-Packages.md

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ This involves identifying vulnerabilities, evaluating risks, and making recommen
1616
The audit can include a review of the packages themselves, as well as any dependencies and their associated risks.
1717
The goal of the audit is to identify and mitigate any security vulnerabilities that could be exploited by attackers, such as code injection or cross-site scripting attacks.
1818

19-
We also have a [blog post](https://devblogs.microsoft.com/nuget/nugetaudit-2-0-elevating-security-and-trust-in-package-management/) which discusses our recommended method for taking action when a package with a known vulnerability is found to be used by your project, and tools to help get more information.
20-
2119
### Feature availability
2220

2321
| NuGet | .NET SDK | Visual Studio | Feature |
@@ -182,7 +180,14 @@ Note that `--include-transitive` is not default, so should be included.
182180

183181
## Actions when packages with known vulnerabilities are reported
184182

185-
We also have a [blog post](https://devblogs.microsoft.com/nuget/nugetaudit-2-0-elevating-security-and-trust-in-package-management/) which discusses our recommended method for taking action when a package with a known vulnerability is found to be used by your project, and tools to help get more information.
183+
Getting a warning about packages with known vulnerabilities is only part of the process.
184+
Once discovered, action needs to be taken to remove the potential vulnerability from your solution.
185+
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.
188+
189+
Package vulnerabilities may be reported in both direct and transitive package references.
190+
The action you take to resolve may be different because of that.
186191

187192
### Security vulnerabilities found with updates
188193

@@ -195,13 +200,60 @@ If security vulnerabilities are found and updates are available for the package,
195200

196201
#### Transitive Packages
197202

198-
If a known vulnerability exists in a top-level package's transitive dependencies, you have these options:
203+
Often a vulnerability will be in a transitive dependency.
204+
Our recommendation is to prefer updates to packages “closest” to your direct references.
205+
Though, there's nothing wrong with just upgrading the package with known vulnerability either.
206+
207+
For example, say your project references package A.
208+
Package A has a dependency on package B, which in turn has a dependency on package C.
209+
In this example, we'll consider that package C version 1.0.0 has a known vulnerability, fixed in version 2.0.0.
210+
Our recommendation is to first try upgrading package A.
211+
If that doesn't resolve the audit warning, then try upgrading package B.
212+
If that doesn't resolve the audit warning, then upgrade C directly.
213+
To aid with this, you'll [need to find the transitive package path](#finding-the-transitive-package-path).
214+
215+
In summary, if a known vulnerability exists in a top-level package's transitive dependencies, you have these options:
199216

217+
- Check if the top-level package contains an update that does not have a transitive vulnerability and update that instead.
218+
- Update the closest package to your direct references that does not reference a vulnerability.
200219
- Add the fixed package version as a direct package reference. **Note:** Be sure to remove this reference when a new package version update becomes available and be sure to maintain the defined attributes for the expected behavior.
201220
- Use [Central Package Management with the transitive pinning functionality](../consume-packages/Central-Package-Management.md#transitive-pinning).
221+
Note that if you pack your project into your own package to share with others, [CPM with transitive pinning will cause packages to become dependencies](../consume-packages/Central-Package-Management.md#transitive-pinning-and-pack), even if your project doesn't directly call APIs on that package.
202222
- [Suppress the advisory](#excluding-advisories) until it can be addressed.
203223
- File an issue in the top-level package's tracker to request an update.
204224

225+
##### Finding the transitive package path
226+
227+
There are several ways to find the package path.
228+
Which method you prefer depends on what tools you normally use during your development.
229+
230+
###### dotnet nuget why
231+
232+
On the command line, you can use the [`dotnet nuget why` command](/dotnet/core/tools/dotnet-nuget-why) to understand why transitive packages are being included in your project's package graph.
233+
234+
![dotnet nuget why example](media/dotnet-nuget-why-1.png)
235+
236+
###### Visual Studio Solution Explorer
237+
238+
SDK style projects also provide the full package graph under the project's Dependency node.
239+
It's also searchable!
240+
Expand search options and enable “search external files”.
241+
242+
![Visual Studio Solution Explorer Search Options](media/vs-solution-explorer-search-options-1.png)
243+
244+
Search the package name, and it will show you all instances under each project's Dependencies node.
245+
246+
![Visual Studio Solution Explorer Search Results](media/vs-solution-explorer-search-results-1.png)
247+
248+
###### Visual Studio NuGet Package Manager UI
249+
250+
When you look at the Installed tab in Visual Studio's package manager UI, when the project uses PackageReference for package management, it will show both direct and transitive packages.
251+
Currently, this only happens when you manage packages for a project, not for the solution.
252+
253+
If you mouse hover over a package in the package list, the tooltip will include the name of one direct package that has caused that transitive package to be included in the project.
254+
255+
![Visual Studio Package Manager UI tooltip](media/pm-ui-transitive-tooltip-1.png)
256+
205257
### Use Copilot to update packages
206258
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.
207259
See [Fixing package vulnerabilities](NuGet-MCP-Server.md#fixing-package-vulnerabilities) for more information.
38.1 KB
Loading
19.7 KB
Loading
7.33 KB
Loading
24.6 KB
Loading

docs/reference/errors-and-warnings/NU1901-NU1904.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ For more information, see [the documentation on auditing packages](../../concept
3333

3434
### Solution
3535

36-
We have [a blog post](https://devblogs.microsoft.com/nuget/nugetaudit-2-0-elevating-security-and-trust-in-package-management/) with more discussion about our recommended actions when your project uses a package with a known vulnerability, and tools that can help.
36+
We have [documentation on upgrading vulnerable packages](../../concepts/Auditing-Packages.md#actions-when-packages-with-known-vulnerabilities-are-reported) that goes in more detail about our recommended actions when your project uses a package with a known vulnerability, and tools that can help.
3737

3838
Upgrading to a newer version of the package is likely to resolve the warning.
3939
If your project does not reference the package directly (it's a transitive package), [`dotnet nuget why`](/dotnet/core/tools/dotnet-nuget-why) can be used to understand which package caused it to be included in your project.

0 commit comments

Comments
 (0)