Skip to content

fix(bundler): let Gemfile.lock decide each gem's source - #168

Merged
sweepies merged 5 commits into
mainfrom
feat/rubygems-origins
Nov 3, 2026
Merged

sweepies merged 5 commits into
mainfrom
feat/rubygems-origins

Conversation

@sweepies

@sweepies sweepies commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

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:

  1. Packages a manifest takes from git, a path or a URL are skipped.
  2. Settings the Count cannot read fail every lookup.
  3. 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.
  4. 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.

Docs: sources.md (package registries), managers.md, compatibility.md, departures.md (#lockfile-registries replaces #python-indexes).

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.
@deepsource-io

deepsource-io Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

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.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Rust Nov 3, 2026 10:29p.m. Review ↗
JavaScript Nov 3, 2026 10:29p.m. Review ↗
Shell Nov 3, 2026 10:29p.m. Review ↗

Important

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.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
count-patchula 6a12c2f Commit Preview URL

Branch Preview URL
Nov 03 2026, 10:18 PM

@context7

context7 Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Docs7 for sweepies/count-patchula

Result Status Action
Deployment ➖ Not used —
Content review ➖ Did not run. This site has no agent runs available this month. Wait for the monthly reset or check your Docs7 plan. —

Commit dda01c4

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 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
Comment thread crates/engine/tests/working_tree.rs Outdated
"config/bundle",
"BUNDLE_MIRROR__ALL: \"https://gems.acme.dev\"\n",
);
std::fs::create_dir(root.join(".bundle")).unwrap();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using `std::fs::create_dir` instead of `std::fs::create_dir_all`


fs::create_dir_all is preferable over fs::create_dir as it creates all
missing components in the provided path without erroring out.

Comment thread crates/manager/src/bundler.rs Outdated
Comment on lines +346 to +348
let end = (i + 1..bytes.len())
.find(|&j| !word(bytes[j]))
.unwrap_or(bytes.len());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Comment thread crates/manager/src/bundler.rs Outdated
Comment on lines +367 to +369
let end = (i..bytes.len())
.find(|&j| !word(bytes[j]))
.unwrap_or(bytes.len());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant