Skip to content

fix: keep the API key out of error messages and causes (1.6.3) - #24

Merged
odds-api-io merged 5 commits into
mainfrom
fix/redact-api-key
Nov 26, 2026
Merged

odds-api-io merged 5 commits into
mainfrom
fix/redact-api-key

Conversation

@odds-api-io

@odds-api-io odds-api-io commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

The key travels as the apiKey query parameter. A fetch implementation that quotes the request URL in its errors (for example node-fetch: request to https://...?apiKey=... failed), an error body that echoes the URL, or a WebSocket that cannot be created (ws throws Invalid URL: <url with key>) put the key into the SDK error and into error listener payloads. The built-in Node fetch does not quote the URL, so the default setup was not affected. Affects 1.6.2 and earlier.

Changes:

  • New src/redact.ts: masks the key (raw and URL-encoded) and any key-like query parameter or header as ***; redactError builds a plain Error copy (same name, code, errno, syscall) with message, stack, property names and values, symbols and the whole cause chain 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/TimeoutError messages and HTTP error bodies are masked, and both errors now carry the underlying error as a masked cause.
  • OddsWebSocket masks construction failures and onerror text; non-SDK errors are wrapped in an OddsWebSocketError with a masked cause.
  • test/redaction.test.mjs: the key is absent from message, stack, body and util.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 an apiKey field.
  • Release 1.6.3 (version, CITATION, README, changelog).

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.
@odds-api-io
odds-api-io merged commit 6e7da39 into main Nov 26, 2026
4 checks passed
@odds-api-io
odds-api-io deleted the fix/redact-api-key branch November 26, 2026 08:34
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