Skip to content

Add an experimental patch mirror for hosted mode behind an internal artifact host - #2180

Merged
Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
feat/patch-mirror
Nov 20, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
feat/patch-mirror

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

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.

without   https://patch.socket.dev/patch/npm/minimist/1.2.2/<token>/<uuid>/minimist-1.2.2.tgz
with      https://repo.example/artifactory/socket-patch/patch/npm/minimist/1.2.2/<token>/<uuid>/minimist-1.2.2.tgz

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 its redirect_mirror_* codes Experimental and outside the semver policy. A repository file cannot set it (the socket.yml trust boundary).

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: the pin is written.
    • 401, 403, 407 or a redirect: the pin is written, with one redirect_mirror_unverified warning.
    • Anything else: that pin is skipped with redirect_mirror_unavailable and its files stay byte-identical.
    • No answer at all (a transport failure or a timeout): nothing more is asked, and that pin and every pin not yet asked about are skipped.
  • SOCKET_PATCH_MIRROR_AUTHORIZATION (environment only) authenticates that check. It goes nowhere else and is scrubbed from child processes.
  • The run's own downloads still read the patch server, and so does what a rollback downloads to restore a pin.
  • list, vex, rollback, remove, vendor and repair read 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.
  • A fork of the same package and version in another repository of the mirror's host stays the project's own source: the rewriters that take over an earlier pin in place do so only under the mirror's base.
  • 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 (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

Socket's backend today Backend that recognizes mirrored pins
No mirror set Unchanged: the lockfiles are the same as before Unchanged
Mirror set Pins and installs work. A Socket scan still lists each package, but as unpatched Listed as patched

The CLI needs nothing new from the Socket API or the patch server: the live suite below runs against production as it is.

Testing

  • Unit tests for the base parser, the candidate rewrite and the unknown-host guard.
  • 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, vex and rollback. 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.
  • Local run on the head commit: CI's clippy command clean, cargo check --all-targets --all-features clean, 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 high reported 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):

  • A mirror was matched by its host, so a URL in another repository of that host counted as a hosted pin. It is now matched by its base.
  • The yarn berry, Bun, Poetry and PDM rewriters could take a fork of the same name and version on the mirror's host for an earlier Socket pin.
  • With only the mirror set, a rollback of a yarn berry pin asked the mirror for the upstream checksum.
  • The unknown-host guard misread a composer.lock with escaped slashes that was pinned on the patch server. This one affected runs without a mirror.
  • An unreachable mirror was asked once per patch, each waiting out the timeout.
  • A malformed mirror value failed apply, which does not use the mirror.
  • Two wording problems: the warning after a 404 followed by a 401, and the Cargo and NuGet skip saying the package stays unpatched.

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/x is 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-review finding is not fixed. For a binary bun.lockb, a re-run asks the mirror again about pins the lock already holds, and a direct pin in it gets no redirect_mirror_pin_not_moved hint. 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 extra HEAD per pin and a less specific skip reason.

Not covered

  • A Maven, Gradle or sbt build through a mirror. The repository URL is written under the mirror, but no build has been run that way.
  • Composer, PDM, Pipenv, Bun and vlt through a mirror, and Go through an Artifactory Go repository.
  • vendor on a Pipenv project that is pinned through a mirror is refused: that path builds its hosted origins from --patch-server-url only.
  • The Pipenv and inline-script rewriters recognize an earlier pin by the patch server's path shape on the grant's host. Under a mirror that still counts a URL in that exact shape in another repository of the mirror's host.

No CHANGELOG.md entry, per the repository rule.

🤖 Generated with Claude Code

@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 20, 2026 15:41
@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 20, 2026
@cursor

cursor Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches hosted lockfile rewriting, patch-host recognition, and grant URL security checks; the unconfigured-host guard changes behavior for every hosted run (additive), while mirror-specific surface is experimental and opt-in.

Overview
Adds an experimental enterprise path so hosted mode can pin patched dependencies to a caching mirror of patch.socket.dev (e.g. Artifactory) instead of the public patch server.

--patch-mirror-url / SOCKET_PATCH_MIRROR_URL (hidden from help) rewrites granted artifact and registry index URLs onto the mirror base while keeping paths and integrity. Hosted scan / get probe new pins with a credential-free HEAD (optional SOCKET_PATCH_MIRROR_AUTHORIZATION) before writing; Cargo/NuGet are skipped as mirror-incompatible, and several rewriters only migrate existing direct patch-server pins after rollback. Discovery and unwind (list, vex, rollback, remove, hosted pin detection) treat the mirror base like a patch host, matching by base path rather than whole host.

Additive for all hosted runs: pins on hosts the run does not know (--patch-server-url or the mirror) are left untouched with redirect_pin_on_unconfigured_host, so a run without the mirror never moves mirrored pins back to Socket's server. CLI wiring validates the mirror base up front (except apply, which ignores it) and threads the setting through download and unwind helpers.

Reviewed by Cursor Bugbot for commit 51d6242. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ 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.

Comment thread crates/socket-patch-core/src/origin.rs Resolved
Comment thread crates/socket-patch-core/src/origin.rs Resolved
…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>
Merged via the queue into main with commit 412796f Nov 20, 2026
101 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the feat/patch-mirror branch November 20, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants