Repository navigation
Description
[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).
Summary
scan --mode vendored refuses a gem whose gem line sits inside a group block (gemfile_declaration_not_editable) and names two remedies: move the line to the top level, "or leave rake to hosted mode (--mode hosted)". After the second one is followed (socket-patch get pkg:gem/rake@13.4.2 --mode hosted, bundle install, the app loads the patched gem, vex attests it), every later scan --mode vendored raises the same refusal again, counts the gem as "left to patch" and exits 1.
This is the defect of #2269 for a second refusal. The fix for #2269 (#2274) added the skip vendor_gem_patched_in_other_mode, but only for native_extensions_unsupported; a gem refused for its declaration shape and patched in hosted mode still fails the scan. Not a regression: 5.1.0 has no such skip at all.
Impact
Gems in group :development / group :test blocks are in almost every Gemfile, so a project that uses vendored mode and follows the printed advice for those gems ends up with a scan --mode vendored that can never exit 0. A CI job or a scheduled patch update that runs it fails on every run, and the totals ("1 vulnerability left to patch") contradict vex, which attests the patch. Nothing on disk is harmed: the pair, the install and the hosted pin stay as they were.
Repro
No Socket API access needed; the script uses the repo's stand-in patch service (tests/nokogiri/patch_service.rb).
# ruby repro.rb <socket-patch binary> <checkout of this repo> (Ruby 3.x, Bundler 2.5+; needs rubygems.org)
require "fileutils"; require "tmpdir"
bin, repo = File.expand_path(ARGV[0]), File.expand_path(ARGV[1])
require File.join(repo, "tests/nokogiri/patch_service")
work = Dir.mktmpdir("indented-")
Dir.chdir(FileUtils.mkdir_p(File.join(work, "app")).first)
File.write("Gemfile", %(source "https://rubygems.org"\n\ngroup :development do\n gem "rake", "13.4.2"\nend\n))
system("bundle config set --local path vendor/bundle", out: File::NULL) or abort
system("bundle install", out: File::NULL, err: File::NULL) or abort
svc = PatchService.new("rake", "13.4.2", [], "0e2e0e2e-0e2e-4e2e-8e2e-0e2e0e2e0e2e", "GHSA-e2e0-e2e0-e2e0",
File.join(work, "svc"), "\nSOCKET_PATCHED_RAKE = 1\n")
args = "--api-url #{svc.url} --patch-server-url #{svc.url} --api-token fake --org nokogiri-e2e"
sp = lambda do |title, cmd|
puts "== #{title}"
system("#{bin} #{cmd} #{args} 2>&1 | grep -E 'rror|Switched|left to patch|Nothing left|Wrote'")
puts "exit=#{`#{bin} #{cmd} #{args} >/dev/null 2>&1; echo $?`.strip}" if cmd.start_with?("scan")
end
sp.call("1. scan --mode vendored", "scan --mode vendored")
sp.call("2. the remedy the refusal names: get --mode hosted", "get pkg:gem/rake@13.4.2 --mode hosted")
system("bundle install", out: File::NULL, err: File::NULL) or abort
puts " app loads: " + `bundle exec ruby -e 'require "rake"; print defined?(SOCKET_PATCHED_RAKE) ? "patched rake" : "UNPATCHED rake"'`
sp.call("3. scan --mode vendored again", "scan --mode vendored")
sp.call("4. vex", "vex --product pkg:generic/app --output vex.json")
svc.stopOutput on main 1b3f422 (Ruby 3.3.6, Bundler 4.1.1):
== 1. scan --mode vendored
Error: Cannot vendor pkg:gem/rake@13.4.2?platform=ruby: the `gem "rake"` declaration is indented (inside a group/conditional block); move it to the top level with the option `group: :development`, or leave rake to hosted mode (`--mode hosted`)
1 vulnerability left to patch: 1 is in packages this run did not patch.
exit=1
== 2. the remedy the refusal names: get --mode hosted
Switched 1 package to hosted patches; rewrote 2 files.
app loads: patched rake
== 3. scan --mode vendored again
[error] pkg:gem/rake@13.4.2?platform=ruby (gemfile_declaration_not_editable): the `gem "rake"` declaration is indented (inside a group/conditional block); move it to the top level with the option `group: :development`, or leave rake to hosted mode (`--mode hosted`)
1 vulnerability left to patch: 1 is in packages this run did not patch.
exit=1
== 4. vex
Wrote OpenVEX document with 1 statement to vex.json
The same on a project with a vendored rack at the top level beside it (Patched 1 package … 1 vulnerability left to patch (50%), exit 1), and on the sinatra app of the common-path cells, where the native puma is now skipped as #2269 asked while rake in group :development keeps the exit code at 1:
[error] pkg:gem/rake@13.4.2?platform=ruby (gemfile_declaration_not_editable): the `gem "rake"` declaration is indented …
Skipping pkg:gem/puma@8.1.3?platform=ruby: puma builds a native extension, which vendored mode cannot vendor; it stays patched in hosted mode (patch …)
Vendored 0 packages; 4 already vendored; 1 skipped.
Patched 5 packages, fixing 5 vulnerabilities (5 high).
1 vulnerability left to patch (17%): 1 is in packages this run did not patch.
Expected
CLI_CONTRACT.md (the vendor_gem_patched_in_other_mode row) makes a gem that vendored mode refuses, and that already holds the selected patch in a mode the refusal names, a benign skip with exit 0, counted as patched. The refusal for an indented declaration names hosted mode in the same way, so a gem that holds the selected patch there (the lock pins it and every installed copy holds it) should get the same skip. A gem in a group block that holds no patch, or another one, should be refused as today.
Actual
The refusal is raised on every run, the gem is counted as left to patch, exit 1.
Versions
| socket-patch | Bundler / Ruby | result |
|---|---|---|
main 1b3f422 |
4.1.1 / 3.3.6 | exit 1 on every vendored re-scan |
main 1b3f422 |
2.6.9 / 3.3.6 | the same |
| 5.1.0 | any | the same, for native gems too (#2269, fixed on main) |
Linux only; nothing here depends on the platform.
Suspect code
crates/socket-patch-cli/src/commands/vendor.rs:285: the skip returns early unless the refusal code is native_extensions_unsupported. Other refusals whose message sends the user to hosted mode (gemfile_declaration_not_editable, and the gems of an optional: true group, which are refused as indented) never reach it.
Generated by Claude Code
Activity
bundler: 2026-12-01 run (main 1b3f422): #2394, #2395 filed