Fix TLS verify passthrough, POST replay, repr token leak, and unbounded pagination#90
Open
splch wants to merge 2 commits into
Open
Fix TLS verify passthrough, POST replay, repr token leak, and unbounded pagination#90splch wants to merge 2 commits into
splch wants to merge 2 commits into
Conversation
…ed pagination - Thread verify_ssl through to the socket-opening transports; httpx ignores verify= once a transport is injected, so a pinned SSLContext or private CA previously fell back to the system trust store silently. - Split the retry policy: idempotent methods keep status+exception retries, POST retries only pre-send connection failures and is never re-sent after a response, so a post-commit 429/5xx cannot duplicate a billable job or session (urllib3-style semantics). - Redact the default-headers dict from Client/AuthenticatedClient repr via a generator post-hook; the auth header is copied into _headers on first use, defeating the existing token repr=False redaction. - Bound cursor pagination: raise IonQError on a repeated cursor or when max_pages (default 10,000, None disables) is exceeded. - Normalize generated client.py EOF in a post-hook so pre-commit's end-of-file-fixer and the generated-code staleness check agree.
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.
Summary
Fixes four security findings in the transport and pagination layers:
verify_sslsilently ignored (CWE-295):IonQClientinjects a transport into the httpx clients, and httpx ignores itsverify=argument entirely once a transport is supplied; the retry transport's default inner transports were built against the system trust store.build_transport()now constructs the socket-openinghttpx.HTTPTransport/AsyncHTTPTransportwith the caller'sverify_ssl, so a pinnedssl.SSLContext, a private CA, orverify_ssl=Falseactually reaches the connections that open sockets (ionq_core/_transport.py,DualTransport).POSTtoallowed_methods, so a 429/5xx received after the server committed (e.g. a load-balancer 503 post-commit) transparently re-sentcreate_job/clone_job/create_session/end_session, duplicating billable work. The transport now runs twoRetryTransportpolicies: idempotent methods keep the existing status + exception retries, while POST retries only pre-send failures (ConnectError,ConnectTimeout,PoolTimeout) and is never re-sent after any response. This matches urllib3/requests semantics: connection-phase errors are retried for all methods because the request never left the client; received responses never trigger a re-send of a non-idempotent request.repr()after first request (CWE-532):get_httpx_client()/get_async_httpx_client()copyAuthorization: apiKey <token>into_headers, which attrs included in__repr__despitetokenbeingrepr=False. Fixed with a generator post-hook (the same mechanism as the existingtokenredaction) so it survives regeneration;client.pyis regenerated in this PR.iter_jobs/aiter_jobs/iter_session_jobs/aiter_session_jobsfollowed the server-controllednextcursor forever. They now raiseIonQErrorwhen the server echoes back the cursor it was just sent, or when the page count exceeds the newmax_pagesargument (default 10,000;Nonedisables the cap).One supporting change: a post-hook normalizes
client.pyto end with a single newline. ruff-format excludesclient.py, so the raw generator output ends with a blank line that pre-commit'send-of-file-fixerstrips - without this, thegenerated.ymlstaleness check and pre-commit disagree about the same bytes. Note for a follow-up: ~50 generated files underionq_core/models/andionq_core/api/have the same latent EOF quirk; this PR only normalizes the file it already touches.Test plan
ConnectError/ConnectTimeout/PoolTimeout, POST does not retryReadTimeout/RemoteProtocolError, GET keeps status and read-timeout retries, plus async variants andmax_retries=0.verify_ssltests assert a caller'sssl.SSLContextis the exact object on the innermost sync and async connection pools (identity check),verify_ssl=FalseyieldsCERT_NONE, and the default yieldsCERT_REQUIRED- both at thebuild_transport()level and end-to-end throughIonQClient(...).repr(client)afterget_httpx_client()/get_async_httpx_client()no longer contains the token (the pre-existing test only checked a freshly constructed client).max_pagesenforcement (sync/async, jobs and session jobs), and themax_pages=Noneopt-out.uv run pytest: 275 passed, 100% branch coverage on hand-written code.uv run ruff check,uv run ruff format --check,uv run ty check ionq_core/, and pre-commit on the changed files all pass.generated.ymlcheck.Important
Most code in
ionq_core/is auto-generated and overwritten on regeneration.See CONTRIBUTING.md for which files are safe to edit.