fix(audit): exclude locally linked packages from vulnerability audit #9044
Open
lucas-gomes-santana wants to merge 1 commit intonpm:latestfrom
Open
fix(audit): exclude locally linked packages from vulnerability audit #9044lucas-gomes-santana wants to merge 1 commit intonpm:latestfrom
lucas-gomes-santana wants to merge 1 commit intonpm:latestfrom
Conversation
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #8920
npm auditwas reporting false positive critical vulnerabilities for packages that resolve to local folders via symlinks ("link": trueinpackage-lock.json).Root Cause
When a
package-lock.jsondeclares a locally linked package, Arborist creates two nodes in the dependency tree:Linknode atnode_modules/<package-name>(withisLink = true)Nodeat the resolved local path (the symlink target, withlinksIn.size > 0)The
shouldAudit()method inaudit-report.jswas not excluding either of these nodes, so both were included in the bulk advisory payload sent to the registry. If a package on the registry happened to share the same name and version as the local package, its vulnerabilities would be incorrectly reported against the local one.This was affecting real-world projects, such as the Microsoft Authentication Library for JS, which has an internal package named
electron-test-appthat coincidentally shares its name with a known malware package on the registry.Fix
In
workspaces/arborist/lib/audit-report.js, theshouldAudit()method now returnsfalsefor:node.isLink— the symlink node itselfnode.linksIn?.size > 0— the local target folder the symlink points toThis prevents locally resolved packages from ever reaching the registry bulk advisory request.
Testing
Added a new test case and fixture (
audit-linked-package) toworkspaces/arborist/test/audit-report.jsthat:MockRegistrystrict mode)