You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 762cec2
Browse filesBrowse the repository at this point in the historyBrowse files
Let a patch fix a package's file permissions in agent mode (#2433)
* Let a patch fix a package's file permissions in agent mode
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>
* Count a file under an unreadable mode as a content match for a wheel'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>
* Say how an unreadable file mode is reported, and what a hosted copy does under one
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* Read a file mode for in-place copies only, and refuse an unreadable one 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>
* Give the reinstall that a warm hosted gem install needs, not bundle pristine
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>
* Keep file verification off the stack, and judge every delivered copy 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>
* Test that a conda build is never written to for a file mode
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>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: crates/socket-patch-cli/CLI_CONTRACT.md
+71-3Lines changed: 71 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -156,6 +156,72 @@ explicit consent for file drift and additionally skips missing files, but a
156
156
is not a merge: the replaced local content is not kept for rollback.
157
157
Vendoring commits the service artifact without merging installed changes.
158
158
159
+
**File permissions as part of a patch.** A file entry of a patch record may
160
+
carry a `mode`: `0` and three octal digits (`"0644"`, `"0755"`), the file's
161
+
permission bits in the patched package. It marks a fix that includes the
162
+
file's permissions, and such an entry may leave the content as it is
163
+
(`beforeHash` equal to `afterHash`): a release that shipped its files
164
+
world-writable is fixed by the bits alone. Entries without a `mode`, which is
165
+
every entry of a patch that fixes content only, are handled exactly as before.
166
+
167
+
- The mode is an upper bound on write bits, never a mode to set. A file is
168
+
patched when its content hashes to `afterHash` **and** it has no group-write
169
+
or other-write bit the mode lacks. Read, execute, owner-write, setuid,
170
+
setgid and sticky bits are never looked at or changed, so a read-only
171
+
(`0444`) or owner-only (`0600`) copy satisfies `"0644"` as it is.
172
+
- `apply` (and the apply step of agent-mode `get` / `scan`) clears exactly the
173
+
excess bits, through the same stage and rename as a content change: a file
174
+
that is hard-linked into a store keeps its other links untouched. A file
175
+
that already holds the patched bytes is replaced with the bytes it holds; it
176
+
is reported in `files` with `appliedVia: "permissions"`, and that write
177
+
reads no blob. (The record's blobs are still expected like any other
178
+
record's: an `--offline` run without them stops before it applies.)
179
+
- The mode is read only for a copy that is patched where it is installed
180
+
(agent mode). `apply --check` and `vex` judge such a copy by the same rule
181
+
as `apply`: a file with the patched bytes and an excess write bit is not
182
+
applied yet. An entry that fixes a file's permissions alone is no build
183
+
input of a native gem, so it never starts a rebuild, and a gem copy that
184
+
does not hold that entry's file takes the record without it.
185
+
- Hosted and vendored copies are judged by their content alone, exactly as
186
+
before, whatever `mode` their entries have: a committed vendored artifact,
187
+
its installed copies, a hosted install and the stale-install checks. Their
188
+
files come from the patched archive, which gives every file `0644` or
189
+
`0755`, and the bits an installer or a git checkout leaves on them follow
190
+
the umask. The same holds for two copies `apply` itself handles: a local
191
+
Go patch copy under `.socket/go-patches/`, which this tool writes and the
192
+
project commits, and a copy conda built, whose bits are conda's and not
193
+
the PyPI release's. Both are written and judged without the `mode`. One consequence: an install made from the upstream release
194
+
before a permissions-only patch was pinned holds the patched content, so
195
+
the hosted stale-install check does not see it and it keeps its modes
196
+
until it is installed again from the patched archive. For a gem that
197
+
means removing the installed gem's `specifications` entry and its cached
198
+
`.gem` and running `bundle install`, as the "Gem stale-install guard"
199
+
section describes for any stale copy; `bundle pristine` reinstalls from
200
+
the cached upstream archive and does not help.
201
+
- `rollback` and `remove` restore content only. They never give back a write
202
+
bit a patch cleared, so a rolled-back file keeps the tightened mode, and an
203
+
entry whose content the patch did not change has nothing to restore.
204
+
- Off Unix a file has no such bits and a `mode` changes nothing.
205
+
- A `mode` in any other spelling, or any other JSON value, is one this release
206
+
cannot read. It fails only the patch it belongs to. The manifest (or the
207
+
API response) still loads, every other patch works as before, and the value
208
+
is written back exactly as it was read. A file with such an entry cannot be
209
+
checked, so its patch is never reported as applied: `apply` fails it
210
+
(`errorCode: apply_failed`, `cause: unreadable_file_mode`) before writing
211
+
any of its files, under `--force` as well, and `apply --check` and `vex`
212
+
report `unreadable_file_mode` for it. `rollback`, `remove`, and hosted and
213
+
vendored use of the patch do not read the `mode` and work as for any other
214
+
patch.
215
+
- A release that predates `mode` ignores it and reads an entry with unchanged
216
+
content as already patched. The patch service therefore sends such entries
217
+
only to a client that names the `file-modes` capability (see
218
+
[API client construction](#api-client-construction)). That does not cover a
219
+
manifest shared with an older release: any of its commands that saves the
220
+
manifest writes every entry back without its `mode`, and the record then
221
+
reads as applied to every release, this one included, until it is removed
222
+
and downloaded again. A project whose manifest holds a `mode` must not be
223
+
driven by a release that predates it.
224
+
159
225
## Existing project patches
160
226
161
227
**Release classification: fix (shipped in 5.1.0).** This tightens the default
@@ -2401,6 +2467,8 @@ Building the API client is what reads the token, prints the client's stderr advi
2401
2467
2402
2468
Telemetry does not build it: see [Telemetry](#telemetry) for the route a client-less run reports on.
2403
2469
2470
+
Every patch request (`view`, `by-package`, `by-cve`, `by-ghsa`, `batch`, `package`, on the org API and the public proxy alike) carries the query parameter `capabilities`, a comma-separated list of what this release reads in a patch record beyond its file hashes. Its one value so far is `file-modes` (a file entry may carry a `mode`; see "File permissions as part of a patch"). A service that does not know the parameter ignores it.
2471
+
2404
2472
### Registry override env vars
2405
2473
2406
2474
Env-only knobs used for hosted upstream restoration and JVM metadata verification. They do not enable local artifact construction. Trailing slashes are trimmed and empty values use the default.
@@ -2509,7 +2577,7 @@ command's integration tests check its output.
2509
2577
{
2510
2578
"path": "package/index.js",
2511
2579
"verified": true,
2512
-
"appliedVia": "blob" // only on action=applied; v5.0 drops "package" and "diff"
2580
+
"appliedVia": "blob" | "permissions" // only on action=applied; v5.0 drops "package" and "diff". "permissions": the file held the patched bytes and lost the write bits its entry's `mode` does not grant
2513
2581
}
2514
2582
],
2515
2583
"bytes": 1234, // only on the GC carrier event and --update's downloaded
@@ -2633,8 +2701,8 @@ command's integration tests check its output.
2633
2701
| `vendor_unwired` | `skipped` | vex: a vendor-ledger entry whose committed artifact no lockfile/config wires any more (reverted lock, leftover ledger or artifact). Applies under `--no-verify` too. |
2634
2702
| `redirect_unwired` | `skipped` | vex: a hosted record (this run's, or a pre-v5 redirect ledger's) whose hosted patch no lockfile wires any more (and no manifest entry owns the purl). Applies under `--no-verify` too. |
2635
2703
| `wiring_conflict` | `skipped` | vex (manifest-less): the lockfiles wire one package to two or more different patches (e.g. a stale sibling lock); which one the build installs is undecidable, so none is attested. |
2636
-
| `hash_mismatch` / `not_applied` / `file_not_found` / `package_not_found` / `no_files` / `vendor_*` | `skipped` | vex: verification omissions — the installed copy (agent / hosted) or the committed artifact (`vendor_hash_mismatch`, `vendor_artifact_missing`, `vendor_artifact_unreadable`, `vendor_artifact_too_large`, `vendor_artifact_non_canonical`, `vendor_inventory_mismatch`, `vendor_uuid_mismatch`, `vendor_path_unsafe`) does not carry the patched bytes, or nothing is installed. `vendor_artifact_too_large` (jars): the committed jar is past the limits jars are read within (see [Vendored JVM support](#vendored-jvm-support-v5)), so its contents were not checked (`vendor --check` reports it as a corrupt artifact that `repair` restores from the recorded jar). `vendor_artifact_non_canonical`: a committed npm tarball holds a second entry the installers would extract over one of the patch's files — the same path under another top-level directory, a second or case-variant spelling of the name, a link, or a non-directory where one of the file's parent directories must be. npm-family installers strip the first path segment whatever it is, extract links as well as files and let a later entry overwrite an earlier one, so such a tarball can hold the patched file where it is checked and install the original (`vendor --check` reports it as a corrupt artifact that `repair` restores). Only the patch's own files are judged: an upstream tarball with a link, a non-ASCII name or a case twin elsewhere, which vendoring accepts, keeps verifying. `vendor_lock_pin_mismatch` (bun): the artifact holds the patch, but the `bun.lock` tuple or `bun.lockb` record that resolves to it carries a digest that is not the tarball's sha512 (a pin under any other algorithm is not one vendoring wrote), so an install does not deliver it — Bun 1.3.10+ fails the integrity check on a cold cache, and Bun 1.4 keys its tarball cache by that digest and installs whatever cached tarball has it. `vendor --check` reports the same as a wiring failure (exit 1) with the remedy, re-running `scan --mode vendored`, which rewrites the pin. A tuple without a digest (the 2-tuple Bun 1.1.39 to 1.3.9 re-save) has no pin to be wrong. `vendor_manifest_unverifiable`: a vendored vlt directory verified without its vendor ledger (from `vlt-lock.json` alone) holds a `package.json` with its devDependencies stripped, and the patched `package.json` blob is not in `.socket/blobs`, so it cannot be checked. A lockfile-pinned hosted reference with nothing installed attests instead of `package_not_found` (see "Manifest-less VEX"). |
2637
-
| `not_applied` / `hash_mismatch` / `file_not_found` / `no_matching_variant` | `failed` | `apply --check` (v5.0): an installed copy of the patch does not verify (still unpatched; neither the original nor the patched bytes; a patched file missing; a copy of a release-variant base that holds none of the manifest's variants, keyed by the base purl). Exit 1, status `partialFailure`. The `no_matching_variant` reason says that `apply` leaves such a copy as it is, and for a gem names `bundle pristine <gem>` and the `apply` to run after it. |
2704
+
| `hash_mismatch` / `not_applied` / `file_not_found` / `unreadable_file_mode` / `package_not_found` / `no_files` / `vendor_*` | `skipped` | vex: verification omissions — the installed copy (agent / hosted) or the committed artifact (`vendor_hash_mismatch`, `vendor_artifact_missing`, `vendor_artifact_unreadable`, `vendor_artifact_too_large`, `vendor_artifact_non_canonical`, `vendor_inventory_mismatch`, `vendor_uuid_mismatch`, `vendor_path_unsafe`) does not carry the patched bytes, or nothing is installed. `vendor_artifact_too_large` (jars): the committed jar is past the limits jars are read within (see [Vendored JVM support](#vendored-jvm-support-v5)), so its contents were not checked (`vendor --check` reports it as a corrupt artifact that `repair` restores from the recorded jar). `vendor_artifact_non_canonical`: a committed npm tarball holds a second entry the installers would extract over one of the patch's files — the same path under another top-level directory, a second or case-variant spelling of the name, a link, or a non-directory where one of the file's parent directories must be. npm-family installers strip the first path segment whatever it is, extract links as well as files and let a later entry overwrite an earlier one, so such a tarball can hold the patched file where it is checked and install the original (`vendor --check` reports it as a corrupt artifact that `repair` restores). Only the patch's own files are judged: an upstream tarball with a link, a non-ASCII name or a case twin elsewhere, which vendoring accepts, keeps verifying. `vendor_lock_pin_mismatch` (bun): the artifact holds the patch, but the `bun.lock` tuple or `bun.lockb` record that resolves to it carries a digest that is not the tarball's sha512 (a pin under any other algorithm is not one vendoring wrote), so an install does not deliver it — Bun 1.3.10+ fails the integrity check on a cold cache, and Bun 1.4 keys its tarball cache by that digest and installs whatever cached tarball has it. `vendor --check` reports the same as a wiring failure (exit 1) with the remedy, re-running `scan --mode vendored`, which rewrites the pin. A tuple without a digest (the 2-tuple Bun 1.1.39 to 1.3.9 re-save) has no pin to be wrong. `vendor_manifest_unverifiable`: a vendored vlt directory verified without its vendor ledger (from `vlt-lock.json` alone) holds a `package.json` with its devDependencies stripped, and the patched `package.json` blob is not in `.socket/blobs`, so it cannot be checked. A lockfile-pinned hosted reference with nothing installed attests instead of `package_not_found` (see "Manifest-less VEX"). |
2705
+
| `not_applied` / `hash_mismatch` / `file_not_found` / `no_matching_variant` / `unreadable_file_mode` | `failed` | `apply --check` (v5.0): an installed copy of the patch does not verify (still unpatched; neither the original nor the patched bytes; a patched file missing; a copy of a release-variant base that holds none of the manifest's variants, keyed by the base purl; a file entry whose `mode` this release cannot read, see "File permissions as part of a patch"). Exit 1, status `partialFailure`. The `no_matching_variant` reason says that `apply` leaves such a copy as it is, and for a gem names `bundle pristine <gem>` and the `apply` to run after it. |
2638
2706
| `no_matching_variant` | `failed` | apply, and the apply that `get` / `scan --mode agent` run (gem, PyPI): an installed copy of a release-variant base (a base whose manifest records are qualified, or a gem build beside another build of its version) whose files match none of the manifest's records for it and which holds one of the patch's files with other content: an edited copy, or another build of the version. (A copy that holds none of the files its records are matched by is not told to belong to them: they stay `package_not_installed`, and the run still exits 1.) Keyed by the base purl, one event per copy. The copy is left as it is and the run exits 1 (`partialFailure`). `error` names the copy and the file that holds neither side of a record; for a gem it adds `bundle pristine <gem>` (or `gem pristine <gem>`), which restores an edited copy to the published gem. The copy is installed, so no record of the base is `package_not_installed` in that run. |
2639
2707
| `redirect_unconfirmed` | `skipped` (`details.mode: "hosted"`) | hosted `scan` / `get` (v5.0, additive): the patch was granted but no lockfile entry pinning it could be rewritten. The status and exit code are unchanged for now, pending the open hosted exit-policy decision (#704); `--silent` hides the human line. |
2640
2708
| `lockfile_unreadable` / `lockfile_unparseable` / `patched_ref_invalid` / `patched_ref_unattributable` | run-level `warnings[]` | vex (every form): lockfile-discovery diagnostics — see "Manifest-less VEX (lockfile discovery)". Never flip the exit on their own. |
0 commit comments