Repository navigation
Let a patch fix a package's file permissions in agent mode - #2433
Conversation
A release can ship its files world-writable and be fixed by a repack with the same content (octopoller 0.2.0, GHSA-26qj-cr27-r5c4). Hosted and vendored installs already get the patched archive's modes. An in-place apply kept the installer's mode bit for bit, and a fix with no content change could not be recorded at all. A file entry of a patch record may now carry `mode` ("0644", "0755"), also when its content is unchanged (`beforeHash` equal to `afterHash`): - The mode is an upper bound on write bits. A file is patched when its content hashes to `afterHash` and it has no group-write or other-write bit the mode lacks. Nothing else of the file's mode is read or changed. - `apply` clears exactly those bits through the usual stage and rename, and reports the file with `appliedVia: "permissions"`. It needs no blob for a file that already holds the patched bytes. - `apply --check`, `vex` and the hosted stale-install check judge an installed copy by the same rule. A committed vendored artifact is judged by its content alone, as before. - `rollback` and `remove` restore content only and keep the tightened mode. - A `mode` in a spelling this release cannot read fails only its own patch (`unreadable_file_mode`): the manifest still loads, every other patch works, and the value is written back as it was read. Records without a `mode` behave exactly as before, and their manifests serialize byte for byte as before. Patch requests now carry `capabilities=file-modes`, so the patch service can keep such entries from releases that would read unchanged content as "already patched". A service that does not know the parameter ignores it. Needs a matching change in Socket's backend before any patch carries a mode. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…en-modes # Conflicts: # crates/socket-patch-cli/src/commands/agent_download.rs
…s record The wheel matcher added on main tells a record of another artifact from the installed copy's by content. A file whose entry has a mode this release cannot read holds content the entry describes, so it does not tell the two apart; applying the record reports the mode. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…oes under one Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ne before any policy Review fixes: - A record with a file mode this release cannot read is refused before any file is verified, in the file engine, the jar swap and the gem apply. A tolerant mismatch policy could otherwise write a file that holds neither side of its entry and report the patch as applied. - Hosted and vendored copies are judged by their content alone again, as on main: a vendored artifact and its installed copies, hosted installs, the stale-install checks, the unwinding of a hosted gem and a compiled conda build. Their bits follow the installer's umask or a git checkout, so reading the mode there reported copies as stale that no reinstall changes. `vex` and `apply --check` read the mode for a copy patched in place. - An entry that fixes a file's permissions alone is no native build input of a gem. - Inside a grouped run a change that must clear bits is refused instead of renaming the file while it is being staged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview Core adds Reviewed by Cursor Bugbot for commit 4be5b2a. Configure here. |
…ristine The cached archive of such an install is the upstream one, so `bundle pristine` brings the same files back. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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 4be5b2a. Configure here.
…by content CI: the coverage build overflowed a 2 MiB test thread in the in-process gem suite. The mode check had added an async layer and two call sites to the verify and apply paths, which sit under the deepest commands. File verification is now main's content check plus a separate mode step, both handed out as boxed futures, and the permissions-only write is one boxed call. The suite's deepest tests need about 1.4 MiB here, against 1.9 MiB on main. Review of the previous fixes: - A record with an unreadable mode is refused as a whole by `vex` and `apply --check` too, and a Maven record is no longer split across Gradle hash dirs when it has one, so no part of it is written. - A package wired to a hosted patch is judged by content wherever its copies are found (Composer and NuGet have no consumed-copy list), and so are a copy conda built and a local Go patch copy, which are also written without the mode. - A gem copy that lacks the file of a permissions-only entry takes the record without it, instead of failing on a missing build input. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A compiled conda build that holds a permissions-only record's content is reported as patched and left as it is, loose bits included; a record that changes content is still refused. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Resolve the conflict with main's file-mode support (#2433) and its boxed engine futures (#2432): - keep one `boxed` helper, main's (both sides added the same function); - thread main's new `mode` argument of `stage_write` through this branch's shared `stage`; the optional RECORD write passes `None`, so it clears no permission bits; - compute the sidecar fixup files once, before the RECORD plan, as this branch does, reading main's `(file, AppliedVia)` entries of `written`; - give this branch's tests the new `mode` field and argument. Assisted-by: Claude Code:claude-opus-5-5

The problem
A release can be vulnerable through its file permissions alone.
octopoller0.2.0 (GHSA-26qj-cr27-r5c4) shipped its files world-writable (0666), so any local user can editlib/octopoller.rband have the next app that loads it run their code. The fix, 0.3.0, is the same code repacked as0644.That fix could not be delivered in agent mode:
applywrites a file's content and keeps its mode bit for bit.A fresh hosted or vendored install is not affected: the patched archive already gives every file
0644or0755, and the vendored extraction does the same. (An install made before the patch was pinned is; see "Not in this PR".)The change
A file entry of a patch record may carry a
mode("0644","0755"). It may do so when its content is unchanged (beforeHashequal toafterHash), which is how a permissions-only fix is recorded.afterHashand it has no group-write or other-write bit the mode lacks. Read, execute, owner, setuid, setgid and sticky bits are never read or changed.applyclears exactly those bits, through the same stage and rename as a content change, so a file hard-linked into a store is replaced and its other links are untouched. A file that already holds the patched bytes is reported withappliedVia: "permissions".apply --checkandvexjudge a copy patched in place by the same rule: patched bytes under an excess write bit are not applied yet.modetheir entries have. Their files come from the patched archive, and the bits an installer or a git checkout leaves on them follow the umask. The same holds for a local Go patch copy under.socket/go-patches/and for a copy conda built: both are written and judged without themode.rollbackandremoverestore content only. They never give back a write bit a patch cleared.modechanges nothing.On a real install of
octopoller0.2.0 (old system Bundler, files at0666/0777), with a record whose 22 entries have unchanged content and a mode:Afterwards the files are
0644/0755and none is group- or world-writable.vexattests the advisory only then.Backward compatibility
Records without a
modebehave exactly as before. That includes an entry whose content is unchanged and has no mode, which stays "already patched" as it is today.I ran the same commands with a build of
mainand a build of this branch on two identical projects whose manifests have nomode:apply --check,apply,applyagain,list,vex, aremoveof another record (which saves the manifest) androllback;octopollerinstall above with a record of 22 unchanged-content entries and nomode, its files at0666:apply --check,apply,vexandrollback.Every stdout (the
--jsonenvelopes), stderr and exit code is the same, and so are the manifest bytes after the apply, after the save and after the rollback, and the modes of the installed files: 44 files compared, 43 identical. The one difference is the random@idand the timestamps of a VEX document. The second project reads as "already patched" and keeps0666under both builds, as it does today.A
modethis release cannot read fails only its own patch. Any spelling other than0and three octal digits, or any other JSON value, still loads: the manifest and the API response parse, every other patch works, and the value is written back exactly as it was read. The patch it belongs to is never reported as applied.applyfails it (errorCode: apply_failed,cause: unreadable_file_mode) before writing any of its files, under--forcetoo.apply --checkandvexreportunreadable_file_modefor it.rollback,remove, and hosted and vendored use do not read the mode and work as usual.One request parameter is new. Every request to a JSON patch endpoint carries
capabilities=file-modes. A service that does not know the parameter ignores it. I checked that against the live service with this build:by-package,view,batchandpackageall answered as before, on the public proxy and on the authenticated org API, and an agent-mode and a vendoredscancompleted. No URL with the parameter is written to a lockfile or a ledger or compared with a stored URL, and artifact URLs (what a patch mirror is asked for) do not carry it.Rust API.
PatchFileInfogains the public fieldmodeandVerifyStatusthe variantUnreadableMode: a source break for code that builds aPatchFileInfoby hand or matchesVerifyStatusexhaustively. The JSON forms only gain an optional key.Older releases and a shared manifest. A release that predates
modeignores it and reads an entry with unchanged content as already patched. The parameter above lets the patch service keep such entries from those releases. It cannot cover a manifest shared with one: any of its commands that saves the manifest writes every entry back without itsmode, and the record then reads as applied to every release, this one included, until it is removed and downloaded again.CLI_CONTRACT.mdsays so.Not in this PR
mode. Until then nothing sends one, and this change is inert apart from the request parameter. The service must answer by the parameter everywhere, cached views included: a view cached for a release that named the capability must not be served to one that did not.specificationsentry and cached.gemand runningbundle install, as the stale-install guard describes (bundle pristinereinstalls from the cached upstream archive). Reading the mode in the hosted gem check would close this; an earlier revision of this branch did, and the review below found it reported copies as stale that no reinstall changes, so it is left for a change that can be tested against a real hosted install.Review
/code-review highreported ten findings, none about records without amode. Fixed:--force, and the default for content an earlier Socket patch wrote) could write a file of a record whose mode cannot be read, and report it as applied. Such a record is now refused before any file is verified, in the file engine, the jar swap and the gem apply.ext/put the patch on the native rebuild path.A second
/code-review high, of those fixes alone, reported six more, again all about records with amode. Fixed:vexandapply --checkrefuse a record with an unreadable mode as a whole, asapplydoes, and a Maven record with one is not split across Gradle hash directories, so no part of it is written.Bugbot's one finding (a compiled conda build could be written to for a mode) is the conda item above; its thread has the fix and a test.
Not changed:
--offlinerun still stops when the record's blobs are missing, like for any record. The contract now says so. Skipping the preflight for such entries would also skip it for an entry whose file holds other content and does need the blob.Testing
cargo test --workspace --locked --no-fail-faston the fixes, before the last merge ofmain: 15,522 passed, 531 ignored, 2 failed. The two failures aree2e_vendor_cargo_build's old-toolchain tests, which cannot start on this machine (launching the oldcargofails withBad CPU type in executable) and do not touch this change. After merging the one commitmaingained since, the core library tests (8,849) and the CLI's unit,apply,get,scanand in-process gem suites pass.cargo clippy --locked --workspace --all-features -- -D warningsandcargo fmt --all -- --checkare clean. The npm schema tests pass (11 of 11).ci.yml,os=windows). All 24 of its jobs passed, both Windows test shards included.in_process_gem_multi_platformunder the coverage build (and the aggregate check). The mode check had deepened the async call chain of every command that verifies a file. File verification is nowmain's content check plus a separate mode step, both behind boxed futures; the deepest tests of that suite pass with a 1.4 to 1.5 MiB thread stack here, wheremainneeds 1.9 MiB.pnpm hosted compatibilityfails onmainas well (pnpm 11.0.0; Keep a vendored pnpm patch when pnpm 11.0.0 to 11.0.2 rewrite its lock entry without the tarball #2434 fixes it), and the Windows nokogiri job timed out downloading libiconv during its native build.patch/apply_file_mode_tests.rs(20 tests: bits cleared and nothing else, hard-linked copies, dry run, rollback, content plus mode in one write, an unreadable mode under every mismatch policy), the manifest and API round-trips of a mode in any spelling,vexin place against content-only and hosted-wired copies, the vendored artifact check, and the native-gem classification and record narrowing.octopollerinstall above; a two-patch project where one record has"mode": "644"and another"mode": 420(the other patch applies, the affected files are untouched, exit 1, also under--force;apply --checkandvexname the unreadable mode; a manifest save writes both values back as they were;rollbackworks); the before/after comparison againstmain; and the live-service requests.mode, and a conda build or a local Go patch copy with one (those two take the record without its modes, which has a unit test).🤖 Generated with Claude Code