Repository navigation
Fetch gems that get built over https only; refuse paths that cannot be probed - #2112
Conversation
…only The source gem of a native-extension rebuild and the gems its build lacks are downloaded from `SOCKET_RUBYGEMS_URL` (default https://rubygems.org) and used when their sha256 is the one that registry's compact index records. Nothing required the registry to be https, and the client followed a redirect from https to http. Over plain http whoever sits on the network path serves both the archive and the checksum, and the archive's `extconf.rb` then runs. The own-source proof does not cover files the installed copy lacks (a precompiled nokogiri ships no `patches/**`). These downloads now go through `SecureRegistryClient`: https, or plain http to a loopback host (`localhost`, `127.0.0.1`, `[::1]`: a local mirror, the hermetic tests), and nothing else. Any other URL is refused before a request is made, with a message that says to use an https URL. A redirect that leaves https, or leads to an http host that is not this machine, is not followed. The outcome is that of a source gem out of reach: a gem RubyGems built is rebuilt in place, a precompiled gem is refused with nothing written, in a dry run too. The hosted unwind had the same hole. After `rollback` / `remove`, the installed copy of a restored gem is replaced by the registry's archive (and built, for a native gem), verified against the sha256 the restore read from the same registry's compact index and pinned into `CHECKSUMS`. `UpstreamClient::rubygems_sha256` and the refresh's registry download go through the same client, so that checksum is never read over plain http. For an https or loopback registry nothing changes. With any other `SOCKET_RUBYGEMS_URL` a pin whose `CHECKSUMS` entry must be re-pinned is refused with the https message, as it is when the registry cannot be reached. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The link guards read any `lstat` failure as "not a link": the private `is_symlink`, and `stage_dirs` with the refresh's copy of it. A path that could not be probed for another reason than "not found" (permission denied, a parent that is no directory, an I/O error) was then created, emptied or deleted by path like a real directory. Nothing said it was not a planted link. Only "not found" now reads as nothing there (`containment::try_entry_type`). Any other probe error is refused like a link, with a message naming the path: - the stage of a rebuild and of a hosted refresh is neither swept nor opened; a gem RubyGems built is rebuilt in place, a precompiled gem is refused; - the extension dir a recovery moves, the extension dir a restore empties and the backup a rollback restores from are refused, so a rollback no longer reports a copy whose gem dir cannot be read as carrying no backup; - a new backup of the original build is made only when no backup and no marker are there, not when they cannot be seen; - a file the installed copy holds but the own-source proof cannot look at fails the proof instead of being skipped, which let a differing file behind an unsearchable directory pass. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ne loopback rule Review of the https-only gem registry client: - A plain-http request to a loopback registry is accepted because it crosses no network, but the client kept the system proxy. With `HTTP_PROXY` or `ALL_PROXY` set and no `NO_PROXY`, the request went to the proxy host in clear text. `SecureRegistryClient` now sends plain http through a client built without a proxy; https keeps the system proxy, where it is tunnelled and verified end to end. - The gate parsed the URL while the fetch compared its text, so `HTTPS://mirror` passed the first and was refused by the second. The request is now made to the URL the gate parsed (`secure_url`). - `no_downgrade_redirects` repeated the self-update's policy and stopped one redirect short of it. Both now use `redirects_unless` and `MAX_REDIRECTS`, which count as `Policy::limited(10)` does. - "This machine" was defined twice, differently. `is_loopback_host` is the one rule, for the gem registry and for a grant's patch server URL: `localhost` or a loopback address. A name under `.localhost` is no longer taken for a grant URL either, since nothing makes the resolver answer it locally; `--patch-server-url` still admits such a server. - Messages named the registry with the credentials of `SOCKET_RUBYGEMS_URL` in them: the remedy, "lists no ...", a sha256 mismatch, an index that is not text, and the errors of the upstream checksum lookup. All are redacted now. - The client test followed a redirect to a host name with an unguarded client. Every URL in these tests now names this machine, the refused ones too. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…stry client per run After `rollback` / `remove` puts a gem back on its upstream entry, the installed copy is judged against the upstream sha256. When the lock pins none and `SOCKET_RUBYGEMS_URL` is refused (plain http, not this machine), the lookup's refusal was dropped with `.ok()?`: the copy was neither refreshed nor mentioned, while it still held the patched build. `upstream_archive` now returns that refusal (`UpstreamArchive::Unverified`) and the unwind reports each installed copy it could not judge under `upstream_gem_stale_install`: "could not be checked against the upstream gem", the reason, and the files to remove. It is not said to hold the patched build, which nothing proves. The human warning counts such copies apart from the ones known to be stale. A lookup that fails for another reason (offline, a registry error) is passed over as before. The refresh built a registry client for every URL of every stale gem. The unwind now builds one for the run (`Source::Registry(&client)`), and none when nothing is stale. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ctory check `restore_original_build` refused a backup dir it could not probe, but read any error on the backup's description file, one level below, as "no backup", and an unreadable marker as "no marker". Rollback could then report a copy as carrying nothing, or rebuild in place and delete the marker, while the original build sat unrestored in its backup. Only "not there" now says there is no backup and no marker. A description file that cannot be probed, and a marker file that is there but cannot be read or understood (another schema), fail the restore with the path and the `gem pristine` remedy. A backup that is there is restored whatever the marker says, as before. The stage-directory guard of a rebuild and of a hosted refresh was the same four-arm match written twice. Both call `containment::ensure_dir_or_absent`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…report A request to a loopback gem registry never goes through a proxy; a name under `.localhost` is not a loopback host; credentials in `SOCKET_RUBYGEMS_URL` are sent and never printed; ten redirects at most. After an unwind under a refused registry, an installed copy that could not be checked is reported under `upstream_gem_stale_install`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryHigh Risk Overview Registry transport. Gem source downloads, native-extension rebuilds, hosted refresh, and upstream checksum lookup now go through Upstream unwind / rollback. When the registry cannot be used to learn the upstream sha256, installed copies are surfaced as unchecked ( Filesystem safety. Stage dirs, backups, markers, and extension paths use Contract docs ( Reviewed by Cursor Bugbot for commit f8e8054. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit f8e8054. Configure here.
After a hosted rollback whose registry was refused, an installed copy that could not be checked was listed only when its archive was still readable in the gem home's cache. With the cache pruned, as slim images have it, the copy was passed over and the patched build stayed in use with no warning. A copy that cannot be judged is now listed whether or not its archive is cached. A copy with a known upstream checksum is judged as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
[agent] PR shepherd: final review of Question: should
Everything else looks sound: the scheme and redirect rules, the proxy split for loopback, credential redaction and the fail-closed probes are tested.
Labelled Generated by Claude Code |
Main gained the in-tree build products fix (#2108) and the hosted scan's refresh of the archive beside an agent-patched gem (#2103). Both touch files this branch changes; three hunks conflicted, each resolved by keeping both sides. crates/socket-patch-core/src/patch/gem_ext.rs, `recover_interrupted_rebuild_sync`: this branch's `refuse_link(&ext, ..)` (a link, or an extension dir that cannot be probed, is refused) in place of main's unchanged `is_symlink` check, followed by main's new restore of the gem's tree from the snapshot of an interrupted in-place build. crates/socket-patch-cli/src/commands/gem_refresh.rs, `report`: main's two headlines for gems patched in place become arms of this branch's `known` headline, which the count of copies that could not be checked is then added to. The words "the switch to hosted patches" come from `switch`. crates/socket-patch-cli/src/commands/gem_refresh.rs, `stale_after_restore`: this branch's listing of a copy that cannot be judged whether or not its archive is cached, with main's new `in_place: false` field. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The in-tree build products fix (#2108) acts on what a listing lacks: a file the tree snapshot does not show is removed when a build is undone, and a rollback removes what the marker lists and the backup does not hold. Its probes read an error as "nothing there": - `restore_tree` listed the snapshot's copies with a walk that skips what it cannot read. A snapshot whose copies could not be listed was read as holding none, and every file of the gem's own tree was removed. `snapshot_tree` listed the gem's tree the same way, so a directory that could not be read was left out and its files were the next undo's to remove. Both now use `try_tree_files`, which fails instead. - Recovery took a snapshot dir it could not probe for no snapshot and settled the extension dir without putting the tree back; so did the failed-snapshot path of `rebuild`. `build_committed_since` took a marker it could not probe for no marker. Each is an error now. - `back_up_tree_changes` and `note_absent_files` took a backup description that is there and cannot be read for no backup, recorded nothing, and let the build be committed. `try_read_backup_info` fails instead, and the build is undone. The marker and backup formats are as #2108 left them, and `read_marker_strict` and the restore read them unchanged. The contract still said an in-place rebuild leaves a library in the gem's own tree as last built, next to #2108's account of backing it up. That sentence now says what the code does. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Recovery of an interrupted in-place build puts the gem's own tree back from the snapshot beside the parked build, file by file, by path. It runs first on every native apply, gem rollback and hosted refresh, and nothing vouches for a snapshot it finds: a gem home can come from the repository being scanned. A snapshot planted there, naming a file under a link in the gem dir, had that file created or replaced wherever the link points. A snapshot this module takes holds no file under a link, since links are not walked when it is taken. `restore_tree` now checks every path it is about to write for a linked level below the gem dir before it removes or writes anything, and refuses the snapshot when there is one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main gained the vendored unwind's refresh of an install a hosted scan patched (#2113). It reworks the unwind refresh this branch changed, and two files conflicted. Each hunk keeps both sides. crates/socket-patch-cli/src/commands/gem_refresh.rs: - `stale_after_restore` takes main's `installed_with_archives` walk and its `Scope`, and keeps this branch's `Option<sha256>` map: a copy with no upstream sha256 to judge it by is listed whether or not its archive is cached, one with a sha256 is judged by the archive as before. - `after_restore` and main's new `after_vendored_unwind` both run `refresh_restored`, which keeps this branch's handling of `UpstreamArchive` (a refused registry is reported, not dropped) and its one `SecureRegistryClient` per run, with main's rule that a vendored unwind judges only a gem the lock resolves from rubygems.org. A refused lookup only comes back for such a gem, so that rule holds for the unchecked copies too. crates/socket-patch-cli/CLI_CONTRACT.md: - The unwind direction paragraph keeps this branch's account of a copy that could not be checked and ends with main's sentence on a copy left by `--no-gem-install-refresh`. - The `upstream_gem_stale_install` row takes main's vendored unwind columns and keeps this branch's "could not be checked" meaning. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…used registry The vendored unwind (#2113) now runs the same refresh as the hosted one, so it reports an installed copy it could not judge when the lock pins no sha256 and `SOCKET_RUBYGEMS_URL` is refused. An e2e holds that for `rollback`, `remove` and `vendor --revert`: the gem home is unchanged, no registry is asked, and the copy is named with the reason. The contract's paragraph on a vendored unwind says so. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

LLM Description written by Claude Code:claude-fable-5-2
Summary
Follow-up to #2098, which merged before the fixes for its two review-bot
findings were pushed. Both findings are confirmed, and both are closed here:
against, are fetched over https only. Rebuild native gem extensions from the source gem, precompiled gems included #2098 made
applydownload asource gem and run its build script. The checksum came from the same
registry base, and that base (
SOCKET_RUBYGEMS_URL) had no scheme check andthe client followed any redirect, so on plain http someone on the network
could serve both the gem and its checksum.
planted-link guard read any
lstaterror as "not a link".mainis not released with #2098 yet, so nothing shipped with either hole.The change
utils/http.rs: one rule for what may be fetched on this path (https, orplain http to a loopback host, which the hermetic tests and a local mirror
use), one redirect policy (nothing out of https, nothing to a non-loopback
http host, ten hops), and one definition of a loopback host, now shared
with
patch/redirect/grant.rsandupdate/release.rs.vendor/registry_fetch.rsSecureRegistryClient: refuses a URL before anyrequest, carries that redirect policy, and sends a loopback request through
a client that ignores system proxies, so "this machine" cannot leave the
machine through
HTTP_PROXY.patch/gem_source.rs: the source gem, its build dependencies and bothindex reads use it. A refused registry behaves as "no source gem in reach":
a gem RubyGems built falls back to its own tree, a precompiled gem is
refused with nothing written, dry run included.
CHECKSUMSentry andreinstalled the upstream gem through the plain client. It uses the secure
client too, and a copy it could not check is now reported under
upstream_gem_stale_installwith the reason, instead of being passed over.utils/containment.rs: only "not found" reads as nothing there; any otherprobe error names the path. Used for the stage dirs (apply and hosted
refresh), the backup, its marker, the extension dir and the own-source
proof, where a file that could not be probed used to be skipped.
SOCKET_RUBYGEMS_URLare redacted wherever thebase is printed.
CLI_CONTRACT.mdanddocs/ecosystems.mddescribe the rule.What a reviewer should weigh
http://SOCKET_RUBYGEMS_URL, hosted rollback nolonger re-pins or refreshes from that registry; it restores the lock and
reports the installed copy as unchecked.
localhostand loopback IPs.A patch-server grant URL on
http://<name>.localhostis no longer treatedas loopback (nothing makes a resolver answer such a name locally);
--patch-server-urlstill admits such a server.restore_original_buildon a gem dir it cannot read now fails naming thepath, where it used to report "no backup".
Code review
/code-review highraised ten findings on the first two commits; all ten wereconfirmed and fixed here (the proxy bypass for loopback, the swallowed refusal
in
upstream_archive, the backup-info probe, a test that reached DNS, theredirect hop count, the duplicated loopback rule and stage check, unredacted
credentials, a client per URL, and a scheme check that disagreed with the
fetch). Left as is:
rollback_filesstill reads an unreadable backupdescription as none (it cannot signal an error, and the restore that follows
now fails loudly), and the source-gem path still builds its client per gem
copy that actually downloads.
Merge with main
maingained #2108 (in-place rebuild of a gem that builds a library intoits own tree) and #2103 while this was in review, and both touch the same
files. This branch merges
mainand keeps both sides. Two commits thenbring #2108's new code under the same rules as the rest of this PR:
they cannot be read. An unlistable snapshot used to be taken for empty, and
the restore then removed every file of the gem's own tree.
planted snapshot beside a parked build, plus such a link, made recovery
write files outside the gem dir.
Not changed here:
restore_backupandrealign_lib_copies, which predate#2108, still write through a link inside the gem dir. That is its own PR.
Testing
refused, no downgrade), the loopback rule, credential redaction, and the
fail-closed probes (unreadable directories, skipped under root).
HTTP_PROXY/ALL_PROXYset asserts theproxy saw nothing; a plain-http registry refuses a precompiled gem and
sends a built one to its own tree; rollback reports the copy a refused
registry left unchecked.
e2e_gem_native_ext_build30,e2e_redirect_gem_stale_install32,in_process_rollback_hosted41,e2e_redirect_gem_build43,e2e_vendor_gem_build14,e2e_gem6 (with--include-ignored);upstream_restore_golden62.applyrebuilds in 34 s, 6 to 7 libxml2 patches,apply --checkin sync,vexnot_affected, rollback byte-identical. WithSOCKET_RUBYGEMS_URL=http://user:secret@rubygems.orgit is refused, nothingis written, and the credential does not appear in the output.
Not verified locally: Linux and Windows.
🤖 Generated with Claude Code