Skip to content

Standalone vex refuses a hosted gem as not_applied because of a leftover <gem>-<version>-x86_64-linux directory that has no gemspec, after the scan's own rm -f … && bundle install remedy #2087

Closed

Description

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

Summary

A project that moves a gem from its precompiled platform build (nokogiri-1.16.0-x86_64-linux) to the ruby platform build, so that hosted mode can patch it, ends up with both gem directories in vendor/bundle. The hosted scan warns about the old platform copy and prints an rm -f … && bundle install command. After running that command Bundler loads the patched nokogiri-1.16.0, but the old gems/nokogiri-1.16.0-x86_64-linux/ directory is still there, with no gemspec, so RubyGems can't load it. Standalone vex still counts it as an installed copy and refuses to attest the gem:

Warning: omitting pkg:gem/nokogiri@1.16.0 from VEX: the patched files still hold the original content (not_applied)
Error: No applied patches with vulnerability metadata to attest.

A re-scan at that point prints no warning at all, and scan --vex writes a statement for the gem. So the two commands disagree, and vex names neither the directory it objects to nor a remedy. Only bundle clean --force (or deleting the directory by hand) clears it.

Impact

This is the path the tool itself sends people down. Agent mode refuses a native patch on a precompiled gem with "Install the ruby platform gem and use socket-patch scan --mode hosted", and hosted mode refuses a platform lock with redirect_gem_platform_unsupported. A user who does that and then follows the scan's cleanup command has a correctly patched app and a socket-patch vex step that exits 1 in CI, with a message that says the patch isn't applied.

Repro

A hosted patch for nokogiri 1.16.0 that changes lib/nokogiri/version/constant.rb (I used a local mock of the patch API serving the repacked upstream source gem; $MOCK stands for --api-url … --proxy-url … --patch-server-url …).

mkdir proj && cd proj && git init -q . && printf '**/vendor/bundle/\n.bundle/\n' > .gitignore
printf 'source "https://rubygems.org"\n\ngem "nokogiri", "1.16.0"\n' > Gemfile
printf 'require "bundler/setup"\nrequire "nokogiri"\nputs "patched=#{($SOCKET_PATCHED||[]).inspect} from #{Gem.loaded_specs["nokogiri"].full_name}"\n' > app.rb
bundle config set --local path vendor/bundle
bundle install                                   # installs nokogiri-1.16.0-x86_64-linux

socket-patch scan --mode hosted --yes $MOCK      # skipped: redirect_gem_platform_unsupported

bundle config set --local force_ruby_platform true
rm Gemfile.lock && bundle lock                   # the lock now holds `nokogiri (1.16.0)` only

socket-patch scan --mode hosted --yes $MOCK      # wires the gem, warns about the stale copy:
#   Re-run `socket-patch scan` to retry, or run `rm -f vendor/bundle/ruby/3.3.0/specifications/nokogiri-1.16.0-x86_64-linux.gemspec vendor/bundle/ruby/3.3.0/cache/nokogiri-1.16.0-x86_64-linux.gem && bundle install`.

rm -f vendor/bundle/ruby/3.3.0/specifications/nokogiri-1.16.0-x86_64-linux.gemspec \
      vendor/bundle/ruby/3.3.0/cache/nokogiri-1.16.0-x86_64-linux.gem && bundle install
bundle exec ruby app.rb                          # patched=["nokogiri"] from nokogiri-1.16.0
ls vendor/bundle/ruby/3.3.0/gems                 # nokogiri-1.16.0  nokogiri-1.16.0-x86_64-linux  …

socket-patch vex --product pkg:generic/x@1 $MOCK                 # exit 1, not_applied
socket-patch scan --mode hosted --yes --vex out.json --vex-product pkg:generic/x@1 $MOCK   # exit 0, 1 statement, no warning

bundle clean --force                             # Removing nokogiri-1.16.0-x86_64 (linux)
socket-patch vex --product pkg:generic/x@1 $MOCK                 # attests nokogiri

A plain bundle install in place of the rm -f … && bundle install command gives the same end state (Bundler fetches the ruby build either way, because the lock no longer lists the platform one), except that the old gemspec is still there too.

Expected

docs/ecosystems.md ("Ruby gems: gems already installed") says that when a copy can't be refreshed the run warns redirect_gem_stale_install, "naming the files to remove by hand", and the scan's next step reads "Install the patched gems with the command in the warning above …, then run socket-patch vex to verify the installed patches". After that command vex should attest the gem: the lock resolves nokogiri (1.16.0) from the patch registry, that copy holds the patched bytes, and the leftover platform directory has no gemspec, so nothing can load it.

If vex is meant to stay strict about any <name>-<version>-<platform> directory (#1092), then the remedy command has to remove that directory too, and the vex warning should name the path it is judging.

Actual

vex omits the gem with not_applied and exits 1 until the orphan directory is deleted. The scan stops warning as soon as the ruby build is installed.

Versions

Bundler Ruby Result
4.0.18 3.3.6 Reproduces (twice)
2.6.9 3.1.6 Reproduces (no CHECKSUMS lock)

socket-patch main 63f791d (5.1.0). Linux only. The platform directory name differs on macOS (-arm64-darwin) but the code path is the same.

Suspect code

  • crates/socket-patch-cli/src/commands/gem_refresh.rs:322 (files_to_remove): the remedy lists the gemspec and the cached archive of the stale copy, not its gems/<leaf> directory.
  • crates/socket-patch-core/src/crawlers/ruby_crawler.rs:1192 (is_platform_dir_of) and the platform-suffix fallback around find_each_by_purl: a <name>-<version>-<platform> directory counts as an installed copy without checking that specifications/<leaf>.gemspec exists.

One smaller thing seen on the way: the scan's next step says "a plain bundle install keeps the gems it already has". In this case a plain bundle install does fetch the patched ruby build, because the lock no longer names the platform build.


Generated by Claude Code

Activity

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

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this issue. Branch: agent/fix-gem-dir-without-gemspec-counted-installed.


    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