Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 71 additions & 3 deletions crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,72 @@ explicit consent for file drift and additionally skips missing files, but a
is not a merge: the replaced local content is not kept for rollback.
Vendoring commits the service artifact without merging installed changes.

**File permissions as part of a patch.** A file entry of a patch record may
carry a `mode`: `0` and three octal digits (`"0644"`, `"0755"`), the file's
permission bits in the patched package. It marks a fix that includes the
file's permissions, and such an entry may leave the content as it is
(`beforeHash` equal to `afterHash`): a release that shipped its files
world-writable is fixed by the bits alone. Entries without a `mode`, which is
every entry of a patch that fixes content only, are handled exactly as before.

- The mode is an upper bound on write bits, never a mode to set. A file is
patched when its content hashes to `afterHash` **and** it has no group-write
or other-write bit the mode lacks. Read, execute, owner-write, setuid,
setgid and sticky bits are never looked at or changed, so a read-only
(`0444`) or owner-only (`0600`) copy satisfies `"0644"` as it is.
- `apply` (and the apply step of agent-mode `get` / `scan`) clears exactly the
excess bits, through the same stage and rename as a content change: a file
that is hard-linked into a store keeps its other links untouched. A file
that already holds the patched bytes is replaced with the bytes it holds; it
is reported in `files` with `appliedVia: "permissions"`, and that write
reads no blob. (The record's blobs are still expected like any other
record's: an `--offline` run without them stops before it applies.)
- The mode is read only for a copy that is patched where it is installed
(agent mode). `apply --check` and `vex` judge such a copy by the same rule
as `apply`: a file with the patched bytes and an excess write bit is not
applied yet. An entry that fixes a file's permissions alone is no build
input of a native gem, so it never starts a rebuild, and a gem copy that
does not hold that entry's file takes the record without it.
- Hosted and vendored copies are judged by their content alone, exactly as
before, whatever `mode` their entries have: a committed vendored artifact,
its installed copies, a hosted install and the stale-install checks. Their
files come from the patched archive, which gives every file `0644` or
`0755`, and the bits an installer or a git checkout leaves on them follow
the umask. The same holds for two copies `apply` itself handles: a local
Go patch copy under `.socket/go-patches/`, which this tool writes and the
project commits, and a copy conda built, whose bits are conda's and not
the PyPI release's. Both are written and judged without the `mode`. One consequence: an install made from the upstream release
before a permissions-only patch was pinned holds the patched content, so
the hosted stale-install check does not see it and it keeps its modes
until it is installed again from the patched archive. For a gem that
means removing the installed gem's `specifications` entry and its cached
`.gem` and running `bundle install`, as the "Gem stale-install guard"
section describes for any stale copy; `bundle pristine` reinstalls from
the cached upstream archive and does not help.
- `rollback` and `remove` restore content only. They never give back a write
bit a patch cleared, so a rolled-back file keeps the tightened mode, and an
entry whose content the patch did not change has nothing to restore.
- Off Unix a file has no such bits and a `mode` changes nothing.
- A `mode` in any other spelling, or any other JSON value, is one this release
cannot read. It fails only the patch it belongs to. The manifest (or the
API response) still loads, every other patch works as before, and the value
is written back exactly as it was read. A file with such an entry cannot be
checked, so its patch is never reported as applied: `apply` fails it
(`errorCode: apply_failed`, `cause: unreadable_file_mode`) before writing
any of its files, under `--force` as well, and `apply --check` and `vex`
report `unreadable_file_mode` for it. `rollback`, `remove`, and hosted and
vendored use of the patch do not read the `mode` and work as for any other
patch.
- A release that predates `mode` ignores it and reads an entry with unchanged
content as already patched. The patch service therefore sends such entries
only to a client that names the `file-modes` capability (see
[API client construction](#api-client-construction)). That does not cover a
manifest shared with an older release: any of its commands that saves the
manifest writes every entry back without its `mode`, and the record then
reads as applied to every release, this one included, until it is removed
and downloaded again. A project whose manifest holds a `mode` must not be
driven by a release that predates it.

## Existing project patches

**Release classification: fix (shipped in 5.1.0).** This tightens the default
Expand Down Expand Up @@ -2401,6 +2467,8 @@ Building the API client is what reads the token, prints the client's stderr advi

Telemetry does not build it: see [Telemetry](#telemetry) for the route a client-less run reports on.

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.

### Registry override env vars

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.
Expand Down Expand Up @@ -2509,7 +2577,7 @@ command's integration tests check its output.
{
"path": "package/index.js",
"verified": true,
"appliedVia": "blob" // only on action=applied; v5.0 drops "package" and "diff"
"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
}
],
"bytes": 1234, // only on the GC carrier event and --update's downloaded
Expand Down Expand Up @@ -2633,8 +2701,8 @@ command's integration tests check its output.
| `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. |
| `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. |
| `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. |
| `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"). |
| `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. |
| `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"). |
| `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. |
| `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. |
| `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. |
| `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. |
Expand Down
Loading
Loading