Skip to content

Show vulnerability indicators for transitive vulnerable packages#5384

Merged
jebriede merged 3 commits intodevfrom
dev-jebriede-TransitiveVulnerabilities
Aug 30, 2023
Merged

Show vulnerability indicators for transitive vulnerable packages#5384
jebriede merged 3 commits intodevfrom
dev-jebriede-TransitiveVulnerabilities

Conversation

@jebriede
Copy link
Contributor

@jebriede jebriede commented Aug 28, 2023

Bug

Fixes: NuGet/Home#8756

Regression? Last working version: N/A

Description

Fetch vulnerabilities database for all enabled sources from VulnerabilityInfoResource and check if transitive packages are vulnerable to show warning indicator by Installed tab and by transitive package in package list.

Updated the install / uninstall / update action code paths that log telemetry to include a count of transitive vulnerable packages and maximum severity of each package.

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
      Updated existing test for telemetry although the test does not fully cover the scenario so we should consider adding additional tests in the future. Code copied from AuditUtility does not have tests as we are going to refactor the code to be shareable and put it under test.

    • OR

    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@jebriede jebriede requested a review from a team as a code owner August 28, 2023 22:37
aortiz-msft
aortiz-msft previously approved these changes Aug 28, 2023
@nkolev92
Copy link
Member

Your fixes statement in your PR description is broken. You need a link in the Fixes: line.

nkolev92
nkolev92 previously approved these changes Aug 29, 2023
Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable.

I have suggestions, but nothing that can't be addressed in a future PR.


ISourceRepositoryProvider sourceRepositoryProvider = await ServiceLocator.GetComponentModelServiceAsync<ISourceRepositoryProvider>();
var sourceRepositories = sourceRepositoryProvider.GetRepositories();
_packageVulnerabilityService = new PackageVulnerabilityService(sourceRepositories, _uiLogger);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sources can change. You probably want to listen to settings changes and reload the sources.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made note of this for a follow-up. Thanks!

return null;
}

using (var sourceCacheContext = new SourceCacheContext())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Share the SourceCacheContext among source repositories.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The static extension methods operate on a single source repository. In order to share SourceCacheContext among various source repositories, we would need to supply the SourceCacheContext along with each of the method calls in the SourceRepositoryExtensions. The current precedent set by this static class and its methods is to create a new SourceCacheContext per each call, which is consistent with what we're doing here.

An alternative design would be to store a static reference to the SourceCacheContext but then we'd need methods on this static class that manages the lifecycle of the SourceCacheContext. Ideally, we would have a better way to manage a collection of source repositories and their operations and share the SourceCacheContext across multiple repos.

I'm making note of your suggestion as an improvement that should be made, but it's out of scope of this feature as this simply follows an existing pattern using an existing mechanism which can be improved upon, but was not introduced in this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current precedent set by this static class and its methods is to create a new SourceCacheContext per each call, which is consistent with what we're doing here.

I see. That's a poor pattern. See 9ea2def.
The caching context should be shared so that any caching decisions don't need to be changed in 10 different places.
I think we should change that, I've created an issue for that NuGet/Home#12859.

simply follows an existing pattern using an existing mechanism which can be improved upon, but was not introduced in this change.

I don't think we should be propagating bad patterns, even if it's a preexisting pattern. However, I think it's reasonable to say that all of those discussions should be handled on a case by case basis, as the cost/impact is different for each one individually.

My suggestion is to just pass down the source cache context, but I'm not too concerned about this single change, so feel free to make a call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nkolev92 thanks for creating the follow-up issue!

_logger = logger ?? throw new ArgumentNullException(nameof(logger)); ;
}

public async Task<IEnumerable<PackageVulnerabilityMetadataContextInfo>> GetVulnerabilityInfoAsync(PackageIdentity packageId, CancellationToken cancellationToken)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use List to avoid constant allocations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

…ulnerable to show warning indicator by Installed tab and by transitive package in package list
@jebriede jebriede dismissed stale reviews from nkolev92 and aortiz-msft via 486d803 August 29, 2023 19:47
@jebriede jebriede force-pushed the dev-jebriede-TransitiveVulnerabilities branch from b097f4f to 486d803 Compare August 29, 2023 19:47
nkolev92
nkolev92 previously approved these changes Aug 29, 2023
@jebriede jebriede merged commit 6179a99 into dev Aug 30, 2023
@jebriede jebriede deleted the dev-jebriede-TransitiveVulnerabilities branch August 30, 2023 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show vulnerabilities in transitive packages for PackageReference type projects in PMUI

3 participants