Repository navigation
docs(server): ctx_metadata credential-leak guidance (#1343) - #1400
Merged
Merged
Conversation
Closes the documentation half of #1343 — the "what goes in ctx_metadata and what doesn't" guide adopters need to avoid embedding credentials in the framework's adopter-internal bag. The wire-strip behavior already exists; this PR documents WHY it isn't enough and the recommended re-derive-per-request pattern. Three leak surfaces beyond the wire response: 1. Adopter-generated error messages (`JSON.stringify(account)` in a throw) 2. Info-level structured logs that serialize the resolved Account 3. Heap dumps and process inspection Recommendation: keep upstream IDs in `ctx_metadata`, put bearers on `Account.authInfo` (which the framework round-trips through `refreshToken`) or in your own per-principal token cache. What ships: - `docs/guides/CTX-METADATA-SAFETY.md` — full guide with safe / unsafe field lists, leak-surface walkthrough, recommended re-derive pattern, forward-compat note - JSDoc warning on `Account.ctx_metadata` (account.ts) pointing to the guide and naming the alternative (`authInfo`) - Cross-references from `CLAUDE.md` and `AGENTS.md` so AI agents scaffolding new platforms see the warning before they reach for `ctx_metadata.accessToken` - Sanity test asserting the wire-strip works for `toWireAccount` The optional Zod / standard-schema enforcement piece (Stage 2 of the issue) is deferred — adopter ergonomics for the docs side land first; the schema-driven structural redaction would be a separate, larger PR that wires into the logger seam. Test-only behavior change (JSDoc + sanity test) — empty changeset. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 of 4 tasks
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.
Summary
Closes the documentation half of #1343 — the "what goes in
ctx_metadataand what doesn't" guide that adopters need to avoid embedding credentials in the framework's adopter-internal bag. The wire-strip behavior already exists; this PR documents why it isn't enough and the recommended re-derive-per-request pattern.Problem
ctx_metadatais the framework's adopter-internal opaque bag on everyDecisioningPlatformresource. The framework strips it from wire responses to buyers. But the strip-on-wire is necessary, not sufficient — three leak surfaces persist:throw new Error(\failed for ${JSON.stringify(account)}`)puts everyctx_metadatafield into the error, which then flows to logs unconditionally and to the buyer whenexposeErrorDetails: true`.logger.info('resolving', { account: ctx.account })serializes the whole object verbatim into Datadog / CloudWatch / wherever your pipeline forwards.The framework's
redactCredentialPatternsis pattern-based whack-a-mole; it catchesBearer <token>shapes in messages but can't see into aJSON.stringify(account)blob whose key happens to beaccessToken.What ships
docs/guides/CTX-METADATA-SAFETY.md— full guide with safe / unsafe field lists, the three leak-surface walkthrough, recommended re-derive pattern, forward-compat noteAccount.ctx_metadata— points to the guide and names the alternative (Account.authInfofor credentials, framework round-trips it viarefreshToken)CLAUDE.mdandAGENTS.md— AI agents scaffolding new platforms see the warning before they reach forctx_metadata.accessTokenctx_metadatainto a response shapeDeferred
The optional Zod / standard-schema enforcement piece (the original issue's Stage 2) is deferred — schema-driven structural redaction would be a separate, larger PR that wires into the logger seam. The docs side lands first since it's high-leverage and zero-blast-radius.
Test plan
test/server-decisioning-ctx-metadata-strip.test.jspassnpm run build:libcleannpm run format:checkclean🤖 Generated with Claude Code