Repository navigation
Conversation
Author
|
Hi @wraithgar, would you mind reviewing this one when you get a chance? It stops git fetch from parsing the ref as an option. Happy to address any feedback. |
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 the option-injection reported in npm/cli#10306, which lives in this package: in
lib/clone.js, theother()path built its fetch as['fetch', 'origin', revDoc.rawRef]with the shallow--depth=1flag appended after the ref. A remote can advertise a ref whose name starts with-(kept verbatim bylines-to-revs.jsfor refs that are not tags, heads, pulls orHEAD), and a matching committish survivesnpm-package-arg, so the ref was parsed bygit fetchas an option — for example--upload-pack=<cmd>, which git runs through the shell for local remotes while npm is still resolving the dependency.Fix
Build the fetch arguments as
['fetch', 'origin', '--depth=1'?, '--end-of-options', revDoc.rawRef]: the shallow flag (when used) stays before--end-of-optionsso it is not treated as a refspec, and the advertised ref is always passed after--end-of-optionsso it can never be parsed as an option. Git then simply reports that it cannot find the remote ref.Tests
test/clone.jsmocksrevsandspawnand asserts the exact fetch argv for a ref of--upload-pack=false, for both shallow and non-shallow fetches. No live git payload is executed. The test fails on the base commit (argv has no--end-of-options) and passes with the fix.tap) run twice locally: 11/11 test files pass both times, with 100% coverage.npm run lintpasses.