Repository navigation
Add an experimental patch mirror for hosted mode behind an internal artifact host - #2180
Conversation
PR SummaryMedium Risk Overview
Additive for all hosted runs: pins on hosts the run does not know ( Reviewed by Cursor Bugbot for commit 51d6242. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ 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 51d6242. Configure here.
51d6242 to
802b277
Compare
…rtifact host Hosted mode pins each patched dependency to a URL on Socket's patch server. A build that may only download from an internal artifact host cannot fetch from there. This adds an experimental setting that names a mirror of the patch server (a caching proxy, such as an Artifactory generic remote repository). Hosted mode then writes its pins under that base, with the same path and the same integrity. The setting is SOCKET_PATCH_MIRROR_URL, or the flag --patch-mirror-url, which is hidden from --help. It is for Socket Enterprise customers and is outside the semver policy while it is experimental. A repository file cannot set it. With the setting: - scan and get in hosted mode move each granted reference onto the mirror. A Go reference is untouched (its pin is a module path). Cargo and NuGet are skipped with redirect_mirror_unsupported, because their index names the patch server's own download URLs. - Before a new mirrored pin is written, the run sends one HEAD for it and follows no redirect. 2xx pins. 401, 403, 407 or a redirect pins with a redirect_mirror_unverified warning. Anything else skips that pin with redirect_mirror_unavailable. SOCKET_PATCH_MIRROR_AUTHORIZATION (env only) authenticates the check and is scrubbed from child processes. - The run's own downloads still read the patch server. - list, vex, rollback, remove, vendor and repair read a pin on the mirror's origin as a hosted patch. - yarn berry, Bun, Bundler, Poetry and PDM cannot move a pin that is already on the patch server in place. They warn redirect_mirror_pin_not_moved and name the remedy. For every hosted run, mirror or not: a pin of the same patch on a host the run was not given is left alone (redirect_pin_on_unconfigured_host), on disk and in the in-memory engine. A run without the setting never moves a mirrored pin back onto the patch server. Without the setting nothing else changes. Tests: unit tests for the base parser, the candidate rewrite and the guard. tests/patch_mirror.rs (hermetic) covers what a live mirror cannot show. tests/e2e_artifactory_mirror.rs (ignored, live) pins a free patch through a real Artifactory and installs it with npm, pnpm, yarn classic, yarn berry, pip, uv and Bundler. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- A mirror is matched by its base, not its host. An allowlist entry for a mirror (`mirror+<base>`) holds only the URLs at or below the base, so a URL in another repository of the mirror's host is not a hosted pin for list, vex, rollback or the unknown-host guard. A --patch-server-url entry still holds its whole origin. - The yarn berry, Bun, Poetry and PDM rewriters take over an earlier pin under a mirror only when it sits under the mirror's base. A fork of the same name and version elsewhere on that host stays the project's own source. - With a mirror, the patch server is always the first origin, so an upstream restore (the yarn berry checksum) never asks the mirror. - The unknown-host guard reads a composer.lock with escaped slashes as the URL it is. A project pinned on the patch server that way was skipped as pinned on a host called "https". - The mirror check stops at the first request that gets no answer and withholds the pins it has not asked about, instead of waiting out the timeout for each one. It builds one HTTP client for the run. - A pin the mirror refused stays withheld when a later request is answered 401, 403, 407 or a redirect; the warning says so. - A re-run does not ask the mirror again about a pin a composer.lock holds with escaped slashes. - apply ignores a mirror base it cannot use instead of exiting 2: it does not use the mirror and runs unattended from install hooks. - The Cargo and NuGet skip no longer says the package stays unpatched. - The live suite's yarn berry and Bundler legs no longer depend on CI defaults (immutable installs, lockfile checksums before Bundler 4). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The test landed on main while this branch changed the function it calls. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two repository hygiene tests failed in CI: - The two new test files defined their own `warning_codes`. They read the envelope through `common/envelope.rs` now. - `vlt_heal` imported `hosted_unwind`, which imports it. It builds its own origin list again, with the mirror listed as a mirror's base. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… yarn berry Review feedback on the check that an earlier pin sits under the mirror's base before a rewriter takes it over: - It compared text, so `<base>/../other/x` passed as a URL under the base. It now reads both URLs as a client does: the earlier pin in any spelling a lock uses, with `.` and `..` segments resolved. - Poetry and PDM had a test for it. Bun and yarn berry call the same check and had none; they have one now. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2789899 to
746c477
Compare

What this adds
Hosted mode pins each patched dependency to a URL on Socket's patch server. A build that may only download from an internal artifact host cannot fetch from there.
This adds an experimental setting that names a mirror of the patch server: a caching proxy, such as an Artifactory generic remote repository, that serves
https://patch.socket.dev/<path>at<base>/<path>. Hosted mode then writes its pins under that base, with the same path and the same integrity.The setting is
SOCKET_PATCH_MIRROR_URL, or the flag--patch-mirror-url, which is hidden from--help. It is for Socket Enterprise customers. The contract marks the flag, its variables and itsredirect_mirror_*codes Experimental and outside the semver policy. A repository file cannot set it (thesocket.ymltrust boundary).With the setting
scanandgetin hosted mode move each granted reference onto the mirror. A Go reference is untouched: its pin is a module path. Cargo and NuGet are skipped withredirect_mirror_unsupported, because their index names the patch server's own download URLs.HEADfor it and follows no redirect.redirect_mirror_unverifiedwarning.redirect_mirror_unavailableand its files stay byte-identical.SOCKET_PATCH_MIRROR_AUTHORIZATION(environment only) authenticates that check. It goes nowhere else and is scrubbed from child processes.list,vex,rollback,remove,vendorandrepairread a pin under the mirror's base as a hosted patch. A URL elsewhere on the mirror's host, in another repository of it, is not one.redirect_mirror_pin_not_movedand name the remedy (rollback, then run again).For every hosted run, mirror or not
A pin of the same patch on a host the run was not given is left alone:
redirect_pin_on_unconfigured_host, on disk and in the in-memory engine. So a run without the setting never moves a mirrored pin back onto the patch server. This is the one behavior change for users who do not set the mirror, and it is additive.Without the setting nothing else changes.
Compatibility
The CLI needs nothing new from the Socket API or the patch server: the live suite below runs against production as it is.
Testing
tests/patch_mirror.rs(hermetic, 5 tests): what a live mirror cannot show, such as each answer to the check and where the credential goes.tests/e2e_artifactory_mirror.rs(#[ignore], live): pins a free patch through a real Artifactory and installs it from cold caches with npm, pnpm, yarn classic, yarn berry, pip, uv and Bundler. It also covers the mirror check,list,vexandrollback. Run locally against Artifactory OSS 7.161 on the head commit: 8 passed. It also passed in CI on Linux against a fresh Artifactory OSS container, with pnpm 10 and Bundler 2.6. This repository's CI only compiles it; Socket runs it against a real Artifactory outside this repository.cargo check --all-targets --all-featuresclean, and 0 failures across the core unit tests (8,351), the CLI unit tests (1,029), the upstream-restore tests (64) and 86 CLI suites (hosted, redirect, rollback, get, parse, contract, help and environment hygiene).Code review
/code-review highreported nine findings. Eight are fixed in the second commit, each with a test where one could be written (the unreachable-mirror change has none: it needs a server that accepts and never answers):composer.lockwith escaped slashes that was pinned on the patch server. This one affected runs without a mirror.apply, which does not use the mirror.Two review comments on the pull request followed, both about the check that an earlier pin sits under the mirror's base. The check now compares parsed URLs, so
<base>/../other/xis not under the base, and Bun and yarn berry have a direct test for it alongside the Poetry and PDM one.One part of one
/code-reviewfinding is not fixed. For a binarybun.lockb, a re-run asks the mirror again about pins the lock already holds, and a direct pin in it gets noredirect_mirror_pin_not_movedhint. Both need the binary lock's records where the check only reads text, and Bun is not tested through a mirror yet. The cost is one extraHEADper pin and a less specific skip reason.Not covered
vendoron a Pipenv project that is pinned through a mirror is refused: that path builds its hosted origins from--patch-server-urlonly.No
CHANGELOG.mdentry, per the repository rule.🤖 Generated with Claude Code