Skip to content

fix: keep the API key out of error messages and tracebacks (1.3.2) - #21

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

odds-api-io merged 4 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

Connection errors, timeouts and request-encoding errors from OddsAPIClient carried the request URL, with the apiKey query parameter, in the SDK error message and in the chained requests/urllib3 exception. Anyone pasting a traceback shared their key. Affects every release up to and including 1.3.1.

Changes:

  • New odds_api/_redact.py: masks the key (raw and URL-encoded), any key-like query parameter or header, and credential fields in mappings as ***. Each exception in the chain is scrubbed in place (args, every instance attribute and slot, __notes__, __cause__/__context__). Objects an exception holds (prepared requests, responses, connection pools) are replaced by masked shallow copies, so live transport state such as proxy headers is never modified. An exception that still shows the key afterwards (for example aiohttp InvalidURL, whose message reads a read-only property) is replaced by a masked RedactedError stand-in.
  • OddsAPIClient, AsyncOddsAPIClient and OddsStream scrub the underlying exception and the SDK error (including HTTP error bodies that echo the URL) before raising. The original exception stays chained as __cause__, masked.
  • tests/test_redaction.py: asserts the key is absent from str(), repr(), args, URL attributes and the full formatted traceback for a refused connection, connect and read timeouts, HTTP 401/502 bodies echoing the URL, an invalid JSON request body, async connection/timeout/HTTP errors, aiohttp ClientResponseError, an invalid WebSocket URL a refused WebSocket handshake, websockets InvalidHeader/InvalidHeaderValue/InvalidURI, shared and nested exceptions, and that live transport objects are left untouched. A recursive check walks every attribute of every exception in the chain.
  • Release 1.3.2 (version, CITATION, README, changelog).

Connection errors, timeouts and request-encoding errors from the sync
client carried the request URL, including the apiKey query parameter,
in the SDK error and in the chained requests/urllib3 exceptions.

Mask the key and key-like query parameters or headers in every error
the SDK raises, in its chained exceptions and in WebSocket refusals.
…g in place fails

Scrub all instance attributes and slots of exceptions and the objects
they hold (response bodies, headers, header values), not a fixed list,
and replace an exception that still shows the key, such as one whose
message reads a read-only property, with a masked stand-in. Raise
WebSocket failures outside the except block so the unmasked original
is never attached as __context__.
Objects held by an exception, such as a connection pool with proxy
headers or a prepared request, may still be used by the session.
Replace the exception's reference with a masked shallow copy instead of
modifying the original.
@odds-api-io
odds-api-io merged commit b96a7ab into main Nov 26, 2026
3 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