rehearsal-report.sh leaks the full Claude OAuth token — ${tok:-EMPTY} expands to the whole secret in the auth-failed alert #159

Closed
opened 2026-09-21 04:52:54 +00:00 by matou-build-agent · 2 comments

Secret leak in rehearsal-report.sh — ${tok:-EMPTY} prints the whole Claude OAuth token

claude_auth_announce() (rehearsal-report.sh) builds its "CLAUDE AUTH FAILED"
alert label as:

(token ${tok:+${tok:0:14}…}${tok:-EMPTY})

${tok:-EMPTY} means "EMPTY if unset, otherwise the value" — so whenever a
token is set
the second expansion appends the entire Claude OAuth token
after its own 14-char redaction. The alert is posted to the drive issue, to
Mattermost, and to the executor log — so on any auth-failure alert every
consumer repo leaks its live CLAUDE_CODE_OAUTH_TOKEN[_B] in three places that
keep history.

It only ever fires on an auth failure, so it sat unseen until one was (falsely)
detected — Matou/idss #1672 fire 1, where account B's full token was posted.

Fix

Compute the display form ONCE into its own variable and let only that reach the
message:

local shown=EMPTY
[ -n "$tok" ] && shown="${tok:0:14}…"

and pin it in tests/rehearsal-report-test.sh with a fake token whose body must
never appear in anything posted (assert the 14-char prefix is present, the body
absent).

This is a straight port of the fix already landed in Matou/idss as bdb42ff6
(where the two files are vendored factory copies and the direct edit reds the
#571/ADR 0180 drift gate — the fix belongs HERE in the factory core). Landing it
here fixes the leak for every consumer repo on their next FACTORY_REF bump.

Related: Matou/idss #1683 (the drift this caused there), Matou/idss GOTCHAS #303
(the leak, idss-side), GOTCHAS #228 (the same "land upstream, re-vendor" rule for
this same file). The leaked account-B token still needs rotating (not owned here).

## Secret leak in `rehearsal-report.sh` — `${tok:-EMPTY}` prints the whole Claude OAuth token `claude_auth_announce()` (`rehearsal-report.sh`) builds its "CLAUDE AUTH FAILED" alert label as: ``` (token ${tok:+${tok:0:14}…}${tok:-EMPTY}) ``` `${tok:-EMPTY}` means "EMPTY **if unset**, otherwise the value" — so **whenever a token is set** the second expansion appends the *entire* Claude OAuth token after its own 14-char redaction. The alert is posted to the drive issue, to Mattermost, and to the executor log — so on any auth-failure alert every consumer repo leaks its live `CLAUDE_CODE_OAUTH_TOKEN[_B]` in three places that keep history. It only ever fires on an auth failure, so it sat unseen until one was (falsely) detected — Matou/idss #1672 fire 1, where account B's full token was posted. ## Fix Compute the display form ONCE into its own variable and let only that reach the message: ``` local shown=EMPTY [ -n "$tok" ] && shown="${tok:0:14}…" ``` and pin it in `tests/rehearsal-report-test.sh` with a fake token whose body must never appear in anything posted (assert the 14-char prefix is present, the body absent). This is a straight port of the fix already landed in Matou/idss as `bdb42ff6` (where the two files are vendored factory copies and the direct edit reds the #571/ADR 0180 drift gate — the fix belongs HERE in the factory core). Landing it here fixes the leak for every consumer repo on their next `FACTORY_REF` bump. Related: Matou/idss #1683 (the drift this caused there), Matou/idss GOTCHAS #303 (the leak, idss-side), GOTCHAS #228 (the same "land upstream, re-vendor" rule for this same file). The leaked account-B token still needs rotating (not owned here).
Author
Member

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.

Ruling: ready-for-agent. Why it's a two-way door: the fix is a
self-contained edit to one harness lib plus its test, revertible by a later
commit and provable by an existing test (this repo's offline suite, and the
new assertion the brief prescribes). Although this is a security ticket, the
code change narrows exposure (it stops a leak) rather than widening
security posture, so it is not on the one-way-door list. The one genuine
one-way-door residue — rotating the leaked account-B CLAUDE_CODE_OAUTH_TOKEN_B
— is explicitly out of scope here and "not owned here" (it belongs to the
credential owner, tracked idss-side), so it does not hold this fix at
ready-for-human. What proves it: the offline test suite
(tests/rehearsal-report-test.sh) plus the new fake-token assertion — prefix
present, secret body absent.

Verification (confirmed): the leak reproduces exactly.
claude_auth_announce() in rehearsal-report.sh builds its alert label as
(token ${tok:+${tok:0:14}…}${tok:-EMPTY}). With a token set, both expansions
fire — the :+ branch emits the 14-char redaction, and ${tok:-EMPTY} (value
if set, EMPTY only if unset) appends the entire token after it. Driving
it with a fake token renders (token sk-ant-oat01-S…sk-ant-oat01-SECRETBODY-…)
— the full secret. The proposed one-variable form renders (token sk-ant-oat01-S…). This alert is posted to the drive issue, Mattermost, and the
executor log, all of which keep history, so every consumer repo leaks its live
token on any auth-failure alert. It only fires on auth failure, which is why it
went unseen until idss #1672 fire 1.


Agent Brief

Category: bug
Summary: claude_auth_announce() in rehearsal-report.sh leaks the full
Claude OAuth token — ${tok:-EMPTY} appends the whole secret after its own
14-char redaction on every auth-failure alert.

Current behavior:
The alert label is composed as
(token ${tok:+${tok:0:14}…}${tok:-EMPTY}). Because ${tok:-EMPTY} substitutes
the value whenever tok is set (and only prints EMPTY when tok is unset),
a set token is emitted in full immediately after its 14-char prefix. The message
is posted to the rehearsal drive issue, to Mattermost, and to the executor log
— three history-keeping surfaces. Every consumer repo inherits this on its next
FACTORY_REF bump, so any auth-failure alert leaks that repo's live
CLAUDE_CODE_OAUTH_TOKEN / _B.

Desired behavior:
The alert shows only a bounded redaction of the token — the 14-char prefix
followed by an ellipsis when a token is present, and EMPTY when none is set.
The full token value must never reach the message string (and therefore never
reach the drive issue, Mattermost, or the log). All other content of the alert
(account, auth-regex match, token-source mechanism line, env-file pointer) is
unchanged.

Key interfaces:

  • The claude_auth_announce() function's display of the token. Compute the
    shown form once into its own local variable and let only that reach the
    message — e.g.:
    local shown=EMPTY
    [ -n "$tok" ] && shown="${tok:0:14}…"
    
    then interpolate $shown into the label. Do not leave any second expansion
    of the raw $tok in the message.
  • This is a straight port of the fix already landed in Matou/idss as
    bdb42ff6; the two files are vendored factory copies there and the fix
    belongs here in the factory core.

