Skip to content

Stop printing the credentials of URLs quoted from lockfiles in refusals and hosted warnings - #2445

Merged
Mikola Lysenko (mikolalysenko) merged 13 commits into
mainfrom
arch-refactor/2287-redact-quoted-lock-urls
Dec 2, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 13 commits into
mainfrom
arch-refactor/2287-redact-quoted-lock-urls

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code

Fixes #2287.

Problem

A project's own files can hold a URL with a credential in it: a yarn.lock block keyed by a private git remote (git+https://x-access-token:<token>@github.com/…), a Cargo.lock git source, a requirements direct reference to a private mirror, a Poetry source, a nuget.config source, a Gradle wrapper distributionUrl. When socket-patch refuses or skips such an entry it quotes the URL as written, so the token goes to the terminal, the CI log, the --json document a pipeline stores, and the result of the in-memory hosted engine.

utils/redact.rs states the rule ("Every URL that reaches a human or a log … goes through redact_urls_in or redact_url first"), and vendor warnings have applied it in their constructor since #1026. Vendored refusals, hosted warnings, vex's notes and the refusals of the upstream restore had no such step, so each message that quotes a lock value was one more place to forget.

It hurts anyone who runs scan, get, vex, rollback or remove in CI on a project that installs something from a private source.

Evidence on main (6280589)

The new CLI tests, run against the binary built from main: file-only projects that each hold the token S3CRETTOKEN0123456789 in one URL, a wiremock patch API, scan and get in both modes, and vex. 21 of 21 runs print the token.

$ cargo test -p socket-patch-cli --test scan quoted_url_credentials      # main's binary
test quoted_url_credentials::a_vendored_refusal_quotes_a_lock_entry_without_its_token ... FAILED
test quoted_url_credentials::a_hosted_warning_quotes_a_lock_entry_without_its_token ... FAILED

9 of 9 runs:
scan --mode vendored (exit 1): TOKEN PRINTED
    Error: Cannot vendor pkg:cargo/cfg-if@1.0.4: cfg-if@1.0.4 resolves from git+https://x-access-token:ghp_S3CRETTOKEN0123456789@github.com/acme/cfg-if.git?rev=0123456#0123456789abcdef0123456789abcdef01234567; server patches require the crates.io package
scan --json --mode vendored (exit 1): TOKEN PRINTED
    "error": "cfg-if@1.0.4 resolves from git+https://x-access-token:ghp_S3CRETTOKEN0123456789@github.com/acme/cfg-if.git?rev=0123456#0123…; server patches require the crates.io package",
scan --dry-run --mode vendored (exit 0): TOKEN PRINTED
    [would-refuse] pkg:npm/covgap-hosted@1.0.0 (vendor_lock_entry_not_rewritable): every yarn.lock block for covgap-hosted@1.0.0 installs from git, … lock block `"covgap-hosted@git+https://x-access-token:ghp_S3CRETTOKEN0123456789@github.com/acme/covgap-hosted.git"` installs from git, …
…
10 of 10 runs:
scan --mode hosted (exit 0): TOKEN PRINTED
    Warning: Lock entry `"covgap-hosted@git+https://x-access-token:ghp_S3CRETTOKEN0123456789@github.com/acme/covgap-hosted.git"` installs covgap-hosted@1.0.0 from git, which yarn fetches from the git source rather than a tarball; the hosted redirect leaves it untouched, so this copy stays unpatched
scan --json --mode hosted (exit 0): TOKEN PRINTED
    "detail": "requirements.txt installs six@1.16.0 from the direct reference https://bot:S3CRETTOKEN0123456789@pypi.corp.example/packages/six-1.16.0-py2.py3-none-any.whl; refusing to overwrite a user-authored source (not rewritten)"
get pkg:pypi/six@1.16.0 --mode hosted (exit 0): TOKEN PRINTED
    Warning: requirements.txt installs six@1.16.0 from the direct reference https://bot:S3CRETTOKEN0123456789@pypi.corp.example/packages/six-1.16.0-py2.py3-none-any.whl; refusing to overwrite a user-authored source (not rewritten)
