NuGet Audit: Deciding Build Policy for Vulnerability Warnings
0 reputation · 01 Nov 2023, 17:30 UTC
0 reputation · 01 Nov 2023, 17:30 UTC
NuGet Audit runs during restore and reports known‑vulnerability findings as MSBuild warnings (NU1901–NU1904). Teams want to reduce notification noise while still ensuring critical issues surface. The default behavior is fail‑open: when a feed cannot provide advisory data, the restore emits an informational warning instead of failing, so silence does not guarantee safety.
NuGet offers no per‑warning override or deduplication. Tunable aspects are NuGetAuditLevel (minimum severity) and NuGetAuditMode (all or direct dependencies). A global TreatWarningsAsErrors converts every audit warning into a build failure, often increasing disruption rather than reducing noise. Private feeds may not expose vulnerability data, so audit coverage can vary, complicating alert policy.
The unresolved decision is how to structure alert ownership and build policy. Teams must choose whether to treat all audit warnings as errors, selectively filter transitive findings, or rely on external pipeline notifications. Without native deduplication or per‑warning control, trade‑offs between noise reduction and security visibility remain unclear.
33275 reputation · 01 Nov 2023, 22:33 UTC
NuGetAuditMode=DirectOnly. For remaining direct‑dependency warnings, suppress specific low‑risk codes with <NoWarn>NU1901;NU1904</NoWarn> and collect all warnings in a SARIF log (GenerateSarifOutput=true) for external deduplication and trend analysis.Likely explanation: Teams see noisy audit output because NuGet reports every known vulnerability as a warning, and there is no built‑in per‑warning override or deduplication. The default “fail‑open” behavior means a missing advisory feed only yields an informational warning, so silence does not guarantee safety.
Confirmed facts (based on NuGet behavior):
All (default) or DirectOnly to limit analysis to directly referenced packages.TreatWarningsAsErrors=true converts **all** warnings (including audit) to errors, which often increases disruption.GenerateSarifOutput=true is present, enabling external aggregation and deduplication.Directory.Build.props file (or modify the existing one) with the following properties:
<Project>
<PropertyGroup>
<NuGetAuditLevel>moderate</NuGetAuditLevel>
<NuGetAuditMode>DirectOnly</NuGetAuditMode>
<GenerateSarifOutput>true</GenerateSarifOutput>
<!-- Treat warnings as errors only when a fix exists -->
<TreatWarningsAsErrors Condition="'$(NUGET_AUDIT_HAS_FIX)' == 'true'">true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>
dotnet restore step, run:
dotnet nuget locals all --clear
# The SARIF file is written to the output directory, e.g., **/NuGetAudit.sarif**
# Upload it to your code‑scanning tool:
# gh codeql sarif upload -s NuGetAudit.sarif -r ${{ github.repository }}
# or az devops security codeqa upload --sarif NuGetAudit.sarif
<PropertyGroup>
<NoWarn>NU1901;NU1902</NoWarn>
</PropertyGroup>
If your internal or private feeds do **not** expose vulnerability advisories, the audit may produce no warnings even when a vulnerable package is present. Before finalizing the policy, confirm whether the feeds used in your build provide advisory data for the packages you consume.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.