-
Notifications
You must be signed in to change notification settings - Fork 694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable advisory suppressions in CLI restore for PackageReference projects #5679
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
Since you're new to the client team, you're not aware of our performance requirements, especially on restore, so there's a bunch of unnecessary memory allocations that should be removed.
src/NuGet.Core/NuGet.Build.Tasks/GetRestoreNuGetAuditSuppressionsTask.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Build.Tasks/GetRestoreNuGetAuditSuppressionsTask.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.Build.Tasks.Test/GetRestoreNuGetAuditSuppressionsTaskTests.cs
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests/RestoreCommandTests.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests/Utility/AuditUtilityTests.cs
Outdated
Show resolved
Hide resolved
@@ -947,7 +947,6 @@ override NuGet.Commands.WarningPropertiesCollection.GetHashCode() -> int | |||
~static NuGet.Commands.MSBuildRestoreUtility.GetDependencySpec(System.Collections.Generic.IEnumerable<NuGet.Commands.IMSBuildItem> items) -> NuGet.ProjectModel.DependencyGraphSpec | |||
~static NuGet.Commands.MSBuildRestoreUtility.GetMessageForUnsupportedProject(string path) -> NuGet.Common.RestoreLogMessage | |||
~static NuGet.Commands.MSBuildRestoreUtility.GetPackageSpec(System.Collections.Generic.IEnumerable<NuGet.Commands.IMSBuildItem> items) -> NuGet.ProjectModel.PackageSpec | |||
~static NuGet.Commands.MSBuildRestoreUtility.GetRestoreAuditProperties(NuGet.Commands.IMSBuildItem specItem) -> NuGet.ProjectModel.RestoreAuditProperties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This an API breaking change.
Sounds like no one is concerned about it, since this is arguably something that ideally wasn't public, but has to be, so I think it's ok to make the breaking change.
However, we should make sure we disclose the API breaking change in our release notes.
You can do that by creating a specific issue with a label Category:BreakingChange
that talks about the breaking change and is fixed by this PR (alongside the other one).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From memory, it's a public API so that both static graph restore, as well as "normal" CLI restore, can share the same code. But the method name, the method parameter type and return type are so specific, I just don't see it being useful to anyone else.
I wish we had some way to mark an API as "public because NuGet needs it internally, but we're going to make no effort to avoid breaking changes". InternalsVisibleTo
feels like a bad solution. But yes, I noticed this when reviewing the PR, but because of the above justification, I just don't see it impacting anyone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I've created an issue here: NuGet/Home#13313, and referenced it in this PR as you mentioned. Let me know if I need to change anything else here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me!
Just one thing where my gut reaction makes me feel it's a correctness issue, although testing a bunch of popular websites, and all the CVE websites I can find, they're all case insensitive, so maybe my suggestion doesn't actually matter.
src/NuGet.Core/NuGet.Build.Tasks/GetRestoreNuGetAuditSuppressionsTask.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/AuditUtility.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/MSBuildRestoreUtility.cs
Outdated
Show resolved
Hide resolved
Removing the label since the target branch is the feature branch anyways |
5d11db8
to
5129e67
Compare
Bug
Fixes: https://github.com/NuGet/Client.Engineering/issues/2720
Fixes: NuGet/Home#13313
Regression? Last working version:
Description
Design spec: https://github.com/NuGet/Home/blob/dev/accepted/2023/NuGetAudit-supress-advisory.md
We're adding a new MSBuild item called
NuGetAuditSuppress
that allows users to suppress individual advisories during restore. These items will have the advisory URL in theInclude=
field, looking something like this:<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-5crp-9r3c-p9vr" />
.This PR implements suppressions for CLI restore paths (dotnet/MSBuild restore, NuGet.exe restore, Static graph restore) for PackageReference projects. The packages.config implementation, as well as the VS restore implementation for PackageReference projects, will follow later.
These are the main pieces:
CollectNuGetAuditSuppressions
(src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets
)_CollectRestoreInputs
, which will run all the individual 'Collect' item targets. This is meant to reduce duplication in our code. Going forward, instead of adding new 'Collect' targets to lists in multiple places, we will be able to add it to theDependsOnTargets=
attribute in_CollectRestoreInputs
, and use this target everywhere. (See _CollectRestoreInputs target)GetRestoreNuGetAuditSuppressionsTask
parses the 'NuGetAuditSuppress' items into the_RestoreGraphEntry
items that we ultimately read in restore.src/NuGet.Core/NuGet.ProjectModel/
holds all the changes related to reading and writing the dgspec.HashSet<string> SuppressedAdvisories
member was addedsrc/NuGet.Core/NuGet.ProjectModel/RestoreAuditProperties.cs
to store the suppression inputs.src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/AuditUtility.cs
file.PR Checklist
PR has a meaningful title
PR has a linked issue.
Described changes
Tests
Documentation
NuGetAuditSuppress
Home#13493