…
$ cargo test -p socket-patch-cli --test vex quoted_url_credentials       # main's binary
vex ["--offline"]: the lock's credential was printed
Warning: yarn.lock: pkg:npm/left-pad@1.3.0 is wired to Socket patch aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa but lock entry `"left-pad@git+https://x-access-token:ghp_S3CRETTOKEN0123456789@github.com/acme/left-pad.git"` installs from git, …

The eleven new unit tests of the constructors, with only the production lines put back to main's text, all fail the same way. Three of them:

patch::redirect::upstream::nuget::tests::refusals_change_nothing
  … Newtonsoft.Json resolves from corp (https://bot:S3CRET@corp.example/v3/index.json) under nuget.config, not from nuget.org alone …
patch::redirect::upstream::client::tests::a_failed_json_lookup_never_quotes_a_credential
  GET http://bot:S3CRET@127.0.0.1:38049/left-pad/1.3.0: HTTP 404 Not Found
crawlers::gradle_cache::tests::a_wrapper_distribution_is_named_without_its_credentials
  ["wrapper distribution https://bot:S3CRET@repo.corp.example/gradle-8.14.3-bin.zip (not unpacked under …/wrapper/dists)"]

On the branch the same 21 runs name each entry as …https://<redacted>@github.com/acme/… and none prints the token.

Fix

The text is redacted where it enters each message type, as VendorWarning::new already did, so a call site that quotes a lock value has nothing to remember:

What is printed Redacted in Covers
a vendored refusal (Cannot vendor …, [would-refuse], events[].error) vendor::common::refused, which every backend builds refusals with the Cargo source and yarn classic lock key of the issue, and every other refusal
an upstream restore's refusal (Cannot restore … of rollback, remove and a takeover) FormatResult::refuse the nuget.config sources and the uv.lock / pylock.toml registry of the issue's follow-up
the error of a JSON lookup against a registry UpstreamClient::get_json_authorized quotes the URL it asked through redact_url SOCKET_NPM_REGISTRY, SOCKET_PYPI_JSON_API and SOCKET_PACKAGIST_URL with credentials
a run warning (Warning: … on stderr, warnings[].detail) RunWarning::new the yarn classic, Poetry and requirements warnings of hosted mode
a discovery note of vex (Warning: …, warnings[].detail) note_warning, which built its RunWarning by hand, now calls RunWarning::new the unpatched-copy note of the issue's table
the warnings of the hosted leg of rollback and remove (Warning: … on stderr, warnings[]) run_hosted_leg, once, where it finishes its list: both commands print stderr from that list before they build the envelope the note that a bun patch stops applying, whose key holds the hosted tarball's URL with its grant token
the in-memory engine's warnings (warnings[], projects[].redirect.warnings[]) EngineWarning::new and hosted::render::rewrite_warnings_json the same warnings, as the Node addon returns them
the Gradle note that a wrapper distribution is not unpacked at the one line that quotes distributionUrl every scan of such a build

The vendor constructors and the new ones share one helper, utils::redact::redact_message.

A RewriteWarning itself still holds the lock's own text: the engine matches it against lock keys (yarn_rewriter_named) and compares warnings for equality, so it is redacted where it is reported, not where it is built.

Two crashes in the redactor, fixed here

Sending more project text through utils/redact.rs reached two panics that are on main for the messages it already redacts. A run over 3,000,000 random strings: main's copy panics on 484,201 inputs of redact_urls_in (shortest é://) and 16,761 of redact_url (shortest ?,key=://T@); the branch's on none.

  • A character of more than one byte right before a ://. The scan for the scheme's start stepped one byte and then sliced inside the character. The first cut of this branch made it reachable from any scan of a Gradle build whose wrapper URL has such a character: exit 101 and no --json document, where main exits 0. scheme_start now steps over the whole character.
  • A ? with a secret-named parameter before the :// (x?auth=https://u:p@h). The userinfo then lies inside, or across the end of, a secret query value, and cutting the second span panicked. Overlapping spans are now cut as one.

Each has a unit test that panics on main's code.

Deleted

The three VendorOutcome::Refused literals of the npm flavor probe and the one the Maven backend rebuilt (they go through refused), the RunWarning literal of vex, and the inline copy of the redaction in VendorWarning::new.

Behavior change

Message text only. In the messages above, the userinfo of a quoted URL, a Socket grant token and a secret query value read <redacted>, as they already did in vendor warnings and download errors.

One place where that shows in an existing contract of tests: three messages name the patchedDependencies key of a bun patch made on a hosted package (<name>@<hosted URL>), and three tests of in_process_vendor_bun_takeover pinned the key as written. The key now reads left-pad@https://patch.socket.dev/patch/npm/left-pad/1.3.0/<redacted>/<uuid>/left-pad-1.3.0.tgz: the name, the patch uuid and the file still say which entry is meant. The tests expect that form and check that the token is not printed. The upstream_registry_fallback warning names its registry as before (without userinfo), and now with a query secret or grant token redacted too. No code, exit status, JSON shape or file on disk changes.

Risk

Low. detail and error strings are documented as human text. A script that matched the exact text of one of these messages, for a URL that held a credential, sees <redacted> in its place.

Review

/code-review high ran five times, by a subagent given the diff and the issue, with both binaries. Each finding was run before it was acted on.

Pass Found Outcome
1 vex's discovery note still printed the token (note_warning built its warning by hand) fixed, with a CLI test
1 the first redactor panic, reachable from the new Gradle redaction fixed
1 upstream_registry_fallback spelled its registry two ways once the cause arrived redacted fixed: reads as on main
1 the JSON lookup test's transport case could meet another test's server holds its port now
1 the redactor misses a credential that holds ) or ', and a URL nested in a query on main; filed #2448
2 the second redactor panic, reachable from the Gradle note and the fallback's rewrite fixed
2 the fallback's rewrite could put a query secret back into the cause fixed: the registry is named with every secret redacted
3 skipping an overlapping span left its tail (inputs that panicked before) spans are merged
3 the lookup redacted by scanning its own message, so a password with ) slipped through redacts the URL as one URL
3 a test asserted before it removed the variable it set reordered
4 no defect in the change. Two more gaps of the redactor on main (a query secret with ) in reqwest's own error text; a uuid-shaped package name after a Socket-served base) added to #2448
CI three tests of in_process_vendor_bun_takeover, a suite the local runs had left out, pinned a bun patch key with its grant token the tests expect the redacted key
after CI run by hand: the human rollback and remove still printed that key on stderr, where --json was now redacted redacted in run_hosted_leg; the test runs both commands without --json
5 no defect in the last two commits. A nit, left: the comment in run_hosted_leg names rollback and remove, and the leg's two other callers (scan's unwind of a withdrawn pin, vendor --revert) get the same redaction. Not pushed, to keep the head CI ran on

