Skip to content

fix: redact credentials from SDK debug logs - #447

Merged
ismaelrumzan merged 2 commits into
mainfrom
fix/redact-debug-log-secrets
Nov 24, 2026
Merged

ismaelrumzan merged 2 commits into
mainfrom
fix/redact-debug-log-secrets

Conversation

@ismaelrumzan

@ismaelrumzan ismaelrumzan commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes Vercel security finding 01M7V6G0R1RSPX4T3Y2KKPZ5HK (webhook signing secret in debug logs).

Debug logger redaction

src/hooks/debug-logger.ts (hand-written) exports redactDebugLogger(logger), which wraps the caller's debugLogger:

  • name: value lines for authorization, cookie, set-cookie, proxy-authorization, and x-api-key become name: [REDACTED]. This covers request headers, response headers, and multipart fields.
  • Plain-object and array arguments, such as parsed JSON bodies, are copied. Any non-null value under a key ending in secret, token, password, apikey, or privatekey becomes [REDACTED], including numbers, arrays, and nested objects. Matching ignores case, -, and _.
  • SDK return values are unchanged.

Generated client wiring

src/lib/sdks.ts sets this.#logger = redactDebugLogger(this._options.debugLogger) in the ClientSDK constructor.

.speakeasy/patches/src/lib/sdks.ts.patch holds that two-line edit. Speakeasy re-applies it after every generation. If the generated context changes, generation fails with conflict markers.

Tests

tests/debug-logger-redaction.test.mjs runs vercel.webhooks.createWebhook through the built SDK with a stub fetcher and a capturing logger. It asserts:

  • the returned secret is intact
  • the log contains no API token or webhook secret
  • numeric, array, and nested-object values under secret-like keys are redacted
  • the patch file and the gen.yaml test script are present

.speakeasy/gen.yaml additionalScripts adds test:debug-logger and runs it from test. package.json matches.

Verification

npm test and npm run lint pass. The new test fails on main. Running speakeasy run with CLI 1.810.0 on a clean generated src/lib/sdks.ts re-applied the patch, and npm test passed on the regenerated tree.

code-review: 2 runs, 0 fixed, 2 declined, no blocker/high/medium open

  • Next nightly regen PR still contains redactDebugLogger in src/lib/sdks.ts (Generate workflow, after merge, does not gate merge)
  • Known gap: request bodies with secrets under generic keys, such as an environment variable's value, are still logged (follow-up, does not gate merge)

Reviewed with review-loop: 2 rounds with gpt-6.1-sol. Verdict: approved

🤖 Generated with Claude Code

When a caller passes `debugLogger`, `logRequest` and `logResponse` in the
generated `src/lib/sdks.ts` print every request header and every JSON
response body verbatim. That includes `authorization: Bearer <token>` on
every call and secrets returned in response bodies, such as the webhook
signing `secret` from `createWebhook` (Vercel security finding
01M7V6G0R1RSPX4T3Y2KKPZ5HK).

Mechanism: `src/hooks/debug-logger.ts` (hand-written, never generated)
exports `redactDebugLogger`, which wraps the caller's logger. Header and
multipart lines (`name: value` strings) for authorization, cookie,
set-cookie, proxy-authorization, x-api-key, or any secret-like name are
replaced with `name: [REDACTED]`. Plain-object and array arguments are
copied with string values under secret-like keys (suffix secret, token,
password, apikey, privatekey, ignoring case, `-` and `_`) replaced. The SDK's
return values are untouched; only what reaches the logger changes.

`src/lib/sdks.ts` is generated, so the two-line edit that applies the wrapper
is also stored as `.speakeasy/patches/src/lib/sdks.ts.patch`. Speakeasy
applies files in `.speakeasy/patches/` after every generation, so the nightly
regen keeps the redaction. If the generated context ever drifts, generation
fails with conflict markers instead of dropping the patch silently.

Tests: `tests/debug-logger-redaction.test.mjs` runs `createWebhook` through
the real SDK with a stub fetcher and a capturing logger. It failed before the
fix (the log contained the bearer token and the webhook secret) and passes
after. It also asserts the patch file and the gen.yaml test script exist, so
removing either fails CI. The script is added to gen.yaml additionalScripts
so regeneration keeps it in package.json.

Verified by running `speakeasy run` with CLI 1.810.0 (the version the
generation workflow uses) from a pristine generated `sdks.ts`: the patch was
re-applied, `debug-logger.ts` was kept, and `npm test` passed on the
regenerated tree.

Known gap: secrets sent in request bodies under generic keys (for example an
environment variable's `value`) are still logged.

Review: review-loop round 1 with gpt-6.1-sol, approved, no findings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ismaelrumzan
ismaelrumzan requested a review from a team as a code owner November 20, 2026 12:55
Speakeasy review feedback: `redactValue` only replaced string values under
secret-like keys, so `{ secret: 12345 }`, `{ token: ["t1", "t2"] }`, and
`{ clientSecret: { value: "..." } }` reached the logger unchanged. Arrays and
objects under those keys were walked recursively, but their elements and
nested keys did not match the key list, so they passed through.

Any non-null value under a key that ends in secret, token, password, apikey,
or privatekey is now replaced with `[REDACTED]`. Null and undefined still log
as-is so a missing field is visible.

Test: a new case in `tests/debug-logger-redaction.test.mjs` sends a response
with a numeric `secret`, an array `token`, and an object `clientSecret`
through `createWebhook`. It failed before this change (the numeric secret
appeared in the log) and passes now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ SDK Test Report: vercel — tests passed   View Report

@ismaelrumzan
ismaelrumzan merged commit df75f93 into main Nov 24, 2026
4 checks passed
@ismaelrumzan
ismaelrumzan deleted the fix/redact-debug-log-secrets branch November 24, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant