Repository navigation
FIX: Send the configured headers with RealtimeTarget's websocket - #4255
Merged
hannahwestra25 merged 1 commit intoNov 23, 2026
Merged
Conversation
RealtimeTarget documents a headers parameter, and like the other OpenAI targets it also reads OPENAI_ADDITIONAL_REQUEST_HEADERS, but they were never passed to the realtime connection, so the websocket handshake left them out. A realtime endpoint behind a gateway that needs its own header couldn't be reached. Pass the headers to client.realtime.connect as extra_headers. Unlike the client's default_headers, these reach the handshake in every openai 3.x release. Signed-off-by: NNIIOVO <haimingni44@gmail.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A critical credential leak allows a non-admin API caller who supplies an API key but omits headers to forward server-configured gateway credentials to a caller-controlled endpoint.
1 open issue
What changed in this PR
This PR addresses #4254 by forwarding configured headers to RealtimeTarget’s WebSocket handshake, enabling PyRIT to connect through gateways that require custom headers.
Changes:
- Pass resolved headers to
client.realtime.connectviaextra_headers. - Add a configured-header regression test and update the existing connection assertion.
| File | Description |
|---|---|
tests/unit/prompt_target/target/test_realtime_target.py |
Verify configured headers are passed to the SDK connection call. |
pyrit/prompt_target/openai/openai_realtime_target.py |
Forward resolved headers when opening a realtime connection. |
Review effort: Balanced
hannahwestra25
approved these changes
Nov 23, 2026
hannahwestra25
left a comment
Collaborator
There was a problem hiding this comment.
thanks for contributing!
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.

Description
RealtimeTargetnever passed itsheaders(orOPENAI_ADDITIONAL_REQUEST_HEADERS) to the realtime connection, so the websocket handshake left them out. This passes them toclient.realtime.connectasextra_headers.Fixes #4254
extra_headers=self._headerstoclient.realtime.connectin_connect_async. Unlike the client'sdefault_headers, these reach the handshake in every openai 3.x release (3.0.0 doesn't adddefault_headersthere).connect, and update the existing connect test.With a local websocket server and
headers='{"X-Gateway-Key": "gateway-key"}', the handshake didn't includeX-Gateway-Keybefore and does after.