Skip to content

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

In review

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:

  1. 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.
  2. The userinfo of a URL nested in a query. https://proxy/fetch?url=https://user:token@host/x is one URL to redact_url (the unit test every_element_of_a_url_list_is_redacted says 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_url on 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

  1. added
    bug
    arch-audit
    on Dec 2, 2026
  2. mikolalysenko commented on Dec 2, 2026

    @mikolalysenko
    CollaboratorAuthor

    [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).

    IN : https://u:p@h/a/https://u2:p2@h2/x                    # a URL in the path of another
    OUT: https://<redacted>@h/a/https://u2:p2@h2/x
    
    IN : GOPROXY=https://a.example/x;https://u:p@b.example     # a `;`-joined list, as NuGet source lists are
    OUT: GOPROXY=https://a.example/x;https://u:p@b.example
    
    IN : a@https://h/x,b@https://u:p@h/y                       # `name@url` entries joined by commas
    OUT: a@https://h/x,b@https://u:p@h/y
    
    IN : https://a.example,é://u:p@b                           # a list element whose scheme is empty
    OUT: https://a.example,é://u:p@b
    

    All four are one rule: after the first ://, a later scheme://…@ 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 of redact_urls_in over 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

  3. mikolalysenko commented on Dec 2, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Two more, from the last review pass of #2445. Both are on main and unchanged by that PR.

    IN : error sending request for url (http://h/private?token=ab)cd/left-pad/1.3.0)
    OUT: error sending request for url (http://h/private?token=<redacted>)cd/left-pad/1.3.0)
    
    IN : GET https://h/patch-registry/npm/GSEC/7c8d9e0f-1a2b-4a1b-8c2d-3e4f5a6b7c8d/0f1e2d3c-4b5a-4968-8776-655443322110/1.3.0: HTTP 404
    OUT: GET https://h/patch-registry/npm/GSEC/<redacted>/0f1e2d3c-4b5a-4968-8776-655443322110/1.3.0: HTTP 404
    
    • The first is the ) 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, as get_json_authorized does for its own half of the message after Stop printing the credentials of URLs quoted from lockfiles in refusals and hosted warnings #2445.
    • The second is the grant-token rule: grant_token_span takes 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

  4. added a commit that references this issue on Dec 2, 2026
  5. mikolalysenko commented on Dec 2, 2026

    @mikolalysenko
    CollaboratorAuthor

    [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 main at 7beca2f through utils/redact.rs built 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 404 comes back unchanged).


    Generated by Claude Code

  6. mikolalysenko commented on Dec 2, 2026

    @mikolalysenko
    CollaboratorAuthor

    [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):

    • a userinfo that holds ) or ';
    • the userinfo of a URL nested in the query or the path of another, of every element of a ;-joined list, of name@url entries joined by commas, and of a list element with an empty scheme;
    • a secret query value that holds ) in the text of a failed request or download: network_error_detail takes the URL from the error and redacts it as one URL, and the registry download, the Maven fetch and utils/http.rs name theirs through redact_url;
    • the grant token of a registry URL whose package is named like a uuid.

    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 than main does, and this would be a place where it showed more.
    • A secret after a comma-joined URL list inside a query is printed in text, on main and on the branch: https://h/x?urls=https://a.example,https://b.example&api_key=SECRET comes back unchanged from redact_urls_in (the comma starts a new URL, which has no ?). redact_url on the same string redacts it. Found by the review of Stop printing a credential the URL redactor ends before, or behind another URL #2461.
    • 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 can pass it to 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

  7. added a commit that references this issue on Dec 2, 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:claimedagent:triagedarch-auditbugpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions