Repository navigation
fix(core): redact sensitive fields when a response fails to parse - #839
Open
mattespapier wants to merge 5 commits into
Open
mattespapier wants to merge 5 commits into
mattespapier wants to merge 5 commits into
Conversation
mattespapier
force-pushed
the
fix/redact-sensitive-parse-errors
branch
2 times, most recently
from
October 8, 2026 03:16
1d045ee to
ca9023f
Compare
A 2xx body for an operation whose output has a sensitive member reached the caller unredacted when it did not match the output schema. In strict mode, `<Sdk>ParseError.body` carried the raw text or the parsed JSON, so a response that drifted from the spec put the secret into an error that gets logged. In lenient mode, a non-JSON body (one cut off mid-secret, for example) came back as the success value. `hasSensitiveMember(ast)`, beside `wrapSensitive` in `protocol-rest`, reports whether any member reachable from an output is marked `SensitiveValue`. It looks inside map values too. For such outputs `makeRestProtocol` fails a non-JSON 2xx body in both modes and builds every parse error with `body: "[REDACTED]"`, the sentinel ACME and ZeroSSL already use; the cause stays the schema error. The whole body is withheld because in a mismatched body the secret may sit at a key the schema does not model. Outputs without sensitive members behave as before. Protocols that do not go through `makeRestProtocol` are unchanged.
`hasSensitiveMember` visited each list element but checked the `SensitiveValue` mark only on an object's members, so an output whose only secret is a list element (a stored header map typed `Record<string, Array<string>>` whose elements are marked) counted as not sensitive, and a parse failure reported its body unredacted. It now checks the mark on each list element too, as it does on a member or a map value. No generated output marks a list element today, so no SDK changes until the generator and `wrapSensitive` honor such a mark.
Stripe's hand-written protocol wires `validateResponse` itself, so the core fix does not reach it. A 2xx body for an output with a sensitive member (`CreateWebhookEndpoint`'s `secret`, `CreateEphemeralKey`'s `secret`) that did not match the schema put the secret into `StripeParseError.body` in strict mode, and a non-JSON body (one cut off mid-secret) came back as the success value in lenient mode. It now does what `makeRestProtocol` does: for an output where `hasSensitiveMember(outputAst)`, a non-JSON 2xx body fails in every mode and every parse error reports `body: "[REDACTED]"`. Outputs without sensitive members behave as before.
Fly.io's GraphQL and Sprites decoders wire `validateResponse` themselves, so the core fix does not reach them. A 2xx body for an output with a sensitive member (`addOn`'s `password` and `publicUrl`, `createOrganizationToken`'s `token`) that did not match the schema put the secret into `FlyIoParseError.body` in strict mode, and a non-JSON body (one cut off mid-secret) came back as the success value in lenient mode. Both now do what `makeRestProtocol` does: for an output where `hasSensitiveMember(outputAst)`, a non-JSON 2xx body fails in every mode and every parse error reports `body: "[REDACTED]"`. The Sprites token mint that runs before every Sprites operation but `createOrganizationToken` reported `json ?? text` when the reply carried no usable token, so a reply cut off mid-token leaked it from an ordinary call such as `deleteSprite`; it now always reports `"[REDACTED]"`, since its reply exists only to carry the token. Outputs without sensitive members behave as before.
Only core's REST protocol, Stripe and Fly.io fail a non-JSON 2xx body for an output with sensitive members; Azure, Coinbase, MongoDB Atlas, Slack, STACKIT, Supabase and ZeroSSL decode it themselves and still return it as text in lenient mode. The decoder comments now say what they do (fail a non-JSON body, withhold the body from parse errors) instead of claiming the body is never returned unredacted, which a secret under a map value still is on success.
mattespapier
force-pushed
the
fix/redact-sensitive-parse-errors
branch
from
October 9, 2026 18:23
ca9023f to
4db9f2b
Compare
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.
In strict mode, when a 2xx response doesn't match the spec,
<Sdk>ParseError.bodycarries the whole body, including fields the spec marks sensitive, and in the default lenient mode a body that isn't JSON comes back as the success value. Here is Polar'swebhooksGetWebhookEndpoint(itssecretis sensitive), a real call to the Polar sandbox through the real SDK, with the reply cut off mid-secretby a fetch wrapper on our side:{ - _tag: 'Success', - value: '{"created_at":"2026-10-09T15:46:04.941999Z",…,"secret":"<first half of the secret>' + _tag: 'Failure', + failure: { + _tag: 'PolarParseError', + body: '[REDACTED]', + cause: 'Invalid JSON response' + } }wrapSensitiveonly runs on the success value; the error carried the body as read, and a mismatched body may hold the secret at an unmodeled key, so the whole body is withheld.hasSensitiveMember(ast),makeRestProtocol's parse errors reportbody: "[REDACTED]"; others are unchanged.hasSensitiveMemberlooks inside map values and list elements, so a secret inside a map (Meilisearchgetembedders,*.apiKey) or a marked list element counts. No generated output marks a list element yet.validateResponsethemselves, do the same; Fly's Sprites token mint always reports"[REDACTED]".Each case below is a real call through the real SDK, with the reply changed on our side before the SDK reads it: cut off in the middle of the secret, or with one field given the wrong type. On
main:bodyholds that text;bodyholds the whole secret, which prints when the error is logged or serialized.On this branch the secret appears in none of them. A wrong type in lenient mode is unchanged (see "Not covered"). Tested on:
webhooksGetWebhookEndpoint,secret, on an endpoint created for the run and deleted after.getProjectBranchRolePassword,password.CreateWebhookEndpoint,secret(returned only at creation), each endpoint deleted after.addOnon a Fly Redis add-on,password, read once and replayed (the GraphQL decoder); one Sprites token minted bylistSprites, its mint reply replayed throughlistSprites(the token mint) andcreateOrganizationToken(the Sprites decoder),token.Not covered: the other protocols that wire
validateResponsethemselves (Azure, Coinbase, MongoDB Atlas, Slack, STACKIT, Supabase and ZeroSSL), AWS's own client, error responses (an HTTP error status, or a GraphQLerrorsreply), and debug HTTP logging. In lenient mode a sensitive member that arrives with the wrong type (Neon'spasswordas["…"]) is still returned as read, unwrapped, sincewrapSensitivewraps strings only. On success, a secret under a map value or in a marked list element is still returned as read, sincewrapSensitivewraps object members only. Fly's GraphQL decoder doesn't callwrapSensitiveon success, so a successfuladdOnreturnspasswordandpublicUrlas plain strings, onmainand here. Out of scope: thedistilled-sdkskill still says lenient mode returns a non-JSON body as text.On
main, 13 of the 14 new cases fail (6 of 7 in core, both in Stripe, all 5 in Fly.io); the 14th checks a matching body still succeeds with the member redacted.Checked:
pnpm vitest runon core, Stripe and Fly.io (792 pass; 778 onmain), the tests of the other seven packages above plus ACME, Polar, Neon, trigger.dev and Cloudflare (242 pass),format:check,lint,tsc -b --noCheck falseon the whole repository (0 errors).Related: #754's new
parseErrorcall inprotocol-rest.tsshould usehasSensitiveMember.