fix: use commit query for npm packages resolved from git URLs#2863
Open
johnsaurabh wants to merge 2 commits into
Open
fix: use commit query for npm packages resolved from git URLs#2863johnsaurabh wants to merge 2 commits into
johnsaurabh wants to merge 2 commits into
Conversation
Packages from yarn.lock that are pinned to a git URL (e.g. resolved via git+https://) carry ecosystem=npm because that reflects the file they were found in, but they were never published to the npm registry. Querying OSV.dev by npm ecosystem+name produces false positive matches against unrelated packages that happen to share the same name on npm. The yarnlock extractor already populates SourceCode.Commit for these dependencies via commitextractor.TryExtractCommit. When a commit hash is present for an npm-ecosystem package, use a commit query instead so the lookup is scoped to the actual upstream git commit. Fixes google#2850
Verify that regular npm packages continue to use ecosystem queries, and that npm packages with a populated commit hash (git-pinned via yarn.lock) use a commit query instead.
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.
Overview
Fixes #2850
pkgToQueryqueried OSV.dev by npm ecosystem+name for all npm-ecosystem packages, including those resolved from git URLs in yarn.lock. These packages were never published to the npm registry, so the query returns false positives from unrelated packages that share the same name on npm.Details
The yarnlock extractor already populates
SourceCode.Commitfor git-pinned dependencies viacommitextractor.TryExtractCommit. When a commit hash is present for an npm-ecosystem package,pkgToQuerynow returns a commit query instead of an ecosystem query.```go
if imodels.Commit(pkg) != "" && imodels.Ecosystem(pkg).Ecosystem == osvconstants.EcosystemNPM {
return &api.Query{
Param: &api.Query_Commit{
Commit: imodels.Commit(pkg),
},
}
}
```
The gate is specific to npm. Other ecosystems are unaffected.
Testing
Checklist