Skip to content

Commit 808a942

Browse files
authored
Update NuGet Audit page (#3177)
1 parent 52a1f60 commit 808a942

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

docs/concepts/Auditing-Packages.md

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,37 @@ title: Auditing package dependencies for security vulnerabilities
33
description: How to audit package dependencies for security vulnerabilities and acting on security audit reports.
44
author: JonDouglas
55
ms.author: jodou
6-
ms.date: 05/04/2023
6+
ms.date: 10/11/2023
77
ms.topic: conceptual
88
---
99

1010
# Auditing package dependencies for security vulnerabilities
1111

1212
## About security audits
1313

14-
A security audit for package managers like NuGet is a process that involves analyzing the security of the packages that are included in a software project. This involves identifying vulnerabilities, evaluating risks, and making recommendations for improving security. The audit can include a review of the packages themselves, as well as any dependencies and their associated risks. 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.
14+
A security audit for package managers like NuGet is a process that involves analyzing the security of the packages that are included in a software project.
15+
This involves identifying vulnerabilities, evaluating risks, and making recommendations for improving security.
16+
The audit can include a review of the packages themselves, as well as any dependencies and their associated risks.
17+
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.
1518

16-
> [!IMPORTANT]
17-
> Security auditing at restore time is available in .NET 8 Preview 4+ and Visual Studio 17.8 Preview 1+.
19+
NuGet Audit is available starting from NuGet 6.8, the .NET 8 SDK (8.0.100), and Visual Studio 2022 17.8.
1820

1921
## Running a security audit with `restore`
2022

21-
The `restore` command automatically runs when you do a common package operation such as loading a project for the first time, adding a new package, updating a package version, or removing a package from your project in your favorite IDE. A description of your dependencies is checked against a report of known vulnerabilities on the [GitHub Advisory Database](https://github.com/advisories?query=type%3Areviewed+ecosystem%3Anuget).
23+
The `restore` command automatically runs when you do a common package operation such as loading a project for the first time, adding a new package, updating a package version, or removing a package from your project in your favorite IDE.
24+
A description of your dependencies is checked against a report of known vulnerabilities on the [GitHub Advisory Database](https://github.com/advisories?query=type%3Areviewed+ecosystem%3Anuget).
2225

2326
> [!IMPORTANT]
2427
> For Audit to check packages, a package source that provides a vulnerability database must be used.
2528
> NuGet.org's V3 URL is one such example (https://api.nuget.org/v3/index.json), but note that NuGet.org's V2 endpoint does not.
2629
27-
> [!NOTE]
28-
> .NET 8 preview 6+ enables Audit by default, but Visual Studio does not ship .NET 8 yet.
29-
> To opt-in to Audit explicitly, set `<NuGetAudit>true</NuGetAudit>` in your project file, or a *Directory.Build.props* file.
30-
3130
1. On the command line, navigate to your project or solution directory.
32-
2. Ensure your project or solution contains a `.csproj` file.
33-
3. Type `dotnet restore` or `restore` using your preferred tooling (i.e. MSBuild, NuGet.exe, etc).
34-
4. Review the audit report and address the known security vulnerabilities.
31+
1. Ensure your project or solution contains a `.csproj` file.
32+
1. Type `dotnet restore` or `restore` using your preferred tooling (i.e. MSBuild, NuGet.exe, etc).
33+
1. Review the audit report and address the known security vulnerabilities.
34+
35+
> [!NOTE]
36+
> At this time, NuGet does not audit `packages.config` projects.
3537
3638
## Reviewing and acting on the security audit report
3739

@@ -56,7 +58,8 @@ In the case that a known vulnerability exists in a package without a security fi
5658

5759
#### Check for mitigating factors
5860

59-
Review the security advisor for any mitigating factors that may allow you to continue using the package with the vulnerability. The vulnerability may only exist when the code is used on a specific framework, operating system, or a special function is called.
61+
Review the security advisor for any mitigating factors that may allow you to continue using the package with the vulnerability.
62+
The vulnerability may only exist when the code is used on a specific framework, operating system, or a special function is called.
6063

6164
#### Use a suggested package
6265

@@ -68,33 +71,43 @@ If a fix does not exist for the security advisory, you may want to suggest chang
6871

6972
#### Open an issue
7073

71-
If you do not want to fix the vulnerability or are unable to update or replace the package, open an issue in the package's issue tracker or preferred contact method. On NuGet.org, you can navigate to the package details page and click `Report package` which will guide you to get in contact with the author.
74+
If you do not want to fix the vulnerability or are unable to update or replace the package, open an issue in the package's issue tracker or preferred contact method.
75+
On NuGet.org, you can navigate to the package details page and click `Report package` which will guide you to get in contact with the author.
7276

7377
### No security vulnerabilities found
7478

75-
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. 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.
79+
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.
80+
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.
7681

7782
### Setting a security audit mode
7883

7984
By default, a security audit is done for top-level dependencies.
8085
In the case that you'd like to audit both top-level and transitive dependencies, you can set the `<NuGetAuditMode>` MSBuild property to the desired mode in which auditing will run.
81-
Possible values are `direct` and `all`. For example if you wanted to audit all dependencies for security advisories, you can set the following:
86+
Possible values are `direct` and `all`.
87+
For example if you wanted to audit all dependencies for security advisories, you can set the following:
8288

8389
```xml
8490
<NuGetAuditMode>all</NuGetAuditMode>
8591
```
8692

93+
> [!NOTE]
94+
> Visual Studio 2022 17.8 does not support changing audit mode for SDK style packages.
95+
> It works from 17.9 Preview 2.
96+
8797
### Setting a security audit level
8898

89-
In cases where you only care about a certain threshold of a security advisory severity, you can set the `<NuGetAuditLevel>` MSBuild property to the desired level in which auditing will fail. Possible values are `low`, `moderate`, `high`, and `critical`. For example if you only want to see `moderate`, `high`, and `critical` advisories, you can set the following:
99+
In cases where you only care about a certain threshold of a security advisory severity, you can set the `<NuGetAuditLevel>` MSBuild property to the desired level in which auditing will fail.
100+
Possible values are `low`, `moderate`, `high`, and `critical`.
101+
For example if you only want to see `moderate`, `high`, and `critical` advisories, you can set the following:
90102

91103
```xml
92104
<NuGetAuditLevel>moderate</NuGetAuditLevel>
93105
```
94106

95107
### Excluding advisories
96108

97-
There is no support for excluding individual advisories at this time. You can use `<NoWarn>` to suppress `NU1901`-`NU1904` warnings or use the `<NuGetAuditLevel>` functionality to ensure your audit reports are useful to your workflow.
109+
There is no support for excluding individual advisories at this time.
110+
You can use `<NoWarn>` to suppress `NU1901`-`NU1904` warnings or use the `<NuGetAuditLevel>` functionality to ensure your audit reports are useful to your workflow.
98111

99112
### Warning codes
100113

@@ -105,11 +118,10 @@ There is no support for excluding individual advisories at this time. You can us
105118
| NU1902 | Package with moderate severity detected |
106119
| NU1903 | Package with high severity detected |
107120
| NU1904 | Package with critical severity detected |
108-
| NU1905 | NuGetAudit is explicitly enabled, but no package sources are providing vulnerability data |
109121

110122
You can customize your build to treat these warnings as errors to [treat warnings as errors, or treat warnings not as errors](/dotnet/csharp/language-reference/compiler-options/errors-warnings#warningsaserrors-and-warningsnotaserrors).
111123
For example, if you're already using `<TreatWarningsAsErrors>` to treat all (C#, NuGet, MSBuild, etc) warnings as errors, you can use `<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>` to prevent vulnerabilities discovered in the future from breaking your build.
112-
Alternatively, if you want to keep low and moderate vulnerabilities as warnings, but treat missing vulnerability data and high and critical vulnerabilities as errors, and you're not using `TreatWarningsAsErrors`, you can use `<WarningsAsErrors>NU1903;NU1904;NU1905</WarningsAsErrors>`.
124+
Alternatively, if you want to keep low and moderate vulnerabilities as warnings, but treat high and critical vulnerabilities as errors, and you're not using `TreatWarningsAsErrors`, you can use `<WarningsAsErrors>NU1903;NU1904</WarningsAsErrors>`.
113125

114126
### Disabling security auditing
115127

@@ -121,4 +133,5 @@ At any time you wish to not receive security audit reports, you can opt-out of t
121133

122134
## Summary
123135

124-
Security auditing features are crucial for maintaining the security and integrity of software projects. These features provide you with an additional layer of protection against security vulnerabilities and ensures that you can use open source packages with confidence.
136+
Security auditing features are crucial for maintaining the security and integrity of software projects.
137+
These features provide you with an additional layer of protection against security vulnerabilities and ensures that you can use open source packages with confidence.

0 commit comments

Comments
 (0)