Repository navigation
Description
Verified against (commit SHA or released version)
commit 988c035 (main HEAD; testsprite --version -> 0.14.0)
Discord Username / User ID
sati1325
What does this improvement do?
When the API returns an error envelope whose message/nextAction prose echoes the rejected request, the bearer token inside is printed unredacted in both text and --output json modes — while the same token inside details does get redacted. src/lib/redact.ts documents the value-based Bearer <token> scan specifically for "a bearer token embedded in server/error prose (e.g. inside a free-form message/nextAction string)", but redactDeep is only ever applied to envelope.details, never to message/nextAction. A related gap: a secret-named key whose value is an array of strings (e.g. set-cookie: [...]) skips the blanking because the key match requires typeof v === 'string', so cookie strings leak element-wise.
Repro (local fake API; no real credentials): serve HTTP 403 with
{"error":{"code":"AUTH_FORBIDDEN","message":"Upstream rejected Authorization: Bearer eyJhbGci9.sig4567","nextAction":"Rotate Bearer eyJhbGci9.sig4567 now","requestId":"req_1","details":{"set-cookie":["sid=s3cr3tSessionValue; HttpOnly"],"note":"Bearer eyJhbGci9.sig4567"}}}
then TESTSPRITE_API_KEY=sk-x testsprite --endpoint-url http://127.0.0.1:48123 auth whoami.
Actual: Error: Upstream rejected Authorization: Bearer eyJhbGci9.sig4567 (text), "message": "...Bearer eyJhbGci9.sig4567" + same in nextAction (JSON), and details["set-cookie"] prints sid=s3cr3tSessionValue verbatim — while details.note correctly shows Bearer [REDACTED].
Expected: Bearer [REDACTED] in message/nextAction too, and [REDACTED] for the set-cookie array members.
Real-world impact: server error prose routinely echoes the rejected Authorization header; the unredacted token lands in terminal scrollback, CI logs, telemetry, and pasted bug reports.
Details / implementation notes
Root cause: ApiError's constructor (src/lib/errors.ts) applies redactDeep only to envelope.details; super(envelope.message, ...) and this.nextAction = envelope.nextAction store the raw strings, and every render path (Error: ${err.message} text, the nextAction line, the JSON error envelope) reads them as-is. In src/lib/redact.ts, the isSecretKey(key) gate blanks only typeof v === 'string' values, so arrays under set-cookie/authorization-style keys walk their elements through the bearer-scan instead of replacing them.
Fix: run redactDeep on envelope.message, envelope.nextAction (and the preserved serverNextAction) at the same single construction point the file already advertises ("Redact at the single point every ApiError is constructed"), and treat a secret-keyed array's string members as redactable in redact.ts. Tests extend redact.spec.ts (array under secret key) and errors.test.ts (bearer in message/nextAction prose); verified locally — after the fix the repro prints Bearer [REDACTED] in all three places.
A PR with the fix + regression tests will follow referencing this issue.
Confirmations
- I have searched existing issues and this is not a duplicate.
- I have provided my Discord identity above for reward coordination.
Activity
fyZhang66 commentedon Oct 22, 2026
Thanks @Satianurag. The CLI only talks to our API, and its error messages never echo the request's credentials, so this doesn't happen in practice. Closing as not planned.