Repository navigation
fix: keep the API key out of error messages and causes (1.6.3) - #24
Merged
Merged
Conversation
Network errors from fetch implementations that quote the request URL, error bodies that echo it, and WebSocket construction errors put the apiKey query parameter into the SDK error. Mask the key and key-like query parameters or headers in messages, stacks and bodies, and attach the underlying error as a masked cause.
…adable Copy causes as plain Error objects instead of prototype clones, so a native DOMException stays readable. Mask plain-object and array values inside causes, reduce other objects to their type name, handle cycles, and replace anything past the depth limit with a placeholder.
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.
The key travels as the
apiKeyquery parameter. Afetchimplementation that quotes the request URL in its errors (for examplenode-fetch:request to https://...?apiKey=... failed), an error body that echoes the URL, or a WebSocket that cannot be created (wsthrowsInvalid URL: <url with key>) put the key into the SDK error and intoerrorlistener payloads. The built-in Nodefetchdoes not quote the URL, so the default setup was not affected. Affects 1.6.2 and earlier.Changes:
src/redact.ts: masks the key (raw and URL-encoded) and any key-like query parameter or header as***;redactErrorbuilds a plainErrorcopy (samename,code,errno,syscall) with message, stack, property names and values, symbols and the wholecausechain masked; credential fields are masked by name, other class instances are reduced to their type name, cycles are handled and chains past the depth limit end in a placeholder.NetworkError/TimeoutErrormessages and HTTP error bodies are masked, and both errors now carry the underlying error as a maskedcause.OddsWebSocketmasks construction failures andonerrortext; non-SDK errors are wrapped in anOddsWebSocketErrorwith a maskedcause.test/redaction.test.mjs: the key is absent frommessage,stack,bodyandutil.inspect(cause chain included) for a refused connection, a URL-quoting fetch error, a timeout, a 401 and a 502 body echoing the URL, a JSON parse error, a WebSocket that cannot be created a WebSocket error event, plain-object/deep/cyclic causes, a native AbortError cause, credential fields and URL-keyed properties. The server message is still extracted when the body contains anapiKeyfield.