Skip to content

FIX: Send the configured headers with RealtimeTarget's websocket - #4255

Merged
hannahwestra25 merged 1 commit into
microsoft:mainfrom
nniiovoo:fix/realtime-target-headers
Nov 23, 2026
Merged

hannahwestra25 merged 1 commit into
microsoft:mainfrom
nniiovoo:fix/realtime-target-headers

Conversation

@nniiovoo

Copy link
Copy Markdown
Contributor

Description

RealtimeTarget never passed its headers (or OPENAI_ADDITIONAL_REQUEST_HEADERS) to the realtime connection, so the websocket handshake left them out. This passes them to client.realtime.connect as extra_headers.

Fixes #4254

  • Pass extra_headers=self._headers to client.realtime.connect in _connect_async. Unlike the client's default_headers, these reach the handshake in every openai 3.x release (3.0.0 doesn't add default_headers there).
  • Add a test that a configured header is passed to connect, and update the existing connect test.

With a local websocket server and headers='{"X-Gateway-Key": "gateway-key"}', the handshake didn't include X-Gateway-Key before and does after.

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>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 22:03

Copilot AI 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.

🟡 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.connect via extra_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 hannahwestra25 self-assigned this Nov 20, 2026

@hannahwestra25 hannahwestra25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks for contributing!

@hannahwestra25
hannahwestra25 added this pull request to the merge queue Nov 23, 2026
Merged via the queue into microsoft:main with commit 372d304 Nov 23, 2026
64 of 66 checks passed
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.

BUG: RealtimeTarget doesn't send its configured headers

3 participants