Not in this PR

  • The URL redactor leaves a credential that holds ) or ', and the userinfo of a URL nested in a query #2448: the redactor's own gaps above. They are on main for every redacted message and need a change to how the end of a quoted URL is found.
  • RunWarning and VendorOutcome::Refused have public fields. About forty RunWarning literals (most in commands/vendor.rs, which an open PR holds) and the (code, detail) pairs that get and the vendored legs print on stderr before they build a warning do not pass a constructor. No quoted URL was found in them by reading.
  • CLI_CONTRACT.md says of SOCKET_RUBYGEMS_URL that credentials in it are "sent and never printed". That is now true of the npm, PyPI and Packagist mirror variables as well; the sentence can follow once the two open PRs that edit the contract land.

Verification

Locally, as root in the sandbox. On 2041fa6, two small commits before the head:

  • CI's clippy (cargo clippy --locked --workspace --all-features -- -D warnings): clean.
  • core: 8,986 unit tests and 699 integration tests pass. CLI: 1,103 unit tests pass.
  • 33 CLI suites (scan, get, vex, cli, apply, rollback, remove, vendor, repair, update, the in-process redirect, vendor and rollback suites, the in-memory hosted suites and four e2e suites): 2,081 pass, 5 fail. The five are the write-failure tests that need a user root is not (in_process_redirect: partial_lockfile_write_failure_exits_1_and_writes_no_ledger, redirect_json_mode_write_failures_emit_error_envelope, vlt::scan_redirect_vlt_heal_invalidation_failure_warns; repair: repair_cleanup_failure_is_reported_in_json_and_silent_modes, repair_exits_zero_and_stays_quiet_when_lock_file_unremovable). They are the failures the routine's register lists for a root sandbox; they were not re-run on main in this run, and they pass in CI.
  • On the head (1c2ca65): clippy clean, the CLI's 1,103 unit tests, and ten suites pass (rollback, remove, scan, get, vex, in_process_vendor_bun_takeover, the three in-process rollback suites, remove_rollback_api_overrides).
  • CI on the head (1c2ca65): 88 checks pass, 26 skipped, none failed. On 2041fa6 coverage (1) failed on the three tests above.
  • Cursor Bugbot did not review: it answered bugbot run with "Bugbot is paused — on-demand spend limit reached".
  • The redactor, built alone, under 3,000,000 random strings: no panic, and what it cuts is exactly the union of the spans it marks.

