Repository navigation
Description
[agent] Filed by the architecture refactor routine. Register: discussion #2244.
Kind: bug: a credential is printed. Found on main at 6280589, while reviewing #2445 (which fixes #2287).
Problem
utils/redact.rs is the one place a URL is made safe to show, and redact_urls_in is how every message applies it to text that quotes a URL. It finds where a quoted URL ends before it looks for the credential, and two kinds of URL end too early or are read as one:
- A credential that holds
)or'.ends_url(crates/socket-patch-core/src/utils/redact.rs, line 236) ends a URL at",',`,<,>,),],}and|. RFC 3986 lets userinfo hold)and'unencoded (they are sub-delimiters), so a password or token with one of them is cut before the@. What is left has no userinfo, and nothing is redacted. The messages that quote lock text wrap the URL in exactly those characters ((legacy <url>),`"<key>"`), which is why they are in the list. - The userinfo of a URL nested in a query.
https://proxy/fetch?url=https://user:token@host/xis one URL toredact_url(the unit testevery_element_of_a_url_list_is_redactedsays so: "a URL nested in a query is still part of its URL"), and only the outer authority is looked at.
A third case is the other way round and only cosmetic: the public proxy route /patch/view/<uuid> is shown as /patch/<redacted>/<uuid>, because the grant-token rule takes the level before a uuid for a token.
Evidence
redact.rs uses only std, so main's copy builds by itself (rustc --edition 2021 main.rs with a main that prints redact_urls_in of each argument). Run at 6280589:
IN : refusing to replace an existing Poetry source (legacy https://bot:pa)ss@pypi.corp.example/simple) for six
OUT: refusing to replace an existing Poetry source (legacy https://bot:pa)ss@pypi.corp.example/simple) for six
IN : lock block `"left-pad@git+https://x-access-token:gh'p_tok@github.com/acme/left-pad.git"` installs from git
OUT: lock block `"left-pad@git+https://x-access-token:gh'p_tok@github.com/acme/left-pad.git"` installs from git
IN : six @ https://proxy.corp.example/fetch?url=https://bot:tok@pypi.corp.example/six.whl; refusing
OUT: six @ https://proxy.corp.example/fetch?url=https://bot:tok@pypi.corp.example/six.whl; refusing
IN : GET https://patch.socket.dev/patch/view/7c8d9e0f-1a2b-4a1b-8c2d-3e4f5a6b7c8d: HTTP 404
OUT: GET https://patch.socket.dev/patch/<redacted>/7c8d9e0f-1a2b-4a1b-8c2d-3e4f5a6b7c8d: HTTP 404
IN : (https://bot:tok@h.example/x) # the control
OUT: (https://<redacted>@h.example/x)
From the binary, on the branch of #2445 (where vex builds its notes with the redacting constructor): a yarn classic lock with one block wired to a hosted patch and one block of the same release keyed "left-pad@git+https://x-access-token:ghp_S3CRET)TOKEN'0123456789@github.com/acme/left-pad.git":
$ socket-patch vex --cwd . --offline
Warning: yarn.lock: pkg:npm/left-pad@1.3.0 is wired to Socket patch aaaaaaaa-… but lock entry `"left-pad@git+https://x-access-token:ghp_S3CRET)TOKEN'0123456789@github.com/acme/left-pad.git"` installs from git, …
The same key without ) and ' in the token prints git+https://<redacted>@github.com/acme/left-pad.git there.
Impact
Every message that goes through redact_urls_in is affected: vendor warnings, download errors, telemetry errors, and after #2445 the vendored refusals, restore refusals and run warnings. A token of letters, digits, _ and - (a GitHub or npm token) is not affected. A password a person chose can be.
Planned fix
In redact_urls_in, find the authority before ending the URL: from ://, a ) or ' is part of the URL when an @ follows it before the next /, ?, #, whitespace or quote. Keep the comma-list rule (https://a,https://u:p@b) and the closing-bracket cases the current tests pin. For a nested URL, redact the userinfo of each scheme:// inside a query value. The red test is the first three inputs above against their redacted forms.
Behavior change: message text only.
Not checked
- Which package managers write such a URL unencoded. Poetry, pip and yarn classic copy a source URL as the user wrote it; I did not run them with a password that holds
). redact_urlon a single URL (not text) is not affected by the first point: it takes the authority up to the first/,?or#.
Generated by Claude Code
Activity
mikolalysenko commentedon Dec 2, 2026
[agent] More inputs of the same kind, from a second review pass of #2445. Each ran through a standalone build of
utils/redact.rs(the branch's copy;main's differs only in two panics that #2445 fixes).All four are one rule: after the first
://, a laterscheme://…@inside the same run of text is taken for part of that URL, so only the first authority is looked at. A random-string run (3,000,000 inputs) found 6,114 where a second pass ofredact_urls_inover its own output redacts more; in each the first pass had left the userinfo of a later://. None un-redacts or corrupts text.For the fix: redact the userinfo of every
://…@in a run, not only the first, and take;for a list separator beside,.#2445 also fixes two panics in this file that the same run found on
main(redact_urls_in("é://"),redact_url("?,key=://T@")), so they are not part of this issue.Generated by Claude Code
mikolalysenko commentedon Dec 2, 2026
[agent] Two more, from the last review pass of #2445. Both are on
mainand unchanged by that PR.)case of this issue in a query value, in the text reqwest writes for a transport error (it keeps the query of the URL it names; it drops the userinfo).network_error_detail(crates/socket-patch-core/src/api/client.rs, line 63) redacts that text by scanning it. It has the error's URL whole (e.url()), so it can redact it as one URL, asget_json_authorizeddoes for its own half of the message after Stop printing the credentials of URLs quoted from lockfiles in refusals and hosted warnings #2445.grant_token_spantakes the level before the last uuid-shaped level, so a package whose name is uuid-shaped, under a Socket-served registry base, moves the cut onto the patch uuid and the token (GSEC) is printed. Read from the code and run through the redactor built alone; no package manager was run against such a name.Generated by Claude Code
refactor: #2445 taken over for #2287, ready; #2448 filed
mikolalysenko commentedon Dec 2, 2026
[agent] Claiming this for the architecture refactor routine. Branch: arch-refactor/2448-redactor-url-ends.
Every input of this issue and its two comments ran again on
mainat 7beca2f throughutils/redact.rsbuilt alone, and each still prints its credential. One more of the same kind turned up: a host written as an IPv6 literal ends the URL at its], so the grant token and the secret query values behind it are printed (GET http://[::1]:8080/x?token=abc: HTTP 404comes back unchanged).Generated by Claude Code
Read every URL in a run of text for credentials
Redact a failed request's URL as one URL
End a token's path where the next URL begins
Take the review's findings on the redactor
Name a download's URL as one URL in its errors
mikolalysenko commentedon Dec 2, 2026
[agent] #2461 is open for this. What it fixes, and what it leaves:
Fixed there (each input below is from this issue or its comments, and is a row of a unit test that fails on
main):)or';;-joined list, ofname@urlentries joined by commas, and of a list element with an empty scheme;)in the text of a failed request or download:network_error_detailtakes the URL from the error and redacts it as one URL, and the registry download, the Maven fetch andutils/http.rsname theirs throughredact_url;Found on the way and fixed with it: a host written as an IPv6 literal ended the URL at its
], so the grant token and the secret query values behind it were printed; a URL nested in a query kept its own secret query values and its grant token.Left:
/patch/view/<uuid>is still shown as/patch/<redacted>/<uuid>(the third point above, cosmetic). Stop printing a credential the URL redactor ends before, or behind another URL #2461 hides more thanmaindoes, and this would be a place where it showed more.mainand on the branch:https://h/x?urls=https://a.example,https://b.example&api_key=SECRETcomes back unchanged fromredact_urls_in(the comma starts a new URL, which has no?).redact_urlon the same string redacts it. Found by the review of Stop printing a credential the URL redactor ends before, or behind another URL #2461.?url=https%3A%2F%2Fuser%3Apass%40host) is not decoded.",<,>,|, a backtick, a space) still ends at it.redact_url; other callers that put a raw URL into a message and scan the message afterwards were not looked for beyond the four above.strip_url_userinfo(the form recorded in a VEX product id) reads the first authority only.None of the left ones was run through a package manager.
Generated by Claude Code
refactor: #2461 opened for #2448, ready with CI green