RubyGems: Use of --source should not fallback to other sources#9627
Open
williantenfen wants to merge 1 commit into
Open
RubyGems: Use of --source should not fallback to other sources#9627williantenfen wants to merge 1 commit into
williantenfen wants to merge 1 commit into
Conversation
When `--source` is passed to `gem install`, the gems named on the command line are now resolved exclusively from the explicitly requested sources instead of silently falling back to the default sources. Their dependencies may still come from the default sources. Previously, an explicit `--source` was merely appended to the source list, so a private or broken source would silently fall back to rubygems.org and could install an unexpected gem of the same name. Co-authored-by: Cursor <cursoragent@cursor.com>
8592736 to
9aa5cf2
Compare
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.
What was the end-user or developer problem that led to this PR?
--sourceis only appended to the source list, so if the requested source isunreachable or doesn't carry the gem,
gem installsilently falls back to thedefault sources and installs from there with a success exit code:
This is a source-substitution / dependency-confusion risk: if a private gem shares
a name with a public one, an attacker squatting that name can have their code
installed whenever the private source is down (flagged as "technically a security
issue" in the original report).
Refs #2313
What is your fix for the problem, implemented in this PR?
Gems named on the command line are now resolved only from the explicitly requested
--source(s), failing if not found there. Their dependencies still resolve fromall configured sources, so private gems that depend on public ones keep working.
--sourcerecords its URLs inoptions[:sources], which are passed to the resolveras
explicit_sources;InstallerSet#add_always_installthen resolves the namedgems against a set built only from those sources, leaving dependency resolution
untouched.
The thread also suggested phasing this in via a deprecation warning first — happy to
do that instead if preferred.
Make sure the following tasks are checked