Skip to content

Fix hosted scan reporting a refused gem as patched (#2303) - #2408

Open
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
agent/fix-gem-hosted-refused-pin-confirmed
Open

Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
agent/fix-gem-hosted-refused-pin-confirmed

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-fable-5-2

Fixes #2303

Summary

A hosted gem pin is two things: the source: option on the gem's Gemfile declaration, and the gem's own GEM section in Gemfile.lock. When the Gemfile loses the option and the lock keeps the section (a merge that took the other side of the Gemfile, a git checkout of that one file), Bundler installs the upstream gem again and a frozen install fails.

Before this change a hosted scan over that state said the gem was patched: an applied event, "Nothing left to patch", and a not_affected statement from --vex. Now the gem is skipped (redirect_unconfirmed), the same run's --vex writes no statement for it, and the warning says what happened and how to get the patch back. The scan still writes nothing for the gem, as before, and the exit code of a plain scan stays 0.

Root cause

confirm (core hosted/engine.rs) decides which patches a hosted run pinned. Gems fell to its last arm, which confirms a patch when its registry index URL occurs anywhere in the final files. The remote: line of the lock section is such an occurrence, so the lock alone confirmed the gem, although the gem rewriter had refused it. Cargo, Go, yarn berry and others were moved off that arm earlier, each to its rewriter's own report. Gems were not.

The change

  • Confirmation. The gem rewriter reports the patches whose pin is in place (RewriteResult::confirmed_gem_uuids), and confirm decides a pkg:gem/ purl by that report alone. A gem is in the set when its plan was written or found already whole, or when the plan was refused but the pair as it stands still pins the gem at the address this run was granted (gem_pin_stands). The second case keeps two pins counted that the URL probe used to count: a source … do block from socket-patch 5.0 / 5.1 that a formatter respelled, and a pin a Bazel rules_ruby hub holds in place.
  • The warning. When the lock resolves the gem from a section of the patch registry alone and the declaration no longer names it, redirect_gem_source_option now says so, says the gem is not patched, and gives the remedy docs/ecosystems.md already documents: bundle install once without frozen mode, then the hosted scan again. With no declaration in sight, redirect_gem_declaration_not_visible names that remedy beside its own, because the declaration may be out of sight with its source still on it.
  • Docs. CLI_CONTRACT.md (how a gem is confirmed, and the two warning rows) and docs/ecosystems.md (the table rows and the "Keep the Gemfile and the lock together" paragraph).

Every gem the new rule confirms was also confirmed by the old one, so the change can only turn a false "patched" into "skipped", never the reverse.

Evidence

The first commit holds the tests alone, and they fail there. With the fix arm switched off, the end-to-end test fails on the report from the issue:

"events":[{"action":"applied","purl":"pkg:gem/stale-probe-gem@1.0.0", …}], "summary":{"applied":1,"skipped":0, …}, "vex":{"statements":1, …}
  left: 1
 right: 0
Test Covers
hosted::engine::tests::a_gem_lock_pin_whose_gemfile_lost_its_source_is_not_confirmed #2303, all three states the issue lists: the option removed, another source named, the line deleted. Also that an intact pair is still confirmed on a re-scan.
e2e_redirect_gem_stale_install::gem_hosted_rescan_over_a_gemfile_that_lost_its_source_is_not_reported_patched #2303 through the CLI: the skipped event, the warning text, no VEX statement, both files byte-identical.
patch::redirect::tests::gem_pin_that_stands_is_confirmed_when_its_plan_is_refused A respelled 5.0 / 5.1 block stays confirmed; the same pair under another grant's address, a path block and a twice-declared gem do not.
patch::redirect::tests::gem_held_by_a_bazel_hub_is_confirmed_only_by_the_pin_that_stands The Bazel-held branch.
patch::redirect::tests::gem_orphaned_lock_pin_is_read_only_from_a_section_of_the_patch_registry_alone The new warning text is not used for a lock section that lists other remotes too.
patch::redirect::tests::gem_file_source_plan_never_speaks_of_the_patch_registry Vendored mode's Bazel lane shares the planner and keeps its own wording.

CI on the head commit: all 121 checks pass, and Cursor Bugbot found no issues.

Local runs on the final tree (Ruby 3.3.6, Bundler 4.0.18):

Command Result
cargo clippy --locked --workspace --all-features -- -D warnings (the CI form) clean
cargo test -p socket-patch-core --lib 8670 passed, 1 ignored
cargo test -p socket-patch-cli --test e2e_redirect_gem_stale_install 73 passed
cargo test -p socket-patch-cli --test e2e_vex_redirect 35 passed
cargo test -p socket-patch-cli --test e2e_redirect_gem_build -- --ignored (real Bundler) 55 passed
cargo test -p socket-patch-cli --test e2e_vendor_gem_build -- --ignored (real Bundler) 13 passed

cargo clippy --all-targets reports lints in test code on main with the pinned toolchain (71 in core). None is in a line this PR adds, and CI does not run that form.

Review

/code-review high ran on the diff. It found one regression (a respelled 5.0 / 5.1 block would have been reported as skipped) and several documentation and test gaps. All are fixed in the third commit, each with a test where one applies.

One finding is left as it is, because it is not new: a pin that a Bazel rules_ruby hub holds is reported as skipped once the grant token in its address rotates, while the warning says the earlier pin stays. The URL probe gave the same answer. Matching the address with the token wildcarded would also match a pin of a superseded patch, so it needs its own change.

Follow-ups

  • Whether a hosted scan should put the source: option back when the lock half is already in place. The issue leaves that open, and so does this PR.
  • The Bazel-held pin under a rotated grant token, above.

https://claude.ai/code/session_011f9aeQC9sKL8R3MTbbsn41


Generated by Claude Code

Refs #2303

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeQC9sKL8R3MTbbsn41
A hosted gem pin is the source option on the Gemfile declaration
and the gem's own GEM section in the lock. When the Gemfile loses
the option and the lock keeps the section, Bundler installs the
upstream gem, but the hosted scan reports the gem as patched and
its --vex attests it.

These tests fail until the next commit: the engine confirms the
gem, the scan emits an applied event, and the VEX document holds a
statement for it.

Refs #2303

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeQC9sKL8R3MTbbsn41
Hosted confirmation of a gem went by its patch registry URL
occurring anywhere in the final files. The remote line of a
Gemfile.lock section is such an occurrence, so a lock that kept
its patch section confirmed a gem whose Gemfile no longer names
the patch source, although the gem rewriter refused it. The scan
then reported the gem as patched and its --vex attested it, while
a frozen install fails and a plain one installs the upstream gem.

The gem rewriter now reports the patches whose pair it wrote or
found whole (confirmed_gem_uuids), and confirm decides a gem by
that report alone, as it does for Cargo and Go. A refused gem is
a skipped event (redirect_unconfirmed) and is not attested.

When the lock still resolves the gem from a section of the patch
registry alone, the refusal says so, says the gem is not patched,
and names the way back from docs/ecosystems.md: bundle install
once without frozen mode, then the hosted scan again.

Fixes #2303

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeQC9sKL8R3MTbbsn41
Review of the previous commit found that a pin which stands but
which the planner refuses to plan over was now reported as
skipped: a source block of socket-patch 5.0 / 5.1 that a
formatter respelled, for one. The gem rewriter now also confirms
a refused gem whose pair still pins it at the address this run
was granted (gem_pin_stands), and uses the same check for a gem a
Bazel rules_ruby hub holds in place.

The orphaned-pin wording is kept to what the rewriter can know.
With no declaration in sight the gem may be declared out of sight
with its source still on it, so that text no longer says the gem
is unpatched and keeps the out-of-sight remedy. A file: source
planned for vendored mode never gets the patch registry wording.

The contract and docs name the pairs that are counted and the
locks the new wording applies to.

Refs #2303

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeQC9sKL8R3MTbbsn41
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 1, 2026 15:18
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes hosted scan/VEX reporting for Ruby gems when Gemfile and lock diverge; behavior is stricter and more accurate but may surface previously hidden stale lock states.

Overview
Fixes a false patched result when Gemfile.lock still references the Socket patch registry but the Gemfile no longer names that source (e.g. after a partial merge or checkout). Hosted confirmation for gems no longer treats a patch URL in the lock as proof of a pin.

Confirmation now follows the gem rewriter’s confirmed_gem_uuids, aligned with cargo/golang: a gem counts only when manifest and lock agree at the granted registry URL, including pins that already stand when a new plan is refused (legacy source … do blocks, Bazel rules_ruby holds).

Detection/refusal adds orphaned-lock handling with clearer redirect_gem_source_option / redirect_gem_declaration_not_visible text (re-run bundle install without frozen mode). Rescans report skipped / redirect_unconfirmed, exit 0 on scan, and --vex omits the gem. Contract and ecosystem docs are updated; e2e and unit tests cover the regression and edge cases.

Reviewed by Cursor Bugbot for commit 17d3c76. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 17d3c76. Configure here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A hosted scan reports a gem as patched, and its --vex attests it, after the Gemfile stops naming the patch source

2 participants