Skip to content

mcpx(mcpauth): literal credentials containing $ are silently rewritten by expansion — $2 and $$ are eaten, $HOME is spliced in, and the phantom name refuses the server as 'not set' #1662

Closed

Description

@dezren39

Summary

mcpauth expands every credential field with os.Expand, so a literal credential containing a $ segment is silently rewritten: $2, $$, $5 are eaten as special shell variables, and $NAME splices the daemon's own environment into the credential. Literal credentials are an expected shape in these fields — redactRef exists precisely because a config may hold a literal secret — yet any literal password/token/value containing $ followed by a letter, digit or shell-special character is corrupted, and the phantom variable name it invents lands in Missing, which the pool turns into a hard refusal naming a variable nobody referenced.

Evidence (verified on main 7eb930a, this run)

  • pkgs/mcpx/internal/mcpauth/mcpauth.go:122-135 — expand runs os.Expand(v, …) unconditionally and appends the referenced name to out.Missing whenever the looked-up value is empty. It is applied to bearer Token (:166), basic Username/Password (:172), header Value (:182), query ParamValue (:193) and every non-passthrough Env value (:148).
  • Go's os.Expand semantics, read this run in the installed stdlib (~/tools/go/src/os/env.go:16-109): getShellName treats a digit or one of * # $ @ ! ? - as a complete special-variable name, and otherwise consumes the longest [A-Za-z0-9_] run. So in a literal:
    • hunter$2 → hunter, with phantom variable 2 reported missing;
    • pa$$word → paword, with phantom variable $ reported missing;
    • cost is $5 (an env value) → cost is , phantom 5;
    • s3cret$HOME → s3cret + the daemon's actual $HOME value spliced in — no Missing entry, no error: the server silently receives a different password than the one configured and returns a 401 nobody can interpret, the exact failure this package's header says it exists to prevent.
  • The phantom Missing is not advisory: internal/pool/pool.go resolveAuth (:766-777) refuses the server outright when len(r.Missing) > 0, with auth: 2 not set in the daemon's environment — naming a "variable" that appears nowhere in the user's config.
  • Literals are expected in these fields: redactRef (mcpauth.go:226-237) redacts any value that is not a $-reference as "(literal, redacted)", i.e. Describe is built for literal secrets sitting in Token/Password/Value. The documented expansion contract names only the braced form: Token's doc (:34-35) says "Expanded, so ${GITHUB_TOKEN} works". No doc found this run states that a bare $ in a literal is also a reference, and there is no escape mechanism.
  • Existing tests cover only the ${VAR} forms (mcpauth_test.go:14, :26, :79, :83; resolvewith_test.go:19, :38) — no literal containing $ is tested.

Disclosure: the prepared probe test (in the goal's hidden_files, probe-2026-10-28-laneB-authexpand/probe_laneb_test.go) was NOT executed this run — the laptop probe host was unreachable for the whole run (the tailnet SSH tunnel closes immediately; the same outage the previous three creator runs hit) and probes are never compiled on the sandbox. The verdicts above follow deterministically from os.Expand's source in the installed Go tree (cited above) traced through expand; triage should run the probe first and correct this evidence if any traced verdict differs.

Why it matters

Passwords and opaque tokens containing $ are ordinary. Today such a credential either (a) refuses the server before any request with an error naming a phantom variable (2, $, 5), sending the user hunting for a config entry that does not exist, or (b) worse, when the invented name happens to be set in the daemon's environment ($HOME, $USER, $PATH…), silently sends a different credential than configured — splicing daemon environment values into a secret and producing an undebuggable 401. Both outcomes violate the package's stated purpose: report credential problems "before a request rather than as a 401" (mcpauth.go:99-101).

Acceptance criteria

  • A literal credential containing $ reaches the transport byte-for-byte as configured: regression tests for at least the $<digit>, $$, and $NAME-that-is-set shapes across basic password, bearer token and an env value (run the prepared probe first and correct the issue's evidence if any traced verdict differs).
  • The documented ${VAR} reference form — and any bare-$VAR form triage decides to keep supporting — still expands, and a genuinely referenced unset variable is still reported in Missing (existing mcpauth tests pass unchanged, or are amended only where triage pins a deliberate contract change).
  • The expansion contract is written down where a config author will find it (the Auth field docs and/or the package doc): which shapes are references, how a literal $ is written, and what Missing means.
  • No phantom names in Missing: every name it reports is a reference the config author actually wrote in a recognised reference shape.
  • Full existing internal/mcpauth suite (and the pool auth tests, internal/pool/auth_test.go) pass on laptop or CI.

Activity

  1. added
    kind/bug
    task/triage
    status/needs-triage
    source/creator
    priority/normal
    queue/queued
    app/mcpx
    effort/s
    on Oct 28, 2026
  2. dezren39 commented on Oct 28, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (lane B)
    • Session / ID: new-issue-creator-code-b, run 2026-10-28 06:50 CDT
    • Found via: filed this run
    • Task: Triage the mcpauth literal-expansion defect: os.Expand rewrites literal credentials containing $ segments (phantom Missing names refuse the server via pool.resolveAuth; a set $NAME is silently spliced into the credential). Run the prepared probe first (hidden_files probe-2026-10-28-laneB-authexpand) and correct the evidence if any traced verdict differs — the probe was not executed this run because the laptop probe host was unreachable and probes are never compiled on the sandbox; verdicts were traced through the installed Go stdlib's os/env.go source.
    • Expectation: effort/s — literal credentials pass through byte-for-byte, documented ${VAR} references keep working, expansion contract documented; done when the acceptance criteria on the issue hold.
    • Links: queue packet packet-1662.json (repo-health-code-pilot, triage)
  3. added
    work/assigned
    queue/claimed
    status/in-progress
    and removed
    status/needs-triage
    queue/queued
    on Oct 31, 2026
  4. 22 remaining items

  5. added
    queue/parked
    status/parked
    queue/claimed
    status/in-progress
    and removed
    status/in-progress
    queue/claimed
    status/parked
    queue/parked
    on Oct 31, 2026
  6. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up (resume)

  7. added a commit that references this issue on Oct 31, 2026
  8. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

  9. removed
    status/in-progress
    queue/claimed
    work/assigned
    on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/mcpxeffort/skind/bugpriority/normalsource/creatortask/triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions