Repository navigation
fix: redact credentials from SDK debug logs - #447
Merged
Merged
Conversation
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>
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>
Contributor
|
✅ SDK Test Report: vercel — tests passed View Report |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes Vercel security finding
01M7V6G0R1RSPX4T3Y2KKPZ5HK(webhook signing secret in debug logs).Debug logger redaction
src/hooks/debug-logger.ts(hand-written) exportsredactDebugLogger(logger), which wraps the caller'sdebugLogger:name: valuelines forauthorization,cookie,set-cookie,proxy-authorization, andx-api-keybecomename: [REDACTED]. This covers request headers, response headers, and multipart fields.secret,token,password,apikey, orprivatekeybecomes[REDACTED], including numbers, arrays, and nested objects. Matching ignores case,-, and_.Generated client wiring
src/lib/sdks.tssetsthis.#logger = redactDebugLogger(this._options.debugLogger)in theClientSDKconstructor..speakeasy/patches/src/lib/sdks.ts.patchholds 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.mjsrunsvercel.webhooks.createWebhookthrough the built SDK with a stub fetcher and a capturing logger. It asserts:secretis intact.speakeasy/gen.yamladditionalScriptsaddstest:debug-loggerand runs it fromtest.package.jsonmatches.Verification
npm testandnpm run lintpass. The new test fails onmain. Runningspeakeasy runwith CLI 1.810.0 on a clean generatedsrc/lib/sdks.tsre-applied the patch, andnpm testpassed on the regenerated tree.code-review: 2 runs, 0 fixed, 2 declined, no blocker/high/medium open
redactDebugLoggerinsrc/lib/sdks.ts(Generate workflow, after merge, does not gate merge)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