Skip to content

Vendored gem scan exits 1 on every run after its own remedy is followed: a native gem patched with get --mode hosted (or agent) is refused again and counted as "left to patch" #2269

Done

Description

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

Summary

Vendored mode refuses a gem with a native extension and tells the user to patch it in another mode ("Patch json with --mode hosted or --mode agent, which build the extension"). After the user does exactly that (socket-patch get json --mode hosted, or --mode agent), every later socket-patch scan --mode vendored still tries to vendor that gem, prints the same error with the same remedy, counts the gem as failed and as "left to patch", and exits 1. The gem is patched: the app loads the patched code and socket-patch vex attests all five gems.

No scan of the project reports it as fully patched afterwards:

Command on the mixed project Result
scan --mode vendored exit 1, Cannot vendor pkg:gem/json… and …racc… again, "Vendored 0 packages; 3 already vendored; 2 failed.", "2 vulnerabilities left to patch (40%)"
scan --mode agent (when the native gems were patched with --mode agent) exit 0, "3 vulnerabilities left to patch (60%): 3 are in packages this run did not patch" (the three vendored gems)
scan --mode hosted exit 0, but three "Not hosted …" lines and three warnings that tell the user to un-vendor rack, rake and nokogiri
scan (no --mode) exit 2, asks for a mode (documented)
vex exit 0, 5 statements

Impact

A stock Rails Gemfile has gems with native extensions (json, puma, bootsnap, racc, bigdecimal, …), so every vendored-mode Ruby project ends up in this state by following the tool's own advice. docs/ecosystems.md then tells the user to "pass --mode on later runs". A CI job or a scheduled socket-patch scan --mode vendored fails on every run from then on, with an error whose remedy has already been applied, and the closing totals say 40% of the vulnerabilities are unpatched when none is. The files are not damaged: installs stay clean and rollback gives the pair back byte for byte.

Repro

Bundler 4.1.1 on Ruby 3.3.6, bundle config set --local path vendor/bundle. Patches for rack 2.2.8, rake 13.2.1 (pure Ruby), json 2.9.1 and racc 1.8.1 (native extension) and nokogiri 1.18.10, served by the repo's stand-in (tests/nokogiri/patch_service.rb); $MOCK stands for --api-url … --patch-server-url … --api-token … --org ….

cat > Gemfile <<'G'
source "https://rubygems.org"

gem "rack", "~> 2.2.8"
gem "rake", "13.2.1"
gem "json", "2.9.1"
gem "nokogiri", "1.18.10"
G
bundle config set --local path vendor/bundle && bundle install

socket-patch scan --mode vendored $MOCK          # exit 1, as documented
# Error: Cannot vendor pkg:gem/json@2.9.1?platform=ruby: json-2.9.1.gemspec declares native extensions; bundler does
#   not build extensions for path-sourced gems. Patch json with `--mode hosted` or `--mode agent`, which build the extension
# Error: Cannot vendor pkg:gem/racc@1.8.1?platform=ruby: … Patch racc with `--mode hosted` or `--mode agent` …
# Vendored 3 packages; 2 failed.
bundle install

socket-patch get json --mode hosted $MOCK        # exit 0, "Switched 1 package to hosted patches"
socket-patch get racc --mode hosted $MOCK        # exit 0
BUNDLE_FROZEN=true bundle install                # clean; the app loads all five patched gems

socket-patch scan --mode vendored $MOCK ; echo $?
#   [skip] pkg:gem/nokogiri@1.18.10?platform=ruby (already vendored)
#   [skip] pkg:gem/rack@2.2.8?platform=ruby (already vendored)
#   [skip] pkg:gem/rake@13.2.1?platform=ruby (already vendored)
# Error: Cannot vendor pkg:gem/json@2.9.1?platform=ruby: json-2.9.1.gemspec declares native extensions; … Patch json with `--mode hosted` or `--mode agent`, which build the extension
# Error: Cannot vendor pkg:gem/racc@1.8.1?platform=ruby: racc-1.8.1.gemspec declares native extensions; … Patch racc with `--mode hosted` or `--mode agent`, which build the extension
# Vendored 0 packages; 3 already vendored; 2 failed.
# Patched 3 packages, fixing 3 vulnerabilities (3 high).
# 2 vulnerabilities left to patch (40%): 2 are in packages this run did not patch.
# 1

socket-patch vex --output vex.json --product pkg:generic/app@1 $MOCK
# Wrote OpenVEX document with 5 statements to vex.json

--json on the re-scan: "status": "partialFailure", two failed events with native_extensions_unsupported for json and racc, summary.failed: 2.

With socket-patch get json --mode agent and get racc --mode agent in place of the hosted ones, the vendored re-scan prints the same two errors and exits 1, and scan --mode agent exits 0 with "3 vulnerabilities left to patch (60%)".

Expected

docs/ecosystems.md, "Ruby gems: gems vendored mode refuses": the refusals "name another mode that can patch the gem", "To patch one gem in another mode, name it: socket-patch get <gem> --mode hosted", and "Once a project holds patches of two modes, a scan with no --mode stops and asks which mode to use, so pass --mode on later runs." A later scan --mode vendored on such a project should therefore be a run that can succeed: a gem that already holds its patch in hosted or agent mode is not a failure of the vendored scan. It should be reported as patched in that mode (a skip, as the hosted scan does for vendored gems with its "leaves vendored gems as they are"), the run should exit 0 when nothing else failed, and the closing totals should not count a vulnerability that a patch of another mode already fixes as "left to patch".

Actual

Exit 1 on every vendored scan, the already-followed remedy printed again, and "2 vulnerabilities left to patch (40%)" for a project whose vex attests every patch.

Versions

Bundler Ruby Result
4.1.1 3.3.6 reproduces (hosted remedy, twice)
4.0.25 3.3.6 reproduces (hosted remedy and agent remedy)
2.5.22 3.3.6 reproduces (hosted remedy)

main cfc870f, Linux x86_64. Nothing here is specific to Linux. Not a regression: v5.1.0 exits 1 on the same re-scan with the same two errors (it has no closing totals).

Suspect code

  • crates/socket-patch-core/src/vendor/gem.rs:653: the native_extensions_unsupported refusal is raised for a gem whatever mode already patches it; the vendored scan has no "already patched in hosted / agent mode" outcome for a gem it would refuse.
  • crates/socket-patch-cli/src/commands/scan/report.rs:568 (the closing totals): "left to patch … in packages this run did not patch" counts advisories that a patch of another mode in the same project already fixes.

Generated by Claude Code

Activity

  1. added
    bug
    bughunt
    pm:bundler
    ux
    on Nov 26, 2026
  2. mikolalysenko commented on Nov 26, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this issue. Branch: agent/fix-vendored-scan-gem-patched-in-other-mode.


    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:p1ux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions