Skip to content

Vendored mode declares a transitive gem without require: false, so Bundler.require starts loading it at boot (hosted mode adds the option) #2084

Closed

Description

[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).

Summary

When vendored mode patches a gem that the Gemfile doesn't declare (a dependency of another gem), it appends a managed block that declares the gem in the default group without require: false:

# >>> socket-patch vendor (managed) >>>
gem "rake", "13.0.6", path: ".socket/vendor/gem/<uuid>/rake-13.0.6"
# <<< socket-patch vendor (managed) <<<

From then on Bundler.require (what config/application.rb of every Rails app runs at boot) requires that gem, which it did not do before the scan. Hosted mode adds require: false to its line for exactly this reason.

Impact

The app's boot behavior changes while the gem is vendored. Which change depends on the gem: with rake the main object gains the whole Rake DSL and FileUtils as private methods (task, file, rm_rf, sh, ...) in the app server process; other gems run load-time side effects, register at_exit hooks, or simply add boot time and memory. A security patch should not change what the app loads.

Repro

sp is socket-patch pointed at a patch API that has a patch for rake 13.0.6 (local mock of the API and registry; real rubygems.org for the rest).

mkdir v2 && cd v2 && git init -q .
printf '**/vendor/bundle/\n.bundle/\n' > .gitignore
cat > Gemfile <<'G'
source "https://rubygems.org"

gem "rake-compiler", "1.2.7"
gem "rake", "13.0.6"
G
bundle config set --local path vendor/bundle
bundle lock
sed -i '/^gem "rake", /d' Gemfile      # rake is now locked at 13.0.6 and only a transitive dependency
bundle install
cat > boot.rb <<'R'
require "bundler/setup"
Bundler.require(:default)
puts "rake loaded at boot=#{!defined?(Rake).nil?} main responds to task=#{respond_to?(:task, true)} rm_rf=#{respond_to?(:rm_rf, true)}"
R
bundle exec ruby boot.rb
sp scan --mode vendored && bundle install
bundle exec ruby boot.rb
--- before
Bundler 4.0.18: rake loaded at boot=false main responds to task=false rm_rf=false
--- after scan --mode vendored
Bundler 4.0.18: rake loaded at boot=true main responds to task=true rm_rf=true

The same project after scan --mode hosted instead:

Bundler 4.0.18: rake loaded at boot=false main responds to task=false rm_rf=false
+gem "rake", "13.0.6", source: "…/patch-registry/gem/<token>/<uuid>/", require: false # added by socket-patch (transitive dependency)

Expected

docs/ecosystems.md, "Ruby gems: hosted mode": "require: false keeps Bundler.require from loading the gem at boot, which it did not do before the line was there; the gems that depend on it load it as they always did." The same holds for the line vendored mode adds. The vendored backend states the rule itself for declared gems (crates/socket-patch-core/src/vendor/gem.rs:1382: "dropping require: false auto-requires the gem at boot, changing app behavior while vendored").

Actual

The managed block's declaration has no require: false, so Bundler.require loads the gem.

Versions

Bundler Ruby Result
4.0.18 3.3.6 reproduces
2.6.9 3.1.6 reproduces
2.5.22 3.3.6 reproduces
4.0.18, hosted mode 3.3.6 does not reproduce (require: false is written)

socket-patch main 63f791d (5.1.0). Linux only; not platform-specific. Projects that are already vendored have the block without the option, so a fix needs the revert and the re-vendor paths to accept both forms.

Suspect code

crates/socket-patch-core/src/vendor/gem.rs:1323: the appended block is formatted as gem "{name}", "{version}", path: "{rel}" with no require: false. The block parser at crates/socket-patch-core/src/vendor/gem.rs:2338 matches that exact shape.


Generated by Claude Code

Activity

  1. added
    bug
    bughunt
    pm:bundler
    on Nov 14, 2026
  2. mikolalysenko commented on Nov 16, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this issue. Branch: agent/fix-vendored-gem-transitive-require.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedbugbughuntpm:bundlerpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions