Skip to content

Stop printing a credential the URL redactor ends before, or behind another URL - #2461

Open
Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
mainfrom
arch-refactor/2448-redactor-url-ends
Open

Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
mainfrom
arch-refactor/2448-redactor-url-ends

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code

Fixes #2448.

Problem

utils/redact.rs is the one place a URL is made safe to show. Every message that quotes a URL goes through it: warnings, refusals, error text, --json details, debug lines and telemetry errors. It decided where a quoted URL ends before it looked for the credential, and it looked at the first authority only. So these credentials were printed, to the terminal and into CI logs:

The URL What was printed
a password or token that holds ) or ' (both are legal in a userinfo, and the messages wrap a quoted URL in exactly those) the whole userinfo
a URL nested in the query or the path of another, or joined to another by ; its userinfo, its secret query values, its grant token
a host written as an IPv6 literal (http://[::1]:8080/…): the URL ended at the ] the grant token and the secret query values behind it
a registry URL whose package is named like a uuid the grant token (the patch uuid was redacted in its place)
a failed request's or download's URL whose secret query value holds a ) the rest of the value

A token of letters, digits, _ and - in a plain URL was never affected. A password a person chose, a fetch proxy that takes the real URL as a parameter, and a patch server or registry on an IPv6 address are.

Evidence on main

The binary built from main (7beca2f). The CLI test tests/scan/quoted_url_credentials.rs plants one token in a file-only project and runs scan and get in hosted and vendored mode, plain, --json and --dry-run. A copy of it with the token changed to S3CRET)TOKEN'0123456789:

main's binary: 19 of 19 runs print the token          this branch: 0 of 19

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_S3CRET)TOKEN'0123456789@github.com/acme/cfg-if.git?rev=0123456#…
scan --json --mode hosted (exit 0): TOKEN PRINTED
    "detail": "requirements.txt installs six@1.16.0 from the direct reference https://bot:S3CRET)TOKEN'0123456789@pypi.corp.example/packages/six-1.16.0-py2.py3-none-any.whl; refusing to overwrite a user-authored source (not rewritten)"
get pkg:npm/covgap-hosted@1.0.0 --mode hosted (exit 0): TOKEN PRINTED
    Warning: Lock entry `"covgap-hosted@git+https://x-access-token:ghp_S3CRET)TOKEN'0123456789@github.com/acme/covgap-hosted.git"` installs covgap-hosted@1.0.0 from git, …

The unit tests of this branch, on main's production code (a worktree of 7beca2f with only the tests added):

$ cargo test -p socket-patch-core --lib -- utils::redact network_error_detail download_errors a_redirect_never_downgrades
test utils::redact::tests::a_credential_that_holds_a_quote_or_a_bracket_is_redacted ... FAILED
test utils::redact::tests::the_userinfo_of_every_url_in_a_run_is_redacted ... FAILED
test utils::redact::tests::an_ipv6_host_does_not_end_its_url ... FAILED
test utils::redact::tests::the_query_and_the_grant_token_of_a_nested_url_are_redacted ... FAILED
test utils::redact::tests::a_registry_token_is_redacted_by_its_place ... FAILED
test api::client::tests::network_error_detail_redacts_the_request_url_as_one_url ... FAILED
test vendor::registry_fetch::tests::download_errors_never_carry_a_credential ... FAILED
test utils::http::tests::a_redirect_never_downgrades_the_transport ... FAILED
test result: FAILED. 12 passed; 8 failed

  left: "refusing a Poetry source (legacy https://bot:pa)ss@pypi.corp.example/simple) for six"
 right: "refusing a Poetry source (legacy https://<redacted>@pypi.corp.example/simple) for six"
  left: "six @ https://proxy.corp.example/fetch?url=https://bot:tok@pypi.corp.example/six.whl; refusing"
 right: "six @ https://proxy.corp.example/fetch?url=https://<redacted>@pypi.corp.example/six.whl; refusing"
  left: "GET http://[::1]:8080/x?token=abc: HTTP 404"
 right: "GET http://[::1]:8080/x?token=<redacted>: HTTP 404"
  left: "https://proxy.corp.example/fetch?url=https://s3.example/b/six.whl?X-Amz-Signature=abc&v=1"
 right: "https://proxy.corp.example/fetch?url=https://s3.example/b/six.whl?X-Amz-Signature=<redacted>&v=1"
  left: "GET https://h/patch-registry/npm/GSEC/<redacted>/0f1e2d3c-4b5a-4968-8776-655443322110/1.3.0: HTTP 404"
 right: "GET https://h/patch-registry/npm/<redacted>/<redacted>/0f1e2d3c-4b5a-4968-8776-655443322110/1.3.0: HTTP 404"