Diff

git diff --stat origin/main: 24 files, +883 −64. Production: +103 −37 in 14 files. Tests: +780 −27.

No cfg(windows) or cfg(unix) code changed.


Generated by Claude Code

Refs #2287.

Assisted-by: Claude Code
@mikolalysenko Mikola Lysenko (mikolalysenko) added arch-refactor PR opened by the scheduled architecture refactor routine refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code labels Dec 2, 2026
A vendored refusal quotes lock text: the source of a Cargo.lock entry,
the key of a yarn.lock block, a registry. It is the `Cannot vendor`
line, a `[would-refuse]` preview line and the `error` of a `--json`
event, so a token in the userinfo of such a URL went to the terminal,
the CI log and the stored document.

`vendor::common::refused`, which every backend builds its refusals
with, now redacts the URLs in its detail, as `VendorWarning::new`
already does. The three refusals the npm flavor probe built by hand and
the one the Maven backend rebuilt go through it. Both constructors use
one helper, `redact_message`.

Refs #2287.

Assisted-by: Claude Code
`rollback`, `remove` and a vendored takeover put a hosted pin back on
its registry entry, and refuse with the reason: the sources a
nuget.config maps a package to, the registry a uv.lock or pylock.toml
records, or the URL of a request that failed. Credentials in any of
those were printed in the `Cannot restore` line and in the `error` of
the `--json` event.

`FormatResult::refuse` now redacts the URLs in its reason. The JSON
lookups (the npm, PyPI and Packagist documents, which a mirror variable
can point at a URL with credentials) redact their errors the way the
byte downloads already do.

Refs #2287.

Assisted-by: Claude Code
A hosted rewriter names the lock entry it leaves alone: a yarn.lock
block installed from git, a Poetry source, a requirements direct
reference. With a token in that URL the warning carried it to stderr,
to `warnings[].detail` of the `--json` document, and to the result of
the in-memory engine.

The warning is now redacted where it enters each reported type:
`RunWarning::new` for the CLI (its stderr lines are printed from the
same values), and `rewrite_warnings_json` and `EngineWarning::new` for
the in-memory engine. A `RewriteWarning` itself keeps the lock's text,
which the engine compares against lock keys.

Refs #2287.

Assisted-by: Claude Code
A wrapper whose `distributionUrl` names a distribution that is not
unpacked yet is reported in the `gradle_maven_local_undetermined` note
of every scan of the build. A distribution server that needs
credentials takes them in that URL, so the note printed them.

Refs #2287.

Assisted-by: Claude Code
Three file-only projects each hold one token in a URL their package
manager writes or reads: a yarn classic lock keyed by a git remote, a
Cargo.lock git source and a requirements direct reference. `scan` and
`get` run over them in hosted and vendored mode, plain, with `--json`
and with `--dry-run`, and neither stream may carry the token. Every run
must still name the entry, with the credential redacted.

Refs #2287.

Assisted-by: Claude Code
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Dec 2, 2026
The run confirmed #2287 on main (11 of 11 runs print the token),
claimed it and opened the draft, then lost its worker for four
hours. Another run took the PR over, so this entry leaves the
register to that run.

Assisted-by: Claude Code
`redact_urls_in` looks back from a `://` for the start of the scheme
and stepped one byte past the character it stopped on. With a
character of more than one byte right before the scheme (a curly
quote, an accented letter in a lock key or a manifest value) it then
sliced inside that character and panicked.

Vendor warnings and download errors already ran project text through
it; the refusals and run warnings this branch redacts made the panic
reachable from every scan of a Gradle build whose wrapper URL has such
a character: exit 101 and no `--json` document, where main exits 0.
The scan now steps over the whole character.