Acceptance criteria:

  • The auth-failed alert never contains the full token value: given a token
    set to a known fake, the rendered/posted alert contains the 14-char prefix
    but not the token body.
  • With no token set (tok unset/empty) the alert still reads EMPTY.
  • tests/rehearsal-report-test.sh is updated in the same commit (per
    CLAUDE.md's "every lib change updates its test") with a fake token whose
    body must never appear in anything posted: assert the 14-char prefix is
    present and the body is absent from the captured curl/Mattermost payloads.
  • The full offline suite passes:
    for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done
  • STATUS.md is updated in the same commit if this changes project state
    (a security fix landing that consumers inherit at their next pin), and
    docs/GOTCHAS.md gets the Symptom → Cause → Rule entry for this leak in
    the same commit (GOTCHAS #228 / idss GOTCHAS #303 are the cross-refs).

Out of scope:

  • Rotating the already-leaked account-B CLAUDE_CODE_OAUTH_TOKEN_B — a
    one-way-door credential action, not owned by this repo (tracked idss-side).
  • Any change to the alert's other fields (account name, auth-regex extraction,
    token-source mechanism sentence, env-file pointer).
  • Editing consumer repos or .sandcastle/* copies — the fix lands in the
    factory-core root file and reaches consumers via their next FACTORY_REF
    bump (pull-only; ADR 0001).
> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** **Ruling:** `ready-for-agent`. **Why it's a two-way door:** the fix is a self-contained edit to one harness lib plus its test, revertible by a later commit and provable by an existing test (this repo's offline suite, and the new assertion the brief prescribes). Although this is a *security* ticket, the code change **narrows** exposure (it stops a leak) rather than widening security posture, so it is not on the one-way-door list. The one genuine one-way-door residue — **rotating the leaked account-B `CLAUDE_CODE_OAUTH_TOKEN_B`** — is explicitly out of scope here and "not owned here" (it belongs to the credential owner, tracked idss-side), so it does not hold this fix at `ready-for-human`. **What proves it:** the offline test suite (`tests/rehearsal-report-test.sh`) plus the new fake-token assertion — prefix present, secret body absent. **Verification (confirmed):** the leak reproduces exactly. `claude_auth_announce()` in `rehearsal-report.sh` builds its alert label as `(token ${tok:+${tok:0:14}…}${tok:-EMPTY})`. With a token set, both expansions fire — the `:+` branch emits the 14-char redaction, and `${tok:-EMPTY}` (value if set, `EMPTY` only if *unset*) appends the **entire** token after it. Driving it with a fake token renders `(token sk-ant-oat01-S…sk-ant-oat01-SECRETBODY-…)` — the full secret. The proposed one-variable form renders `(token sk-ant-oat01-S…)`. This alert is posted to the drive issue, Mattermost, and the executor log, all of which keep history, so every consumer repo leaks its live token on any auth-failure alert. It only fires on auth failure, which is why it went unseen until idss #1672 fire 1. --- ## Agent Brief **Category:** bug **Summary:** `claude_auth_announce()` in `rehearsal-report.sh` leaks the full Claude OAuth token — `${tok:-EMPTY}` appends the whole secret after its own 14-char redaction on every auth-failure alert. **Current behavior:** The alert label is composed as `(token ${tok:+${tok:0:14}…}${tok:-EMPTY})`. Because `${tok:-EMPTY}` substitutes the *value* whenever `tok` is set (and only prints `EMPTY` when `tok` is unset), a set token is emitted in full immediately after its 14-char prefix. The message is posted to the rehearsal drive issue, to Mattermost, and to the executor log — three history-keeping surfaces. Every consumer repo inherits this on its next `FACTORY_REF` bump, so any auth-failure alert leaks that repo's live `CLAUDE_CODE_OAUTH_TOKEN` / `_B`. **Desired behavior:** The alert shows only a bounded redaction of the token — the 14-char prefix followed by an ellipsis when a token is present, and `EMPTY` when none is set. The full token value must never reach the message string (and therefore never reach the drive issue, Mattermost, or the log). All other content of the alert (account, auth-regex match, token-source mechanism line, env-file pointer) is unchanged. **Key interfaces:** - The `claude_auth_announce()` function's display of the token. Compute the shown form once into its own local variable and let only that reach the message — e.g.: ``` local shown=EMPTY [ -n "$tok" ] && shown="${tok:0:14}…" ``` then interpolate `$shown` into the label. Do not leave any second expansion of the raw `$tok` in the message. - This is a straight port of the fix already landed in `Matou/idss` as `bdb42ff6`; the two files are vendored factory copies there and the fix belongs here in the factory core. **Acceptance criteria:** - [ ] The auth-failed alert never contains the full token value: given a token set to a known fake, the rendered/posted alert contains the 14-char prefix but **not** the token body. - [ ] With no token set (`tok` unset/empty) the alert still reads `EMPTY`. - [ ] `tests/rehearsal-report-test.sh` is updated in the same commit (per CLAUDE.md's "every lib change updates its test") with a fake token whose body must never appear in anything posted: assert the 14-char prefix is present and the body is absent from the captured curl/Mattermost payloads. - [ ] The full offline suite passes: `for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done` - [ ] `STATUS.md` is updated in the same commit if this changes project state (a security fix landing that consumers inherit at their next pin), and `docs/GOTCHAS.md` gets the Symptom → Cause → Rule entry for this leak in the same commit (GOTCHAS #228 / idss GOTCHAS #303 are the cross-refs). **Out of scope:** - Rotating the already-leaked account-B `CLAUDE_CODE_OAUTH_TOKEN_B` — a one-way-door credential action, not owned by this repo (tracked idss-side). - Any change to the alert's other fields (account name, auth-regex extraction, token-source mechanism sentence, env-file pointer). - Editing consumer repos or `.sandcastle/*` copies — the fix lands in the factory-core root file and reaches consumers via their next `FACTORY_REF` bump (pull-only; ADR 0001).
Author
Member

Landed. PR #160 merged the fix into main (89b6bad), and the fix commit
142a3c10 sits on main's line branched off 41495283 so consumer repos still
pinned near there can adopt it without the full-main upgrade.

  • rehearsal-report.sh claude_auth_announce now computes shown=EMPTY; [ -n "$tok" ] && shown="${tok:0:14}…" and only $shown reaches the message — the full token can no longer expand into the alert.
  • tests/rehearsal-report-test.sh runs the reporter with a fake CLAUDE_CODE_OAUTH_TOKEN and asserts the body never reaches $CURL_LOG while the 14-char prefix still does.
  • Proof: reintroducing the leak line → test FAILs ("leaked the token body"); with the fix → PASS (50 cases).

Matou/idss #1683 has re-vendored its FACTORY_REF to 142a3c10 (drift gate
green). Leaked account-B token still needs rotating (out of scope here).

**Landed.** PR #160 merged the fix into `main` (`89b6bad`), and the fix commit `142a3c10` sits on `main`'s line branched off `41495283` so consumer repos still pinned near there can adopt it without the full-main upgrade. - `rehearsal-report.sh` `claude_auth_announce` now computes `shown=EMPTY; [ -n "$tok" ] && shown="${tok:0:14}…"` and only `$shown` reaches the message — the full token can no longer expand into the alert. - `tests/rehearsal-report-test.sh` runs the reporter with a fake `CLAUDE_CODE_OAUTH_TOKEN` and asserts the body never reaches `$CURL_LOG` while the 14-char prefix still does. - Proof: reintroducing the leak line → test FAILs ("leaked the token body"); with the fix → PASS (50 cases). Matou/idss #1683 has re-vendored its `FACTORY_REF` to `142a3c10` (drift gate green). Leaked account-B token still needs rotating (out of scope here).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/dev-factory#159
No description provided.