fix: npm run audit also on patched packages #7042
Open
+70
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's the problem this PR addresses?
This PR was created by me and @Gudahtt; without him, this PR would never have existed. 👏
yarn npm auditwas not auditing packages that sit behind the patch: protocol (or any protocol that uses resolution dependencies). It only considered locators with an npm: reference, so patched (and similar) packages were skipped and their underlying npm package was never sent to the audit.That created a gap: vulnerabilities in patched packages were not reported.
How did you fix it?
Use the resolver’s resolution dependencies: For each descriptor, we call resolver.getResolutionDependencies(). When that returns entries, we recurse by calling processDescriptor(parent, resolutionDependencyDescriptor) for each, so we follow the real source (e.g. the npm package behind a patch) instead of hardcoding protocols.
Devirtualize before resolving: We run structUtils.ensureDevirtualizedDescriptor(descriptor) before calling into the resolver, so we never call getResolutionDependencies on a virtual descriptor.
Graceful fallback: If the descriptor has no resolution dependencies, we keep the current behavior: we treat the resolved package as the one to audit and continue the tree walk as before.
One place for recursive traversal: We no longer return early in the “has resolution dependencies” branch. Both that branch and the normal branch fall through to a single if (recursive) { … queue pkg.dependencies } at the end, so recursive traversal is shared and the full dependency tree is still audited.
Checklist