Skip to content

Scan totals say "Nothing left to patch." when a refused gem is locked as precompiled platform builds (nokogiri) #2181

Closed

Description

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

Summary

When a hosted or vendored scan refuses a gem that Gemfile.lock holds as precompiled platform builds (redirect_gem_platform_unsupported, vendor_prebuilt_platform_pending), the closing totals do not count its advisories as left to patch. If the run patched another gem, it ends with Nothing left to patch. while the refused gem is still vulnerable. If it patched nothing, it prints no totals at all. A refused ruby-platform gem is counted correctly (1 vulnerability left to patch: 1 is in packages this run did not patch.).

Impact

A stock bundle install on Bundler 2.5+ / 4.x locks nokogiri for 8 platforms, so this refusal is what a new user sees whenever the patch has prebuilds for fewer. The run exits 0, and its last line tells them the project is fully patched. The only sign otherwise is one long warning further up. In a monorepo scan from the root it is easier to miss: one project is patched, another is refused, and the single closing line for the whole run says Nothing left to patch.

Repro

Run from a checkout after cargo build --release -p socket-patch-cli. It uses the repo's stand-in for the patch service (tests/nokogiri/patch_service.rb) and real gems from rubygems.org.

#!/bin/bash
# Run from a socket-patch checkout after `cargo build --release -p socket-patch-cli`.
# Needs Ruby >= 3.1 with Bundler 2.5+ and access to rubygems.org.
set -u
REPO=$PWD; SP=$REPO/target/release/socket-patch; W=$(mktemp -d)
# The repo's stand-in for the patch service: nokogiri 1.18.10 with patched
# builds for 3 platforms, and rack 2.2.8 (ruby platform).
cat > $W/serve.rb <<RB
require "$REPO/tests/nokogiri/patch_service.rb"
n = PatchService.new("nokogiri", "1.18.10", %w[x86_64-linux-gnu aarch64-linux-gnu arm64-darwin],
  "44444444-4444-4444-8444-444444444444", "GHSA-aaaa-bbbb-nok1", "$W/n", "\n# patched\n")
r = PatchService.new("rack", "2.2.8", [], "77777777-7777-4777-8777-777777777777", "GHSA-aaaa-bbbb-rck1", "$W/r", "\n# patched\n")
File.write("$W/urls", "#{n.url} #{r.url}"); sleep
RB
ruby $W/serve.rb & SRV=$!
until [ -s $W/urls ]; do sleep 1; done
read NOKO RACK < $W/urls
sp() { u=$1; shift; "$SP" "$@" --api-url $u --patch-server-url $u --api-token fake --org nokogiri-e2e 2>&1 | grep -v 'api-token\|Got: fake' | cut -c1-230; }

echo "### A: a precompiled platform gem the scan refuses"
mkdir $W/a && cd $W/a
printf 'source "https://rubygems.org"\n\ngem "nokogiri", "1.18.10"\n' > Gemfile
bundle config set --local path vendor/bundle >/dev/null; bundle install >/dev/null 2>&1
grep -c '    nokogiri (1.18.10-' Gemfile.lock
sp $NOKO scan --mode hosted --yes; echo "exit=$?"

echo "### B: a ruby-platform gem the scan refuses"
mkdir $W/b && cd $W/b
printf 'source "https://rubygems.org"\n\ngem "rack", "2.2.8"\ngem "rack", "2.2.8"\n' > Gemfile
bundle config set --local path vendor/bundle >/dev/null; bundle install >/dev/null 2>&1
sp $RACK scan --mode hosted --yes; echo "exit=$?"
kill $SRV

Output (Bundler 4.0.18, Ruby 3.3.6):

### A: a precompiled platform gem the scan refuses
8
Found 2 packages (2 ruby)
Switched 0 packages to hosted patches; rewrote 0 files.
No patches could be switched to hosted:
  pkg:gem/nokogiri@1.18.10?platform=ruby: no lockfile entry pinning it could be rewritten (see the warning below)
Warning: Gemfile.lock locks platform-specific builds of nokogiri 1.18.10 (...), and the patch has no patched build for ... redirect skipped
exit=0
### B: a ruby-platform gem the scan refuses
Found 1 package (1 ruby)
Switched 0 packages to hosted patches; rewrote 0 files.
No patches could be switched to hosted:
  pkg:gem/rack@2.2.8?platform=ruby: no lockfile entry pinning it could be rewritten (see the warning below)
Warning: `gem "rack"` is declared more than once in Gemfile; ...

1 vulnerability left to patch: 1 is in packages this run did not patch.
exit=0

With a second gem that does get wired in the same project (a Gemfile with nokogiri and rack, the lock naming x86_64-linux-musl, which the patch has no prebuild for, and patches offered for both), the run ends:

Not hosted pkg:gem/nokogiri@1.18.10?platform=ruby: no lockfile entry pinning it could be rewritten (see the warnings below)
Next steps:
  1. Commit Gemfile and Gemfile.lock to keep the hosted patches.
  2. Run `socket-patch vex` to verify the installed patches (...).

Patched 1 package, fixing 1 vulnerability (1 high).
Saved about 2 hours of engineering time (1 package upgrade at ~2 hours).
Nothing left to patch.

scan --mode vendored on project A prints Vendored 0 packages; 1 skipped. and no totals either.

Expected

crates/socket-patch-cli/CLI_CONTRACT.md (the scan closing totals): "'Left to patch' counts the advisories of every package a patch was offered for that this run did not fix", and "Nothing is printed when no patch was offered at all." A patch was offered for nokogiri and the run did not fix it, so run A should end with 1 vulnerability left to patch: 1 is in packages this run did not patch., as run B does, and the two-gem run should not say Nothing left to patch.

Actual

The refused platform gem is left out of the count: no totals in run A, Nothing left to patch. in the two-gem run and in a monorepo scan from the root.

Versions

Bundler Ruby Mode Result
4.0.18 3.3.6 hosted, nokogiri alone (default 8-platform lock) no totals line
4.0.18 3.3.6 vendored, same project no totals line
2.5.22 3.3.6 hosted, nokogiri (lock with x86_64-linux-musl) beside a wired rack Nothing left to patch.
2.5.22 3.3.6 hosted, monorepo root: api wired, web refused Nothing left to patch.
4.0.18 3.3.6 hosted, rack declared twice (ruby platform, refused) correct: 1 vulnerability left to patch

Tested on main 6579162, Linux. Nothing here is specific to Linux, so macOS and Windows should behave the same. No first bad release: precompiled platform gems reached hosted and vendored mode after 5.1.0, so no release has this path yet.

Suspect

crates/socket-patch-cli/src/commands/scan/mod.rs:3811: in_project looks the patched purl (pkg:gem/nokogiri@1.18.10) up among the lockfile entries, and a lock that holds only platform entries (nokogiri (1.18.10-x86_64-linux-gnu)) seems not to match it. The gem is then taken for a copy the project does not use (outside_project) and Counts::of skips it (crates/socket-patch-cli/src/commands/scan/report.rs:279).


Generated by Claude Code

Activity

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

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this issue. Branch: agent/fix-gem-platform-lock-left-to-patch.


    Generated by Claude Code

  3. added a commit that references this issue on Nov 20, 2026
    ecd8b0c
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