Refs #2287.

Assisted-by: Claude Code
`vex` reports a Socket-wired lock entry it cannot attribute and quotes
the entry beside it: for a yarn classic lock, the key of a block that
installs the same release from git. With a token in that remote the
note printed it on stderr and in `warnings[].detail`.

`note_warning`, which every advisory of `vex` is recorded through,
built its `RunWarning` by hand and so skipped the constructor that
redacts. It now calls `RunWarning::new`; the stderr lines are printed
from the same values.

Refs #2287.

Assisted-by: Claude Code
`upstream_registry_fallback` names the project's registry without its
userinfo and rewrote the cause to match. The cause of a failed lookup
now arrives redacted, so the rewrite found nothing and the sentence
read `http://host/…` beside `http://<redacted>@host/…`. The rewrite
takes both spellings, and the warning reads as it does on main.

The JSON lookup's test holds its port for the transport case instead
of reusing one a dropped listener released, and checks each cause.

Refs #2287.

Assisted-by: Claude Code
`redact_url` collects the userinfo, the grant token and each secret
query value of a URL and cuts them out in order. A value that is shown
as one URL is whatever a project file holds, and when a `?` with a
secret-named parameter comes before its `://` (`x?auth=https://u:p@h`)
the userinfo lies inside the query value: the second cut started
before the first one ended, and the slice panicked.

`redact_urls_in` never hands it such text, so main reaches this only
from callers that pass a setting whole. This branch added two: the
Gradle wrapper's `distributionUrl` and the registry of the fallback
warning. A span that starts inside an earlier one is now skipped, as
the earlier one covers it.

The fallback warning also names its registry with any query secret or
grant token redacted, not only without its userinfo, so the cause
cannot put one back.

Refs #2287.

Assisted-by: Claude Code
The spans of a text that is not a well-formed URL can overlap only in
part: a userinfo or a grant token that runs past the end of a secret
query value, or a query value that starts inside one. Skipping the
later span left its tail in the output (`x?auth=https://user:PASS&WORD@h`
kept `&WORD`). Overlapping spans are now cut together. Each of these
inputs panicked before this branch.

A JSON lookup redacts the URL it asked as the one URL it is, instead
of scanning its own message for URLs, so a password that holds `)` or
`'` is redacted there too. Its test uses such a password.

The fallback warning's test asserts only after it has removed the
variable it set.

Refs #2287.

Assisted-by: Claude Code
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 2, 2026 12:42
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 2, 2026

Copy link
Copy Markdown

Bugbot is paused — on-demand spend limit reached

Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

Three messages name the `patchedDependencies` key of a `bun patch`
made while the package resolved to its hosted tarball: the skip of a
superseding hosted run, the refusal of a vendored takeover, and the
rollback's note that the patch stops applying. The key is
`<name>@<hosted URL>`, and the URL holds the grant token.

Their tests pinned the key as written. The messages now go through
the redacting constructors, so the token reads `<redacted>`; the name,
the patch uuid and the file still say which entry is meant. The tests
expect that form and check that the token is not printed.

Refs #2287.

Assisted-by: Claude Code
`rollback` and `remove` print the warnings of their hosted leg on
stderr from the leg's own list and build the envelope's copy
afterwards. The envelope's copy is redacted by its constructor; the
stderr line was not, so a human run still printed the grant token in
the key of a dropped `bun patch`, where `--json` showed `<redacted>`.

`run_hosted_leg` now redacts its warnings once, where it finishes
them, so both channels read the same. The test of that warning runs
`rollback` and `remove` without `--json` as well.

Refs #2287.

Assisted-by: Claude Code
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Dec 2, 2026
The run took over the abandoned draft, fixed the credential leaks of
#2287 with two panics of the URL redactor, and filed the redactor's
remaining gaps as #2448.

Assisted-by: Claude Code
@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 2440352 Dec 2, 2026
114 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the arch-refactor/2287-redact-quoted-lock-urls branch December 2, 2026 15:18
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Dec 2, 2026
Brings in #2445, which changed `commands/vex.rs`, so that the
omission phrase of a lock pin can be edited on its current text.

Assisted-by: Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-refactor PR opened by the scheduled architecture refactor routine refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refusals and hosted warnings print the credentials of URLs quoted from lockfiles

4 participants