You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(bundler): let Gemfile.lock decide each gem's source - #168
First of the per-ecosystem fixes from the registry audit: Bundler read rubygems.org for every gem, so a private gem's name could be looked up on RubyGems, where it may be someone else's.
The rule, now shared
crate::origins holds one rule for every ecosystem, used by PyPI (#164) and now RubyGems:
Packages a manifest takes from git, a path or a URL are skipped.
Settings the Count cannot read fail every lookup.
What the tool's lockfile records, and what declarations say where the Count can read them with certainty. When both speak they must agree; disagreement fails the lookup, or skips the package if either says git or a path.
Otherwise the public registry, only when nothing else is configured; elsewhere the lookup fails rather than guess.
Bundler
A Gemfile is Ruby, so the Count does not evaluate or approximate it. A first version parsed source blocks with regexes, and review found conditions, git blocks and continued lines that still led to RubyGems. That was the same mistake as re-implementing uv's resolution, so reading is now fail-closed by construction:
Plain Gemfiles. A strict line grammar (tokens, call, Reading::line) accepts only source, gem, group/platforms, gemspec, ruby and end with literal values. If every line parses, Bundler's DSL rule applies: the gem's source: option, else its source block, else the one top-level source (none: fails).
Anything else (a condition, git_source, eval_gemfile, a continued line, several top-level sources): the Gemfile is not relied on, and Gemfile.lock decides. A gem the lock does not record fails its lookup, asking for the lock to be committed.
Lock and Gemfile must agree where both speak, so a stale lock fails instead of sending a private name to RubyGems. GIT, PATH and plugin sections mean skipped.
.bundle/config is read line by line as KEY: value, the way Bundler reads it, not as YAML. Any setting outside a list of harmless ones (a mirror, BUNDLE_GEMFILE, a lockfile path, plugins, host keys), or any line of another shape, fails every lookup.
Symlinks. A symlinked .bundle directory, or a symlinked settings file, locally or in a GitHub tree, is unreadable rather than absent or read as the link's target.
Gems from git:, github:, path: and the like are listed as skipped.
Private gem sources are not read yet, so their gems' lookups fail rather than read RubyGems.
A gem now comes from the source its Gemfile names for it (a source block
or its source: option), else the remote Gemfile.lock records, else
RubyGems only when the Gemfile names no other top-level source; anywhere
else its lookup fails rather than read RubyGems for someone else's gem.
A source the Count cannot read, or an eval_gemfile, fails every lookup.
Gems from git, a path or GitHub are listed as skipped.
The rule now lives in one module, crate::origins, that PyPI and RubyGems
share and the other ecosystems will.
We reviewed changes in b6fbeb6...dda01c4 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
A Gemfile is Ruby, and reading sources out of it re-implemented Bundler:
conditions, git blocks and continued lines could all leave a private gem
looked up on RubyGems. Gemfile.lock now decides every gem it records. The
Gemfile is only read to tell whether an unrecorded gem can only be
RubyGems': every line must be a plain source, gem, group, platforms,
gemspec, ruby or end with literal values, naming no other source.
Otherwise unrecorded gems' lookups fail until the lock is committed.
A project .bundle/config with a setting that could move gems, such as a
mirror or BUNDLE_GEMFILE, fails every lookup, and one behind a symlink is
read as unreadable, like Python settings.
sweepies
changed the title
fix(bundler): take each gem's source from the Gemfile or Gemfile.lock
fix(bundler): let Gemfile.lock decide each gem's source
Nov 3, 2026
The reason will be displayed to describe this comment to others. Learn more.
Use of `unwrap_or` followed by function call, prefer `unwrap_or_else` instead
Calls to unwrap_or followed by a function call should be replaced with unwrap_or_else or unwrap_or_default, to increase laziness. The argument to unwrap_or is evaluated eagerly and unconditionally. unwrap_or_else or unwrap_or_default are evaluated lazily and only if required, sometimes
leading to lower overhead and fewer allocations.
The reason will be displayed to describe this comment to others. Learn more.
Use of `unwrap_or` followed by function call, prefer `unwrap_or_else` instead
Calls to unwrap_or followed by a function call should be replaced with unwrap_or_else or unwrap_or_default, to increase laziness. The argument to unwrap_or is evaluated eagerly and unconditionally. unwrap_or_else or unwrap_or_default are evaluated lazily and only if required, sometimes
leading to lower overhead and fewer allocations.
… does
- A Gemfile whose every line is a plain form says where each gem comes
from: its source: option, else its source block, else the one top-level
source, or none when it names no source. Where Gemfile.lock records the
gem too, the two must agree; a stale lock fails the lookup rather than
sending the name to RubyGems. Any other Gemfile leaves it to the lock.
crate::origins now combines declarations and locks this way.
- .bundle/config is read line by line as KEY: value, the way Bundler reads
it, not as YAML; an indented or other line is unreadable.
- A symlinked .bundle directory, locally or in a GitHub tree, and a
symlinked settings file in a GitHub tree, are unreadable rather than
absent or read as the link's target.
- The lock is the Gemfile's path plus .lock and .bundle sits in its
directory, whatever the Gemfile is called.
- The gem pattern requires matching quotes, and Gemfile strings with a
quote inside are not read.
A gem's own source: option or source block, read from a line the Count
understands, still counts when other lines are not read, so a stale
Gemfile.lock that records the gem on RubyGems makes its lookup fail.
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
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.
First of the per-ecosystem fixes from the registry audit: Bundler read rubygems.org for every gem, so a private gem's name could be looked up on RubyGems, where it may be someone else's.
The rule, now shared
crate::originsholds one rule for every ecosystem, used by PyPI (#164) and now RubyGems:Bundler
A Gemfile is Ruby, so the Count does not evaluate or approximate it. A first version parsed
sourceblocks with regexes, and review found conditions,gitblocks and continued lines that still led to RubyGems. That was the same mistake as re-implementing uv's resolution, so reading is now fail-closed by construction:tokens,call,Reading::line) accepts onlysource,gem,group/platforms,gemspec,rubyandendwith literal values. If every line parses, Bundler's DSL rule applies: the gem'ssource:option, else itssourceblock, else the one top-level source (none: fails).git_source,eval_gemfile, a continued line, several top-level sources): the Gemfile is not relied on, andGemfile.lockdecides. A gem the lock does not record fails its lookup, asking for the lock to be committed..bundle/configis read line by line asKEY: value, the way Bundler reads it, not as YAML. Any setting outside a list of harmless ones (a mirror,BUNDLE_GEMFILE, a lockfile path, plugins, host keys), or any line of another shape, fails every lookup..bundledirectory, or a symlinked settings file, locally or in a GitHub tree, is unreadable rather than absent or read as the link's target.git:,github:,path:and the like are listed as skipped.Docs: sources.md (package registries), managers.md, compatibility.md, departures.md (
#lockfile-registriesreplaces#python-indexes).