Repository navigation
fix: keep the API key out of error messages and tracebacks (1.3.2) - #21
Merged
Merged
Conversation
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.
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.
Connection errors, timeouts and request-encoding errors from
OddsAPIClientcarried the request URL, with theapiKeyquery parameter, in the SDK error message and in the chainedrequests/urllib3exception. Anyone pasting a traceback shared their key. Affects every release up to and including 1.3.1.Changes:
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 aiohttpInvalidURL, whose message reads a read-only property) is replaced by a maskedRedactedErrorstand-in.OddsAPIClient,AsyncOddsAPIClientandOddsStreamscrub 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 fromstr(),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, aiohttpClientResponseError, an invalid WebSocket URL a refused WebSocket handshake, websocketsInvalidHeader/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.