Repository navigation
Stop printing a credential the URL redactor ends before, or behind another URL - #2461
Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
Conversation
Refs #2448. Assisted-by: Claude Code
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
|
bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview Call-site changes: 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. |
There was a problem hiding this comment.
✅ 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.
Assisted-by: Claude Code
|
[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 Risk: low. The change only affects message text: no JSON shape, flag, exit code or file changes. It hides more than Look here
Verified
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 |
LLM Description written by Claude Code
Fixes #2448.
Problem
utils/redact.rsis the one place a URL is made safe to show. Every message that quotes a URL goes through it: warnings, refusals, error text,--jsondetails, 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:)or'(both are legal in a userinfo, and the messages wrap a quoted URL in exactly those);http://[::1]:8080/…): the URL ended at the])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
mainThe binary built from
main(7beca2f). The CLI testtests/scan/quoted_url_credentials.rsplants one token in a file-only project and runsscanandgetin hosted and vendored mode, plain,--jsonand--dry-run. A copy of it with the token changed toS3CRET)TOKEN'0123456789:The unit tests of this branch, on
main's production code (a worktree of 7beca2f with only the tests added):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.redact_urlredacts the userinfo behind every://, not only the first. In free text,url_endsteps 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.url_endsteps over a bracketed host that holds a:([::1],[fe80::1%25eth0]). A]anywhere else still ends the URL.?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.://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.network_error_detail(coreapi/client.rs) takes it from thereqwesterror, and the registry download, the Maven fetch and the two messages ofutils/http.rsname theirs throughredact_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_endandgrant_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
@:'or), with an@behind that before any space,/,?or#:registry (https://npm.corp.example),left-pad@1.3.0readsregistry (https://<redacted>@1.3.0;@:?registry=https://registry.npmjs.org&name=@babel/corereads?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 ofmainthat 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.rsuses onlystd),main's copy against this branch's:mainhides that this branch showsmain678,171, this branch 0redact_urlmain240,503, this branch 0mainThe one shape where
mainhides a path level and this branch shows it: a serve path that holds a://betweenpatchand its token, followed by a second uuid-shaped level behind a URL thatmainended early at a',)or](…/patch/://T/<uuid>/://'@/<uuid>).maintook the first uuid for the last one only because it stopped reading there; with a plain host in the same placemainprints 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.mainhides a credential and the branch prints it; none at all forredact_urlin 17,000,000 cases; no panic; linear timemainread on its own is now nested: its path was cut at an&(a package nameda&b) or at the next://utils/http.rsstill printed a secret query value that holds): they put the raw URL into a message that is scanned afterwardsredact_url; the download's and the redirect's tests carry such a valuenetwork_error_detailreplaced the URL wherever it occurs as a substring(<url>), the formreqwestwrites#/auth/callback?state=abc,#key=value, an integrity fragment with=padding)?behind the#starts a query), or a nested password that holds&…=maintoo: a secret after a comma-joined URL list inside a query (?urls=https://a,https://b&api_key=S) is printed in textNot in this PR
/patch/view/<uuid>is still shown as/patch/<redacted>/<uuid>(the issue's third point, cosmetic). Changing it would show a levelmainhides.?url=https%3A%2F%2Fuser%3Apass%40host) is not decoded.",<,>,|, a backtick, a space) still ends at it.redact_url.strip_url_userinfo(the form recorded in a VEX product id) reads the first authority only.tests/scan/quoted_url_credentials.rswith 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.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) andrepair(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)orcfg(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