Skip to content

Preserve Azure authentication boundaries across transports - #3684

Open
apcha-oai wants to merge 3 commits into
mainfrom
apcha/azure-transport-compatibility
Open

Preserve Azure authentication boundaries across transports#3684
apcha-oai wants to merge 3 commits into
mainfrom
apcha/azure-transport-compatibility

Conversation

@apcha-oai

@apcha-oai apcha-oai commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Keep Azure authentication scoped to the original request origin across HTTP and Realtime connections. Supported HTTP clients remove the Azure API key when following an off-origin redirect, and async Realtime connections reject off-origin handshake redirects. Same-origin authentication and normal connection behavior remain intact.

The change is limited to Azure transport handling and focused synchronous/asynchronous coverage for stable and beta Realtime. No public API or dependency changes.

Review follow-up

The requested test logging-override cleanup is addressed by 6eb081861d715eee668cd46bffca44b3cd0227ec. It removes the unnecessary A002 suppression without changing runtime behavior. All 22 focused WebSocket redirect tests, Ruff, targeted Pyright, and git diff --check pass. Human re-review is requested; auto-merge remains disabled.

@apcha-oai
apcha-oai requested a review from a team as a code owner August 19, 2026 20:26
@openai-sdks

openai-sdks Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

OkTest Summary

237/237 SDK tests passed in 9.245s for Python SDK PR #3684.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 141ms
tests/chat-completions-create.test.ts ✅ Passed 203ms
tests/chat-completions-stream.test.ts ✅ Passed 98ms
tests/files-content-binary.test.ts ✅ Passed 153ms
tests/files-create-multipart.test.ts ✅ Passed 227ms
tests/files-list-pagination.test.ts ✅ Passed 132ms
tests/initialize-config.test.ts ✅ Passed 170ms
tests/instance-isolation.test.ts ✅ Passed 126ms
tests/models-list.test.ts ✅ Passed 215ms
tests/responses-background-lifecycle.test.ts ✅ Passed 144ms
tests/responses-body-method-errors.test.ts ✅ Passed 257ms
tests/responses-cancel-timeout.test.ts ✅ Passed 166ms
tests/responses-cancel.test.ts ✅ Passed 197ms
tests/responses-compact-retries.test.ts ✅ Passed 224ms
tests/responses-compact.test.ts ✅ Passed 205ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 91ms
tests/responses-create-advanced.test.ts ✅ Passed 161ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.177s
tests/responses-create-errors.test.ts ✅ Passed 142ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 95ms
tests/responses-create-retries.test.ts ✅ Passed 252ms
tests/responses-create-stream-failures.test.ts ✅ Passed 104ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 215ms
tests/responses-create-stream-wire.test.ts ✅ Passed 2.923s
tests/responses-create-stream.test.ts ✅ Passed 216ms
tests/responses-create-terminal-states.test.ts ✅ Passed 170ms
tests/responses-create-timeout.test.ts ✅ Passed 191ms
tests/responses-create.test.ts ✅ Passed 377ms
tests/responses-delete.test.ts ✅ Passed 190ms
tests/responses-input-items-errors.test.ts ✅ Passed 288ms
tests/responses-input-items-list.test.ts ✅ Passed 261ms
tests/responses-input-items-options.test.ts ✅ Passed 214ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 197ms
tests/responses-input-tokens-count.test.ts ✅ Passed 138ms
tests/responses-malformed-inputs.test.ts ✅ Passed 2.194s
tests/responses-not-found-errors.test.ts ✅ Passed 192ms
tests/responses-parse.test.ts ✅ Passed 273ms
tests/responses-retrieve-retries.test.ts ✅ Passed 264ms
tests/responses-retrieve.test.ts ✅ Passed 149ms
tests/responses-stored-method-errors.test.ts ✅ Passed 454ms
tests/retry-behavior.test.ts ✅ Passed 3.098s
tests/sdk-error-shape.test.ts ✅ Passed 255ms

View OkTest run #32309921996

SDK merge (3b1c71424fc6) · head (6eb081861d71) · base (1fc0a217047c) · OkTest (2b1bdfd25e98)

@apcha-oai
apcha-oai enabled auto-merge August 19, 2026 20:33

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The new HTTPX origin guard does not protect stable or beta async Azure Realtime connections. Both construct WebSocket connections directly with Azure api-key or bearer headers, and the supported websockets 15.0.1 client follows cross-origin handshake redirects while retaining those authentication headers. Two-server testing confirms both credential types are forwarded to the redirected origin, violating the same origin boundary this change establishes for HTTP. Reject cross-origin WebSocket redirects before reconnecting or strip all Azure authentication headers, and add stable/beta regressions for both API-key and bearer authentication.

Comment thread src/openai/lib/azure.py
self._azure_endpoint = httpx2.URL(azure_endpoint) if azure_endpoint else None

hooks = self._client.event_hooks["request"]
if _async_strip_azure_api_key_on_redirect not in hooks:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] This HTTP-only hook leaves stable and beta async Azure Realtime WebSockets unprotected. Supported websockets 15 follows cross-origin handshake redirects and reuses both api-key and Authorization headers; a real two-server reproduction confirms credential forwarding. Reject cross-origin WebSocket redirects or strip credentials before reconnecting, with coverage for both clients and auth methods.

@apcha-oai
apcha-oai disabled auto-merge August 19, 2026 21:05
@apcha-oai
apcha-oai requested a review from a team August 19, 2026 21:11

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent re-review confirms the prior High Azure Realtime redirect credential leak is fixed for stable/beta clients, API-key/bearer authentication, and supported websockets versions. One small required test cleanup remains: remove the newly introduced, avoidable A002 suppression.

self.end_headers()

@override
def log_message(self, format: str, *args: object) -> None: # noqa: A002

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Low] Remove the avoidable A002 suppression. This new test override does not need a parameter named format: def log_message(self, *_args: object, **_kwargs: object) -> None: preserves positional/keyword compatibility, keeps the no-op behavior, and passes Ruff without # noqa: A002. Please use that straightforward lint-compliant form.

@apcha-oai
apcha-oai enabled auto-merge August 19, 2026 22:39
@apcha-oai
apcha-oai disabled auto-merge August 19, 2026 22:40
@apcha-oai
apcha-oai requested review from a team and jbeckwith-oai August 19, 2026 22:41

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent two-pass security re-review confirms the prior High Azure Realtime credential leak is fixed: stable and beta asynchronous WebSockets reject cross-origin redirects before forwarding API keys or bearer tokens while preserving legitimate same-origin redirects across supported websockets versions. The requested A002 suppression is removed using the straightforward variadic no-op test override. Real-server regressions, substantive CI, and CodeQL pass; no actionable findings.

pull Bot pushed a commit to tooniez/openai-python that referenced this pull request Aug 19, 2026
## Summary

- Resolve one Azure authentication mode consistently for synchronous and
asynchronous clients. Explicit credentials take precedence over
credential environment variables; conflicting explicit modes raise the
existing `MutuallyExclusiveAuthError`.
- Preserve environment-only AD-token precedence, client-copy behavior,
and callable API-key refresh.
- Keep module-level explicit Azure configuration separate from
environment fallback, including import-time configuration and automatic
Azure selection.
- Add focused regressions for explicit and ambient credential selection,
client copies, HTTP and Realtime configuration, and callable keys.

No dependency or exported client API changes. This is independent of the
Azure redirect-transport changes in openai#3684.
@apcha-oai
apcha-oai added this pull request to the merge queue Aug 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 20, 2026
@apcha-oai
apcha-oai added this pull request to the merge queue Aug 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 20, 2026
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.

2 participants