error sending request for url (http://127.0.0.1:36103/private?token=<redacted>)cdSECRET&v=1): client error (Connect): …
QSECRET in refusing non-http(s) artifact URL `ftp://h.example/patch/npm/a/1.0.0/<redacted>/7c8d9e0f-…/a.tgz?token=<redacted>)QSECRET`
refusing a redirect from https://rubygems.org/gems/a-1.gem?token=<redacted>)FROMSECRET to http://cdn.example.test/a-1.gem?sig=<redacted>)TOSECRET, which is not an https URL

On this branch they all pass.

The fix

One rule: every :// starts a URL of its own, and its credentials are looked for before anything decides where it ends.

  • Userinfo. redact_url redacts the userinfo behind every ://, not only the first. In free text, url_end steps over a userinfo before it looks for the character that ends the URL. A ' or a ) is part of a userinfo when an @ follows it in the same authority; every other character that ends a quoted URL (", `, <, >, ], }, |, whitespace) still ends it there, since no userinfo holds one. Past the host, ' and ) end the URL as before.
  • IPv6 hosts. url_end steps over a bracketed host that holds a : ([::1], [fe80::1%25eth0]). A ] anywhere else still ends the URL.
  • Queries. A ? inside a query pair starts the query of a nested URL, and its names are read (?url=https://h/x?X-Amz-Signature=…). A fragment's own pairs are still not read (#sha256=…, a route), but a ? behind a # starts a query: that is where the query of a URL joined to this one sits.
  • Grant tokens. The path behind each :// is read for a token three ways: as a URL of its own (to the first ? or #, main's reading of the first URL), up to where the next URL begins, and up to its first & (a query value ends there). A registry URL's token is also taken by its place, right below the ecosystem (patch-registry/<eco>/<token>/<uuid>/…), whatever path follows the uuid.
  • A failed request or download. Where the caller has the URL, it is redacted as one URL and not cut out of the message again: network_error_detail (core api/client.rs) takes it from the reqwest error, and the registry download, the Maven fetch and the two messages of utils/http.rs name theirs through redact_url.

main's own rules are all kept and the new ones are added to them, so the change hides more and, outside one contrived shape (under Risk), never less.

What was deleted

list_element_end and grant_token_span. Finding a URL's end and its list boundary is one forward scan (url_end); it was a scan to the end of the text for every element of a comma-joined list.

Behavior change

Message text only. No JSON shape, flag, exit code or file changes.

  • The credentials in the table are redacted.

  • For a registry URL whose package path holds a uuid-shaped level, the patch uuid is redacted along with the token.

  • A failed Maven fetch names its cause chain (…: client error (Connect): tcp connect error: Connection refused), as the registry download beside it already did.

  • Text that is not a credential can be redacted in two shapes. Both hide a host name and what follows it up to an @:

    • a URL with no path, closed by ' or ), with an @ behind that before any space, /, ? or #: registry (https://npm.corp.example),left-pad@1.3.0 reads registry (https://<redacted>@1.3.0;
    • a nested URL with no path, followed by a pair that holds an @: ?registry=https://registry.npmjs.org&name=@babel/core reads ?registry=https://<redacted>@babel/core.

    The unit tests pin the common neighbours that stay as they are: (see https://h.example) or mail bob@corp.example, 'https://a.example' and 'bob@b.example', a compact JSON object. Of the 10,898 lines of main that hold a :// (the redactor's own file aside), main's copy and this branch's differ on one: a test string whose password holds ) and '.

Risk

The redactor runs on every message, over text from project files. Checked with the file built alone (utils/redact.rs uses only std), main's copy against this branch's:

Check Inputs Result
a byte main hides that this branch shows 1,000,000 random strings from the characters the redactor branches on, as text and as one URL; 1,000,000 generated messages; 1,000,000 generated URLs none
the same, with the reviewer's generator 3,000,000 strings, as text and as one URL as one URL: none. As text: 35, all one shape (below)
a planted credential printed (userinfo with any character RFC 3986 allows, grant tokens, secret query values; nested URLs, IPv6 hosts, lists, uuid-shaped names and tokens) 1,000,000 messages main 678,171, this branch 0
the same, one URL through redact_url 1,000,000 URLs main 240,503, this branch 0
a panic; a second pass that changes the output 1,000,000 random strings none
a rule switched off, one at a time 12 mutants each fails the unit test that names its rule
time on 12 hostile inputs of up to 256 KB linear; a 192 KB comma-joined list takes 3 ms, 1.6 s on main

The one shape where main hides a path level and this branch shows it: a serve path that holds a :// between patch and its token, followed by a second uuid-shaped level behind a URL that main ended early at a ', ) or ] (…/patch/://T/<uuid>/://'@/<uuid>). main took the first uuid for the last one only because it stopped reading there; with a plain host in the same place main prints that level too. No package path looks like this.

What the review found

One subagent, given the diff and the issue and not my conclusions: /code-review high, then its own probes, fuzzers and mutants in a directory of its own (55 minutes). Each finding was run before it was acted on.

Found Outcome
no realistic input where main hides a credential and the branch prints it; none at all for redact_url in 17,000,000 cases; no panic; linear time —
a grant token missed when a URL that main read on its own is now nested: its path was cut at an & (a package named a&b) or at the next :// fixed: the path is read three ways. The reviewer's run goes from 208 hits per 3,000,000 to the 35 above
the registry download, the Maven fetch and utils/http.rs still printed a secret query value that holds ): they put the raw URL into a message that is scanned afterwards fixed: each names its URL through redact_url; the download's and the redirect's tests carry such a value
network_error_detail replaced the URL wherever it occurs as a substring fixed: it replaces (<url>), the form reqwest writes
reading a fragment's own pairs redacted values that are no secret (#/auth/callback?state=abc, #key=value, an integrity fragment with = padding) fixed: a fragment's pairs are not read; only a ? behind the # starts a query
three rules and two claims of the tests could be removed with every test passing fixed: nine rows added; 12 mutants, one per rule, each fail the test that names the rule
a doc comment said the uuid always stays; a test name promised more than its rule fixed
the two shapes of redacted text that is no credential (under Behavior change) not changed. The narrower rules the reviewer tried bring back a printed credential: a token-only userinfo that holds ), or a nested password that holds &…=
on main too: a secret after a comma-joined URL list inside a query (?urls=https://a,https://b&api_key=S) is printed in text not changed here; it is on the issue

Not in this PR

  • /patch/view/<uuid> is still shown as /patch/<redacted>/<uuid> (the issue's third point, cosmetic). Changing it would show a level main hides.
  • A nested URL that is percent-encoded (?url=https%3A%2F%2Fuser%3Apass%40host) is not decoded.
  • A userinfo that holds a character RFC 3986 does not allow there as it is (", <, >, |, a backtick, a space) still ends at it.
  • In free text, a grant token or a secret query value that itself holds a character that ends a URL cannot be told from the text behind it. A caller that has the URL passes it to redact_url.
  • strip_url_userinfo (the form recorded in a VEX product id) reads the first authority only.
  • No CLI test is added. The run above is a copy of tests/scan/quoted_url_credentials.rs with another token, and that file is changed by the open Give the pip case of the quoted-URL credential test its own venv, so it passes off Ubuntu #2457.

Verification

Local, on the head (39f96bf):

  • cargo clippy --locked --workspace --all-features -- -D warnings: clean.
  • Core: 9,003 unit tests passed, 0 failed, on the head's production code. Two test rows were added after that run; the 31 tests of the changed modules passed again with them. The 699 integration tests passed on 31d0e40, before the review's fixes.
  • CLI: every test binary (224): 6,027 passed, 5 failed. The five are 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) and repair (repair_cleanup_failure_is_reported_in_json_and_silent_modes, repair_exits_zero_and_stays_quiet_when_lock_file_unremovable). Each makes a file unwritable with chmod, which does not stop root, the user this sandbox runs as; they pass in CI. The CLI's 1,105 unit tests passed on 31d0e40.

Windows and macOS were not run here. No cfg(windows) or cfg(unix) code changed.

CI on 39f96bf at 21:00Z: 37 checks pass, 53 are skipped (33 of them by a run that the push started while the PR was a draft, the rest by path), none failed. Cursor Bugbot reviewed 39f96bf and found no issues.

git diff --stat: 5 files, +549 −81. Production +277 −81 (utils/redact.rs +238 −62, about half of it doc comments; api/client.rs +17 −5; vendor/maven_repo.rs +12 −7; vendor/registry_fetch.rs +7 −4; utils/http.rs +3 −3). Tests +272 −0.


Generated by Claude Code

Refs #2448.

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
The redactor decided where a quoted URL ends before it looked for the
credential, and looked at the first authority only. So it printed:

- a userinfo that holds `'` or `)`. Both are legal there, and the
  messages wrap a quoted URL in exactly those;
- the userinfo of a URL nested in the query or the path of another, or
  joined to another by `;`;
- the secret query values and the grant token of a URL nested in a
  query;
- the grant token and the query secrets of a URL whose host is an IPv6
  literal, which ended at its `]`;
- the grant token of a registry URL whose package is named like a
  uuid, and of every URL but the last in a `;`-joined list.

Every `://` now starts a URL of its own: its userinfo is redacted, the
path behind it is read for a grant token, and a `?` inside a query pair
starts a nested query. What follows a `#` is read for secret names
like a query. In text, a URL's end is looked for behind the userinfo
and the brackets of an IPv6 host, and a `;` before a scheme separates
list elements as a `,` does. A registry URL's token is also taken by
its place, right below the ecosystem.

Finding the end is one forward scan now. It was a scan to the end of
the text for every list element, which took 1.6 s on a 192 KB
comma-joined list and takes 3 ms.

Refs #2448.

Assisted-by: Claude Code
reqwest names the request URL in brackets in its error text, and
`network_error_detail` redacted it by scanning that text. A secret
query value that holds a `)` ended the URL there, so the rest of the
value was printed. The URL is now taken from the error and redacted
whole before the text is scanned.

Refs #2448.

Assisted-by: Claude Code
A `;` before a scheme split the text into two URLs, as a `,` does.
That showed text `main` hides: after a secret query value, the
`;https://…` behind it was the tail of the value. A `;`-joined list is
one URL again, as on `main`, so nothing `main` redacts is shown.

What the split was for is done where the token is looked for. The
path behind a `://` ends before the next URL's scheme and before the
`,` or `;` that joins the two, so a registry URL that ends at its
uuid is read however the list is joined, and as one URL too.

Refs #2448.

Assisted-by: Claude Code
- A grant token could be missed in a URL that is now nested where
  `main` read it on its own: its path was cut at an `&` (a package
  named `a&b`) or at the next `://`. The path behind each `://` is
  read three ways: as a URL of its own, up to where the next URL
  begins, and up to its first `&`. Paths read whole do not overlap,
  so the work stays linear.
- Reading a fragment's own pairs redacted values that are no secret:
  the `state` of `#/auth/callback?state=…`, `#key=value`, the padding
  of an integrity fragment. A fragment's pairs are not read; a `?`
  behind the `#` starts a query, which is where the query of a URL
  joined to this one sits.
- Six rules could be switched off with every test passing. Each has
  a row now, and twelve mutants, one per rule, each fail the test
  that names the rule.
- A doc comment said the uuid always stays, and a test's name
  promised more than its rule.

Refs #2448.

Assisted-by: Claude Code
The registry download, the Maven fetch and two messages of
`utils/http.rs` put the raw URL into a message and scanned the
message afterwards, so a secret query value that holds a `)` was
printed from the `)` on. Each has the URL, and names it through
`redact_url`. The Maven fetch takes reqwest's text through
`network_error_detail`, as the registry download does, so its error
also names the cause.

`network_error_detail` replaced the request URL wherever it occurs
as a substring. It replaces `(<url>)`, the form reqwest writes.

Refs #2448.

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

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Security-sensitive log/error redaction on all user-facing messages; behavior is message-only but mistakes could leak credentials or over-redact diagnostics.

Overview
Fixes credential leaks in CLI/log output by rewriting URL redaction so each :// is treated as its own URL, userinfo/IPv6 bracket spans are stepped over before deciding where a quoted URL ends, nested query/path URLs and registry grant tokens are redacted, and fragment query pairs are handled more carefully.

Call-site changes: network_error_detail redacts via the reqwest URL and (<url>) replacement plus redact_message, instead of only scanning error strings. Registry/Maven download errors and HTTP secure_url/redirect_refusal messages use redact_url on the known URL so secret query values containing ) are not truncated mid-value when re-scanned in text.

Tests add broad unit coverage for quotes, brackets, nested URLs, IPv6, and registry token placement; one integration-style test for network error detail.

Reviewed by Cursor Bugbot for commit 39f96bf. 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 39f96bf. Configure here.

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Dec 2, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. The URL redactor used to decide where a quoted URL ends before it looked for credentials, and it read only the first authority. So a password holding ) or ', a URL nested in another or joined to it by ;, a host written in IPv6 brackets, and a registry package named like a uuid all leaked a secret into messages and CI logs. Now every :// is read as a URL of its own, and its userinfo and IPv6 host are stepped over before its end is found. Callers that already hold the URL (the reqwest error, registry download, Maven fetch, redirect refusal) redact it as one URL.

Risk: low. The change only affects message text: no JSON shape, flag, exit code or file changes. It hides more than main. It over-redacts in two shapes the description lists: a host up to a later @ with no space between, e.g. (https://h),pkg@1.0. That costs readability, not security. The scan is linear time; a 192 KB list takes 3 ms against 1.6 s on main.

Look here

Verified

  • Read the full diff and checked every caller of redact_url, including the npm fallback's .replace, which redacts both sides the same way.
  • cargo test -p socket-patch-core --lib on the head: 9,003 passed, 0 failed.
  • cargo clippy --locked --workspace --all-features -- -D warnings: clean.
  • CHANGELOG.md is untouched. No platform-specific code changed.
  • CI on 39f96bf: ci-ok and clippy are green and nothing failed. Bugbot found no issues, and no review threads are open.

Changes I made: none.

Open questions: none blocking. Follow-ups already noted on the issue: percent-encoded nested URLs, and a secret after a comma-joined list inside a query.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 2, 2026
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 Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review 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.

The URL redactor leaves a credential that holds ) or ', and the userinfo of a URL nested in a query

2 participants