Skip to content

Hosted Bun re-run with a patch mirror re-checks a bun.lockb pin already on the mirror, and reports it skipped and unpatched when the mirror answers 5xx #2384

Backlog

Description

[agent] Found by the scheduled Bun bug-hunt routine (ledger #306).

Summary

The patch mirror is experimental (added in #2180, not in v5.1.0), so this isn't a regression since v5.1.0.

Take a Bun project whose bun.lockb already pins a patch on the mirror, and re-run scan --mode hosted with the same SOCKET_PATCH_MIRROR_URL / --patch-mirror-url. Nothing new needs pinning, but socket-patch still sends a HEAD to the mirror for the existing pin on every run. Then it treats the answer as if it were pinning that patch for the first time:

  • Mirror briefly down (5xx, or no answer): the run says Switched 0 packages to hosted patches, No patches could be switched to hosted: … the patch mirror does not serve it, so nothing was pinned, and 1 vulnerability left to patch. The --json output has summary.skipped: 1, applied: 0, and an event skipped / redirect_mirror_unavailable. All of that is false: bun.lockb is unchanged and still pins the patched tarball, so a frozen install still gets the patched bytes.
  • Mirror requires credentials (401/403, the usual case for a private Artifactory): every re-run prints redirect_mirror_unverified again, even though nothing is being pinned.

With bun.lock (text), the same re-run sends no HEAD and reports 1 package is already on hosted patches; nothing to rewrite, whatever the mirror answers. That's what the contract says should happen.

Impact

An Enterprise team that runs scan on a schedule or in CI, with the mirror configured, is told whenever the mirror has a blip that a patched vulnerability is now unpatched. Anything that reads --json (skipped, applied, the redirect_mirror_unavailable event) sees a regression that didn't happen. The warning tells them to check that --patch-mirror-url "names it exactly", which sends them to investigate a working configuration. A mirror that needs credentials (most private ones) repeats the "unverified" warning on every run.

Repro (offline: a local mock patch API on :18771 and a mirror on :18772)

The mock serves /v0/orgs/o/patches/{batch,by-package,package,view}, the tarball at /patch/npm/left-pad/1.3.0/<tok>/<uuid>/left-pad-1.3.0.tgz, and the same path under /artifactory/socket-patch on the mirror port. Its mirror HEAD answer can be switched to 500 or 401. Any mock that grants one npm patch will do.

unset BUN_OPTIONS
export SOCKET_PATCH_SERVER_URL=http://127.0.0.1:18771 SOCKET_PROXY_URL=http://127.0.0.1:18771
export SOCKET_PATCH_MIRROR_URL=http://127.0.0.1:18772/artifactory/socket-patch
sp() { socket-patch "$@" --api-url http://127.0.0.1:18771 --org o --api-token fake; }
mkdir p && cd p && git init -q && echo node_modules/ > .gitignore
echo '{"name":"m","version":"1.0.0","dependencies":{"left-pad":"1.3.0"}}' > package.json
printf '[install]\nsaveTextLockfile = false\n' > bunfig.toml   # drop this for the bun.lock control
bun install && git add -A && git commit -qm init
sp scan --mode hosted              # mirror answers 200: pins left-pad on the mirror
git add -A && git commit -qm hosted
sp scan --mode hosted              # mirror still 200: "already on hosted patches", but the mock logs a HEAD
# now make the mirror answer HEAD with 500
sp scan --mode hosted; git status --short    # nothing changed on disk
sp scan --mode hosted --json | jq '.summary.applied, .summary.skipped, [.events[].errorCode]'

Actual (bun.lockb, Bun 1.4.5 and 1.2.23):

Switched 0 packages to hosted patches; rewrote 0 files.
No patches could be switched to hosted:
  pkg:npm/left-pad@1.3.0: the patch mirror does not serve it, so nothing was pinned (see the warning)
Warning: The patch mirror http://127.0.0.1:18772/artifactory/socket-patch does not serve the patches (it answered HTTP 500), so nothing was pinned to it; check that it proxies Socket's patch server at that base and that --patch-mirror-url names it exactly

1 vulnerability left to patch: 1 is in packages this run did not patch.

--json: applied 0, skipped 1, ["redirect_mirror_unavailable"]. With the mirror answering 401: applied 1, plus a redirect_mirror_unverified warning on every run.

Control (bun.lock v2, same steps): 1 package is already on hosted patches; nothing to rewrite., applied 1, skipped 0, no warnings, and no HEAD in the mirror's log.

Expected

crates/socket-patch-cli/CLI_CONTRACT.md, "Patch mirror (experimental)", The mirror is checked before anything is pinned: "One HEAD for each mirrored reference the project's files do not already hold (a re-run that pins nothing new sends none)". The doc comment on check_mirror says the same: "A pin the project's files already hold is not asked about again, so a re-run that changes nothing sends nothing." A bun.lockb pin should count as one the project already holds, as a bun.lock pin does, and the re-run should report the package as already on hosted patches.

Where it reproduces

Bun Lock Extra HEAD on re-run 500 → false skipped / "left to patch" 401 → repeated redirect_mirror_unverified
1.2.23 bun.lockb yes yes (not run)
1.4.5 bun.lockb yes yes yes
1.4.5 bun.lock v2 no no no

Main cfc870f, Linux. v5.1.0 has no patch mirror. The code path is platform-independent, so macOS and Windows should behave the same.

Suspect code

crates/socket-patch-cli/src/commands/scan/hosted.rs:218: check_mirror's already_pinned looks for the artifact URL only in files (read.files, passed at hosted.rs:1817). That map holds the project's text files, so the URL inside binary bun.lockb is never found, and every existing lockb pin counts as a new pin.

Related: #2279 is another case where the mirror code doesn't see a bun.lockb pin (an earlier patch-server pin under a mirror, and the reverse redirect_pin_on_unconfigured_host case). Its guard, withhold_foreign_host_pins(&read.files, …) at hosted.rs:1808, reads the same map, so both may share a root cause. The open fix, #2282, changes only the warnings issued after the rewrite (mirror_pins_not_moved) and doesn't touch check_mirror, so this case stays broken with it. The symptom and the contract clause here are different too: this one is the steady-state re-run on a project that is already on the mirror.


Generated by Claude Code

Activity

  1. added
    bug
    bughunt
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedbugbughuntpm:bunpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions