Skip to content

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

Backlog

Description

[agent] Filed by the architecture refactor routine. Register: discussion #2244.

Kind: bug: a credential is printed. Found on main at cfc870f.

Problem

When a project's own lockfile or manifest holds a URL with credentials in it, four messages quote that URL as it is written, so the token goes to the terminal, the CI log and the --json document.

utils/redact.rs states the rule: "Every URL that reaches a human or a log (a warning, an error message, a --json event, a debug line, a telemetry error) goes through redact_urls_in or redact_url first", and it names userinfo (https://user:token@host/…) as the first kind of credential. #1026 applied the rule to vendor warnings by redacting in the constructor, VendorWarning::new ("whoever builds it"). Three other message types carry the same quoted text and have no such step:

Type Built by Where it leaks
VendorOutcome::Refused vendor::common::refused (633 calls) and 10 struct literals vendor/cargo.rs lock_source_refusal and vendor/yarn_classic_lock.rs (lines 378 to 388)
RewriteWarning a struct with public fields (246 literals) patch/redirect/requirements.rs (lines 286 to 296) and utils/poetry_lock.rs
the discovery note of an unpatched copy unpatched_copy vex/discover/yarn.rs

The npm backend shows the two ways side by side. Its vendor_lock_entry_not_rewritable refusal joins the details of VendorWarnings, which are already redacted. Yarn classic's refusal of the same code joins plain strings.

Evidence

I built the binary from main and ran it over 17 file-only projects. Each holds the token S3CRETTOKEN0123456789 in the userinfo of one URL, in a place where the package manager itself writes it or reads it. A local server stood in for the patch API and offered one free patch per package. Each project went through ten commands: scan in agent, vendored and hosted mode (dry and wet, with --json, with --debug) and get <purl> in vendored and hosted mode. Of the 170 runs, 29 print the token.

1. Cargo, vendored mode. Cargo.lock locks cfg-if 1.0.4 from a git source, another registry, or a sparse registry:

$ socket-patch scan --mode vendored --yes
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
Vendored 0 packages; 1 failed.

$ socket-patch scan --mode vendored --yes --json        # events[]
      "errorCode": "vendor_source_unsupported",
      "error": "cfg-if@1.0.4 resolves from registry+https://bot:S3CRETTOKEN0123456789@cargo.corp.example/index; server patches require the crates.io package",

get pkg:cargo/cfg-if@1.0.4 --mode vendored prints the same line.

2. Yarn classic, vendored and hosted mode. yarn.lock has a block keyed "left-pad@git+https://x-access-token:ghp_…@github.com/acme/left-pad.git":

$ socket-patch scan --mode vendored --dry-run --yes
  [would-refuse] pkg:npm/left-pad@1.3.0 (vendor_lock_entry_not_rewritable): every yarn.lock block for left-pad@1.3.0 installs from git, a link, a file: directory or a non-registry tarball, which vendoring can't rewire — those copies stay UNPATCHED and `yarn install` will not help: lock block `"left-pad@git+https://x-access-token:ghp_S3CRETTOKEN0123456789@github.com/acme/left-pad.git"` installs …

$ socket-patch scan --mode hosted --yes
Warning: Lock entry `"left-pad@git+https://x-access-token:ghp_S3CRETTOKEN0123456789@github.com/acme/left-pad.git"` installs left-pad@1.3.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

The same project with a package-lock.json is redacted: (it resolves to "git+https://<redacted>@github.com/acme/left-pad.git#0123…").

3. Poetry, hosted mode. poetry.lock has [package.source] type = "legacy" with url = "https://bot:…@pypi.corp.example/simple":

$ socket-patch scan --mode hosted --yes
Warning: poetry.lock: refusing to replace an existing Poetry source (legacy https://bot:S3CRETTOKEN0123456789@pypi.corp.example/simple) for six

4. A requirements direct reference, hosted mode. requirements.txt is six @ https://bot:…@pypi.corp.example/packages/six-1.16.0-py2.py3-none-any.whl:

$ socket-patch scan --mode hosted --yes
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)

For 2, 3 and 4 the --json run carries the same text in warnings[].detail, and get <purl> --mode hosted prints the same warning. The in-memory hosted engine returns 2 and 3 in projects[].redirect.warnings[].detail.

What did not leak. The other 141 runs: the token in a package-lock.json git spec, a pnpm-lock.yaml git entry, a bun.lock git entry, an .npmrc registry with a matching resolved, --index-url, --extra-index-url and --find-links lines, a Pipenv source, a uv index, a Gemfile.lock git remote, a gem source and a Composer repository. That shows these runs were clean, not that every message about those files is. Telemetry is clean: with it on, the patch_vendor_failed event of case 1 does not carry the text.

Impact

A token that sits in a lockfile is already in the repository. These messages copy it to places with a wider audience: CI logs, a --json document that a pipeline stores or posts, and the result of the in-memory engine. The rule the code states for itself does not hold for refusals and hosted warnings, so each new message that quotes a lock value is one more place to forget.

Planned fix

Redact where the text enters each type, as VendorWarning::new does, so no call site has to remember:

  • vendor::common::refused redacts its detail, and the 10 struct literals go through it.
  • RewriteWarning gets a constructor that redacts, and the 246 literals use it. A smaller first slice is to redact once where a RewriteResult's warnings are collected.
  • The discovery note redacts the key it quotes.

Then pin it with the matrix above as a CLI test: a table of project files and commands, asserting the token appears in neither stdout nor stderr. It is red on main for the four cases.

Behavior change: message text only. The userinfo of a quoted URL becomes <redacted>, as it already does in vendor warnings. No code, exit status or JSON shape changes.

Not checked

  • Maven, Gradle, NuGet and Go project files.
  • The messages of rollback, remove, vendor --revert, repair and vex over the same files.
  • Hosted cargo with a registry override. The stand-in served none, so those runs stopped at has no cargo-sparse registry override.

Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 26, 2026
  2. added 2 commits that reference this issue on Nov 26, 2026
  3. mikolalysenko commented on Nov 26, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Four more sites of this defect, from the part the issue lists under "Not checked". Run with the binary built from main at cfc870f.

    How it was run. The repository's benchmark harness builds a hosted-mode project for each of 20 package managers and serves a local patch API for it (socket-patch-bench serve <pm>/hosted). I copied each project, planted the token S3CRETTOKEN0123456789 in one place per copy (a URL in a project file, a URL in a user-level file, or an environment variable), and ran 17 commands in a row over the copy: scan dry, wet, --json and --debug, list, vex, repair, rollback, rollback --json, remove <purl>, and scan --mode vendored and --mode agent. 103 of 2,269 runs print the token. No outside registry can be reached in these runs, so an undo that asks one fails, and that failure message is what the runs test.

    # The URL comes from Commands that print it Site in crates/socket-patch-core/src/
    5 distributionUrl in gradle/wrapper/gradle-wrapper.properties, when it names a distribution that is not a stock Gradle one and is not unpacked yet every scan, in agent, vendored and hosted mode, dry and wet; warnings[].detail under --json crawlers/gradle_cache.rs, init_scripts_for_build, lines 897 to 901
    6 a package source in nuget.config rollback, remove, and scan --mode vendored over the hosted pin; error under --json patch/redirect/upstream/nuget.rs, check_upstream_feed, lines 197 to 205
    7 the registry that uv.lock or pylock.toml records the same three patch/redirect/upstream/uv.rs, line 1358
    8 SOCKET_NPM_REGISTRY, SOCKET_PYPI_JSON_API or SOCKET_PACKAGIST_URL the same three, for all six npm-family projects, six of the seven Python ones (Hatch's undo asks no registry) and Composer patch/redirect/upstream/client.rs, get_json_authorized, lines 337 and 340

    The Cargo refusal of case 1 reproduced on this harness's project as well.

    5. Gradle wrapper. The note is printed on every scan of the project, not only on a refusal:

    $ socket-patch scan --mode agent --dry-run
    Note: the Maven local repository is scanned for this Gradle build because mavenLocal() could not be ruled out (init script wrapper distribution https://bot:S3CRETTOKEN0123456789@repo.corp.example/gradle-8.14.3-bin.zip (not unpacked under <home>/.gradle/wrapper/dists) could not be parsed)
    
    $ socket-patch scan --json        # warnings[]
          "code": "gradle_maven_local_undetermined",
          "detail": "the Maven local repository is scanned for this Gradle build because mavenLocal() could not be ruled out (init script wrapper distribution https://bot:S3CRETTOKEN0123456789@repo.corp.example/gradle-8.14.3-bin.zip (not unpacked under <home>/.gradle/wrapper/dists) could not be parsed)"
    

    The Gradle wrapper takes basic credentials in distributionUrl for a distribution server that needs them. I could not open Gradle's user guide from the sandbox to quote it.

    6. NuGet. The hosted scan succeeds (Switched 1 package to hosted patches; rewrote 2 files.). The undo then quotes every source that could serve the package:

    $ socket-patch rollback
    Error: Cannot restore pkg:nuget/daqu2.waab9@0.14.6 to its upstream registry entry: daqu2.waab9 resolves from nuget.org (https://api.nuget.org/v3/index.json), corp (https://bot:S3CRETTOKEN0123456789@repo.corp.example/nuget/v3/index.json) under nuget.config, not from nuget.org alone, so the original contentHash cannot be re-derived; restore it from version control instead (`git checkout -- nuget.config`)
    

    A source whose secret is a query value prints the same way: corp (https://nuget.corp.example/v3/index.json?token=S3CRETTOKEN0123456789). That is the third kind of credential utils/redact.rs lists.

    7. uv.lock and pylock.toml.

    $ socket-patch rollback
    Error: Cannot restore pkg:pypi/py-feesde4@7.7.4 to its upstream registry entry: pylock.toml: the lock's registry https://bot:S3CRETTOKEN0123456789@repo.corp.example/pypi.org/simple is not PyPI, so its release files cannot be re-derived; restore it from version control instead (`git checkout -- pylock.toml`)
    

    I did not check which tools write credentials into these two files.

    8. The mirror variables. The contract says of SOCKET_RUBYGEMS_URL that "Credentials in the URL are sent to the registry and never printed". Nine variables name a registry for the undo. In these runs eight of them put GET <url> in front of a failed request (no undo asked SOCKET_MAVEN_REGISTRY). Five print it redacted (vendor::registry_fetch::download redacts its errors, and the gem lookup redacts for itself):

    $ SOCKET_CRATES_INDEX=https://bot:S3CRETTOKEN0123456789@mirror.corp.example/x socket-patch rollback
    Error: Cannot restore pkg:cargo/dielnoli1-core@3.16.6 to its upstream registry entry: dielnoli1-core@3.16.6: GET https://<redacted>@mirror.corp.example/x/di/el/dielnoli1-core: error sending request for url (https://mirror.corp.example/x/di/el/dielnoli1-core): client error (Connect): …
    

    SOCKET_NUGET_URL, SOCKET_GOPROXY, SOCKET_GOSUMDB_URL and SOCKET_RUBYGEMS_URL print the same https://<redacted>@…. The three whose requests are JSON go through get_json_authorized, which prints the URL as it was given. reqwest's own half of the same line has already dropped the userinfo:

    $ SOCKET_NPM_REGISTRY=https://bot:S3CRETTOKEN0123456789@mirror.corp.example/x socket-patch rollback
    Error: Cannot restore pkg:npm/fefiba30@25.24.3 to its upstream registry entry: fefiba30@25.24.3: GET https://bot:S3CRETTOKEN0123456789@mirror.corp.example/x/fefiba30/25.24.3: error sending request for url (https://mirror.corp.example/x/fefiba30/25.24.3): client error (Connect): …
    

    SOCKET_PYPI_JSON_API (GET https://bot:…@mirror.corp.example/x/py-jowa10/6.2.8/json: …) and SOCKET_PACKAGIST_URL (GET https://bot:…@mirror.corp.example/x/p2/inact/zoka1.json: …) print the same shape.

    What was clean in these runs. Everything else the token was planted in:

    • Maven: a pom.xml repository, plugin repository and distributionManagement, a settings.xml mirror in the user home and under .mvn/, and .mvn/maven.config and jvm.config properties;
    • Gradle: a repository in build.gradle, in settings.gradle and in a user init.gradle, and gradle.properties;
    • NuGet: a user-level NuGet.Config, the source of a .nupkg.metadata, and RestoreSources in the project file;
    • Go: GOPROXY in the environment and in the go env -w file, and GOFLAGS;
    • Cargo: [source] replacement in the project's and the user's config.toml, [registries] in the project's, and a [patch] entry;
    • the npm family: .npmrc (registry URLs and an _authToken line), .yarnrc, .yarnrc.yml, bunfig.toml and vlt.json registries, and the https:// URLs already in package-lock.json, a classic yarn.lock and vlt-lock.json;
    • Python: pip.conf, --index-url lines, and index tables in pyproject.toml, uv.toml, Pipfile, pdm.toml and hatch.toml;
    • Ruby and Composer: a Gemfile source and the Gemfile.lock remote, .bundle/config mirrors, .gemrc, Composer repositories, auth.json, and the composer.lock dist and source URLs;
    • the environment: the package managers' own registry and token variables, and HTTPS_PROXY with credentials. SOCKET_MAVEN_REGISTRY was set too, but no undo in these runs asked it.

    Not checked: vendor --revert and the other undo commands over a package that was actually vendored. The harness serves hosted artifacts only, so every vendored run here stopped before it wrote a ledger.

    For the fix. These four fit the plan above without changing it: 6 and 7 are refusal text of the upstream restore (FormatResult::refuse), 8 is one transport that can redact its errors the way download does, and 5 is a discovery note. The harness makes the test cheap: one table of plants and commands, asserting that the token appears in neither stream.


    Generated by Claude Code

  4. added a commit that references this issue on Nov 26, 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:triagedarch-auditbugpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions