Skip to content

fix(security): authenticate WebSockets outside URLs - #4279

Merged
simonrosenberg merged 4 commits into
mainfrom
fix-websocket-auth-frame
Jul 28, 2026
Merged

simonrosenberg merged 4 commits into
mainfrom
fix-websocket-auth-frame

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Remove session_api_key from Python SDK WebSocket URLs.


AGENT:

Why

Session API keys in WebSocket query strings are copied into reverse-proxy and access logs. Production log review confirmed credential-bearing event-socket URLs.

Summary

  • Remove session_api_key from Python SDK WebSocket URLs.
  • Send the existing first-message auth payload immediately after connection.
  • Verify the URL is clean and the auth payload is the first client frame.

Issue Number

N/A

How to Test

  • uv run pytest tests/sdk/conversation/remote/test_websocket_client.py tests/agent_server/test_agent_server_wsproto.py::test_agent_server_websocket_first_message_auth_accepted -q
    • 10 passed.
    • This covers both the updated client frame and a real agent-server WebSocket accepting first-message authentication.
  • uv run pre-commit run --files openhands-sdk/openhands/sdk/conversation/impl/remote_conversation.py tests/sdk/conversation/remote/test_websocket_client.py
    • All hooks passed.

Video/Screenshots

N/A. This is a wire-protocol security change.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

Agent-server first-message authentication is already available on main from #2790. The server retains its deprecated query fallback for older clients.


Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:0a7e7ea-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-0a7e7ea-python \
  ghcr.io/openhands/agent-server:0a7e7ea-python

All tags pushed for this build

ghcr.io/openhands/agent-server:0a7e7ea-golang-amd64
ghcr.io/openhands/agent-server:0a7e7ea0234f9fd69c28814dd363e863e63683fe-golang-amd64
ghcr.io/openhands/agent-server:fix-websocket-auth-frame-golang-amd64
ghcr.io/openhands/agent-server:0a7e7ea-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:0a7e7ea-golang-arm64
ghcr.io/openhands/agent-server:0a7e7ea0234f9fd69c28814dd363e863e63683fe-golang-arm64
ghcr.io/openhands/agent-server:fix-websocket-auth-frame-golang-arm64
ghcr.io/openhands/agent-server:0a7e7ea-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:0a7e7ea-java-amd64
ghcr.io/openhands/agent-server:0a7e7ea0234f9fd69c28814dd363e863e63683fe-java-amd64
ghcr.io/openhands/agent-server:fix-websocket-auth-frame-java-amd64
ghcr.io/openhands/agent-server:0a7e7ea-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:0a7e7ea-java-arm64
ghcr.io/openhands/agent-server:0a7e7ea0234f9fd69c28814dd363e863e63683fe-java-arm64
ghcr.io/openhands/agent-server:fix-websocket-auth-frame-java-arm64
ghcr.io/openhands/agent-server:0a7e7ea-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:0a7e7ea-python-amd64
ghcr.io/openhands/agent-server:0a7e7ea0234f9fd69c28814dd363e863e63683fe-python-amd64
ghcr.io/openhands/agent-server:fix-websocket-auth-frame-python-amd64
ghcr.io/openhands/agent-server:0a7e7ea-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:0a7e7ea-python-arm64
ghcr.io/openhands/agent-server:0a7e7ea0234f9fd69c28814dd363e863e63683fe-python-arm64
ghcr.io/openhands/agent-server:fix-websocket-auth-frame-python-arm64
ghcr.io/openhands/agent-server:0a7e7ea-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:0a7e7ea-golang
ghcr.io/openhands/agent-server:0a7e7ea0234f9fd69c28814dd363e863e63683fe-golang
ghcr.io/openhands/agent-server:fix-websocket-auth-frame-golang
ghcr.io/openhands/agent-server:0a7e7ea-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:0a7e7ea-java
ghcr.io/openhands/agent-server:0a7e7ea0234f9fd69c28814dd363e863e63683fe-java
ghcr.io/openhands/agent-server:fix-websocket-auth-frame-java
ghcr.io/openhands/agent-server:0a7e7ea-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:0a7e7ea-python
ghcr.io/openhands/agent-server:0a7e7ea0234f9fd69c28814dd363e863e63683fe-python
ghcr.io/openhands/agent-server:fix-websocket-auth-frame-python
ghcr.io/openhands/agent-server:0a7e7ea-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., 0a7e7ea-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 0a7e7ea-python-amd64) are also available if needed

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

github-actions Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/conversation/impl
   remote_conversation.py7518888%91, 166, 193, 206, 208–211, 237, 255–256, 267–270, 277–278, 283–286, 370, 380–382, 388, 466, 613–616, 618, 644–648, 653–656, 659, 675, 813, 871–872, 876–877, 891, 905–908, 949, 962–963, 987–988, 1028–1029, 1065, 1075, 1079, 1088–1089, 1128, 1278–1279, 1373–1374, 1378, 1383–1387, 1393–1399, 1412, 1417, 1467, 1711–1712
TOTAL384561105271% 

@simonrosenberg
simonrosenberg marked this pull request as ready for review July 27, 2026 18:04

@all-hands-bot all-hands-bot 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.

✅ QA Report: PASS

Verified the SDK WebSocket client behavior with a real local WebSocket server: the PR removes session API keys from event-socket URLs and sends them as the first client frame.

Does this PR achieve its stated goal?

Yes. The stated goal was to keep session API keys out of WebSocket URLs while authenticating immediately after connect. On origin/main, the captured request path contained ?session_api_key=... and no first client frame arrived within 1s; on the PR branch, the request path was /sockets/events/qa-conversation and the first frame was {"type": "auth", "session_api_key": ...}. A no-api-key probe on the PR branch also connected with a clean URL and no unsolicited auth frame.

Phase Result
Environment Setup ✅ make build completed and installed the editable workspace packages.
CI Status ⚠️ GitHub reports 33 successful checks, 1 failing PR Description Check, 1 pending QA Changes check, and 2 skipped checks.
Functional Verification ✅ Before/after WebSocket probe confirmed the security fix and the no-api-key edge case.
Functional Verification

Test 1: WebSocket auth moves from URL query to first frame

Step 1 — Reproduce / establish baseline (without the fix):
Checked out origin/main and ran a local WebSocket capture probe:

git switch --detach origin/main
OPENHANDS_SUPPRESS_BANNER=1 uv run python - <<'PY'
# Started websockets.serve on localhost, instantiated WebSocketCallbackClient
# with api_key='sk-oh-' + 'a' * 64, captured ws.request.path and first ws.recv().
PY

Observed:

{"first_client_frame": "<NO_CLIENT_FRAME_WITHIN_1.0S>", "request_path": "/sockets/events/qa-conversation?session_api_key=sk-oh-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}

This confirms the bug exists on the base branch because credential material appears in the WebSocket request URL, which is the path/query layer commonly copied into reverse-proxy and access logs.

Step 2 — Apply the PR's changes:
Checked out fix-websocket-auth-frame at 45ca400558905ab1cd7c2692ab3c0439ff1eb423.

Step 3 — Re-run with the fix in place:
Ran the same local-server probe, plus the no-api-key edge case:

git switch fix-websocket-auth-frame
OPENHANDS_SUPPRESS_BANNER=1 uv run python - <<'PY'
# Same local WebSocket capture script; first with api_key, then with api_key=None.
PY

Observed:

[
  {
    "api_key_supplied": true,
    "first_client_frame": "{\"type\": \"auth\", \"session_api_key\": \"sk-oh-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}",
    "request_path": "/sockets/events/qa-conversation"
  },
  {
    "api_key_supplied": false,
    "first_client_frame": "<NO_CLIENT_FRAME_WITHIN_1.0S>",
    "request_path": "/sockets/events/qa-conversation"
  }
]

This confirms the fix works: with an API key, the URL is clean and the auth payload is the first client frame; without an API key, the client still connects with a clean URL and does not send an auth frame.

Issues Found

None.

This review was created by an AI agent (OpenHands) on behalf of the user.

@all-hands-bot all-hands-bot 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.

✅ QA Report: PASS

Verified the SDK WebSocket client against a real local WebSocket endpoint: base leaked session_api_key in the URL, while this PR sends a clean URL and moves auth into the first client frame.

Does this PR achieve its stated goal?

Yes. The stated goal is to remove session_api_key from Python SDK WebSocket URLs while preserving authentication via the existing first-message auth payload. In before/after execution, the base branch connected to /sockets/events/...?...session_api_key=... and sent no first frame; the PR connected to /sockets/events/... and the first client frame decoded to {"type": "auth", "session_api_key": ...}. That confirms the credential is no longer exposed in the WebSocket URL and is sent outside the URL as intended.

Phase Result
Environment Setup ✅ make build completed; dependencies installed and development environment ready.
CI Status 🟡 GitHub reported 35 successful, 16 skipped, 1 pending, 0 failing checks at QA time.
Functional Verification ✅ Real WebSocket capture verified clean URL + first-frame auth on the PR.
Functional Verification

Test 1: WebSocket API key moves from URL query to first frame

I used a temporary QA script that starts a real local websockets.serve(...) endpoint, then instantiates the SDK WebSocketCallbackClient with a fake API key containing URL-sensitive characters: 1+FYh/SRE=ds 8Q. The server records the request path and waits for the first client frame.

Step 1 — Reproduce / establish baseline without the fix:

Ran:

git fetch origin main --quiet
git checkout --quiet origin/main
OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_ws_capture.py

Output:

{"decoded_first_message": null, "first_message": null, "path": "/sockets/events/qa-ws-auth-conversation?session_api_key=sk-oh-qa-token-with-specials-1%2BFYh%2FSRE%3Dds%208Q"}

This confirms the baseline bug: the fake credential is URL-encoded into the WebSocket request path, which is the data reverse proxies commonly log. The server also received no first client frame within the capture window.

Step 2 — Apply the PR changes:

Checked out the PR commit:

git checkout --quiet 45ca400558905ab1cd7c2692ab3c0439ff1eb423

Step 3 — Re-run with the fix in place:

Ran the same capture script:

OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_ws_capture.py

Output:

{"decoded_first_message": {"session_api_key": "sk-oh-qa-token-with-specials-1+FYh/SRE=ds 8Q", "type": "auth"}, "first_message": "{"type": "auth", "session_api_key": "sk-oh-qa-token-with-specials-1+FYh/SRE=ds 8Q"}", "path": "/sockets/events/qa-ws-auth-conversation"}

This confirms the fix works: the WebSocket URL path is clean, and the auth payload is sent as the first client frame with the original API key preserved exactly, including special characters.

Issues Found

None.

This QA review was created by an AI agent (OpenHands) on behalf of the user.

@aivong-openhands

aivong-openhands commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Mutation-testing the new suite

I ran mutation testing against tests/sdk/conversation/remote/test_websocket_client.py to see which parts of the change the test actually pins down. Baseline: 9 passed.

The rewritten test_websocket_client_sends_api_key_in_first_frame is strong on the core claim — all three control mutants die:

Control mutant Result
Rename the frame type ("auth" → "authenticate") ❌ caught
Put the key back in the URL as ?session_api_key=… ❌ caught
Don't send the auth frame at all ❌ caught

Exact-equality assertions on both captured_urls[0] and sent_messages are what make that work — good choice over substring matching.

What survives is everything about the loop the frame now lives inside:

Surviving mutant Result
if self.api_key: → if self.api_key and not has_connected: ✅ 9 passed
Delete delay = 1.0 (backoff reset on successful connect) ✅ 9 passed
if self.api_key: → if True: ⚠️ suite hangs, doesn't fail

1. Reconnects are not covered — and that's where auth now lives

The auth frame moved inside while not self._stop.is_set(), so every reconnect has to re-send it. Nothing tests that. Gating the send on the first connection only:

if self.api_key and not has_connected:
    await ws.send(...)

leaves the suite fully green, but in production every reconnect after a network blip would hit the server's first-message-auth path with no frame and get closed at the 10s deadline in _accept_authenticated_websocket. Since the old query-param URL was inherently re-sent on every reconnect, this is a failure mode the change introduces.

test_websocket_client_retries_after_retryable_connection_closed already exercises the reconnect path — extending its mock to record sends is most of the work:

def test_websocket_client_reauthenticates_on_reconnect():
    sent_per_connection = []

    class _MockWebSocket:
        def __init__(self):
            self.sent = []
            sent_per_connection.append(self.sent)

        async def send(self, message):
            self.sent.append(message)

        def __aiter__(self):
            return self

        async def __anext__(self):
            if len(sent_per_connection) >= 2:
                client._stop.set()
                raise StopAsyncIteration
            raise websockets.exceptions.ConnectionClosed(
                rcvd=websockets.frames.Close(1006, "boom"),
                sent=None,
                rcvd_then_sent=False,
            )

    # ... connect() returns a fresh _MockWebSocket each call ...

    assert len(sent_per_connection) == 2
    expected = json.dumps({"type": "auth", "session_api_key": client.api_key})
    assert sent_per_connection == [[expected], [expected]]  # re-auth on every connect

2. The if self.api_key: guard hangs instead of failing

Removing the guard doesn't produce a red test — it spins test_websocket_client_retries_after_retryable_connection_closed forever (that test's mock has no send, the AttributeError is swallowed by the reconnect handler, and the loop never terminates). I had to kill it at 45s.

Two things follow. First, there's no positive assertion that a client with no API key sends no frame, which is the behavior the guard exists for:

def test_websocket_client_sends_no_auth_frame_without_api_key():
    # same mock as the first-frame test, api_key=None
    assert sent_messages == []
    assert "session_api_key" not in captured_urls[0]

Second, and more general: a mutation in this file degrades into a CI timeout rather than a diagnostic. Worth a @pytest.mark.timeout(...) on the reconnect tests, or an iteration cap in the mock, so a regression here reports as a failure instead of a hung job.

3. Backoff reset is unpinned

delay = 1.0 can be deleted with a green suite. That line matters more after this change than before it: the await ws.send(...) now sits between connect() and the reset, so a send that raises skips the reset and the client keeps backing off. Asserting the reconnect delay sequence in the retry test would cover both.


Not a test gap, but worth a look before merge

The frame's literals ("auth", "session_api_key") are a contract with _accept_authenticated_websocket in openhands-agent-server/.../sockets.py, which reads data.get("type") != "auth" and data.get("session_api_key") against its own literals. Each side is asserted against its own copy of those strings, so a rename on one side leaves the suite green. A single shared constant, or one round-trip test against the real events_socket, would remove the class of problem.

Also note the server still honours the deprecated query parameter at a higher precedence than the frame (_resolve_websocket_session_api_key returns it first). Nothing in this PR is wrong because of that, but the URL-borne key isn't gone from the system until the server drops it too — worth saying in the description so the PR isn't read as closing that off entirely.

This comment was generated by an AI assistant on behalf of the user.

@simonrosenberg
simonrosenberg marked this pull request as draft July 28, 2026 07:33
@simonrosenberg
simonrosenberg marked this pull request as ready for review July 28, 2026 07:34
@simonrosenberg

Copy link
Copy Markdown
Member Author

Addressed in 82f6714. The unit coverage now asserts both keyed and keyless connections, verifies auth is sent on every reconnect, and pins the backoff reset to 1 second after each successful connection. The reconnect mock now accepts sends, so removing the key guard fails diagnostically instead of hanging. I also added a client-to-real-agent-server round-trip test to pin the shared first-message-auth contract. The PR Notes already call out that the server retains the deprecated query fallback for older clients.

@all-hands-bot all-hands-bot 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.

✅ QA Report: PASS

The SDK WebSocket client now keeps session_api_key out of the URL and sends it as the first client frame; I found no functional issues.

Does this PR achieve its stated goal?

Yes. I exercised the real SDK WebSocket client against a real local WebSocket server with an API key containing spaces and URL-reserved characters. On origin/main, the server observed the credential in the WebSocket request path and no first frame; on this PR commit, the request path was clean and the first client frame was the auth payload.

Phase Result
Environment Setup ✅ make build completed successfully and installed the uv environment
CI Status 🟡 23 passing, 7 still in progress, 13 skipped at query time; no failing checks observed
Functional Verification ✅ Before/after WebSocket probe confirms the intended auth transport change
Functional Verification

Test 1: API key moves from WebSocket URL to first client frame

Step 1 — Reproduce / establish baseline without the fix:

Ran git switch --detach origin/main && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_ws_probe.py using a temporary script that instantiated WebSocketCallbackClient and connected it to a real local websockets server:

[{"first_message": null, "path": "/sockets/events/qa-conversation?session_api_key=qa%20key%2Fwith%2Bsymbols%3Fand%20spaces"}]

This confirms the reported bug exists on base: the session API key is present in the WebSocket request URL, where reverse proxies and access logs can capture it, and the client sends no first auth frame.

Step 2 — Apply the PR changes:

Restored fix-websocket-auth-frame at commit 82f6714418c51580027228efe7d3fa82330950b2.

Step 3 — Re-run with the fix in place:

Ran git rev-parse HEAD && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_ws_probe.py:

82f6714418c51580027228efe7d3fa82330950b2
[{"first_message": "{"type": "auth", "session_api_key": "qa key/with+symbols?and spaces"}", "path": "/sockets/events/qa-conversation"}]

This confirms the fix works: the WebSocket path no longer contains session_api_key, and the first client frame carries the existing auth payload.

Test 2: No-api-key behavior remains clean

Ran QA_API_KEY=__NONE__ OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_ws_probe.py on the PR branch:

[{"first_message": null, "path": "/sockets/events/qa-conversation"}]

This confirms clients without an API key still connect without adding an auth query parameter or sending a spurious auth frame.

Issues Found

None.

This review was created by an AI agent (OpenHands) on behalf of the user.

@VascoSch92 VascoSch92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just one thing to be sure it is wanted: Dropping the query param outright means the client now only works against agent-server v1.19.0 or newer. Is that correct?

@simonrosenberg
simonrosenberg marked this pull request as draft July 28, 2026 08:56
@simonrosenberg
simonrosenberg marked this pull request as ready for review July 28, 2026 08:57
Co-authored-by: openhands <openhands@all-hands.dev>
@simonrosenberg

Copy link
Copy Markdown
Member Author

On the compatibility question: the exact floor is agent-server v1.18.1, not v1.19.0. First-message WebSocket auth landed in #2790 and was released in v1.18.1; v1.18.0 does not support it. This floor applies when session-key authentication is configured. No-key clients send no auth frame and remain compatible with older servers. Dropping the query parameter for authenticated connections is intentional so we do not retain the credential-leaking fallback.

@all-hands-bot all-hands-bot 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.

✅ QA Report: PASS

The PR removes the SDK WebSocket API key from the URL and still authenticates successfully against a real agent-server using the first client frame.

Does this PR achieve its stated goal?

Yes. The stated goal was to remove session_api_key from Python SDK WebSocket URLs and send the existing auth payload as the first client frame. I verified the old SDK behavior put the key in the query string, the PR SDK uses a clean WebSocket URL and sends {"type":"auth","session_api_key":...} first, and a live authenticated agent-server accepts that no-query first-frame auth while rejecting an invalid first-frame key.

Phase Result
Environment Setup ✅ uv sync --dev completed; branch HEAD was 0a7e7ea0234f9fd69c28814dd363e863e63683fe
CI Status 🟡 51 checks observed: 34 pass, 1 pending (qa-changes), 16 skipping
Functional Verification ✅ SDK client behavior and live agent-server WebSocket auth path verified with real WebSocket traffic
Functional Verification

Test 1: SDK WebSocket client no longer puts the API key in the URL

Step 1 — Reproduce / establish baseline without the fix:
Checked out the base commit in /tmp/qa-ws-base and ran a local WebSocket server probe that records the request path and first client frame:

OPENHANDS_SUPPRESS_BANNER=1 uv run --project /tmp/qa-ws-base python /tmp/qa_sdk_ws_client_probe.py

Observed:

{
  "client_class": "WebSocketCallbackClient",
  "first_client_frame": null,
  "request_path": "/sockets/events/qa-conversation-id?session_api_key=1%2BFYh%2FSRE%3Dds%208Q"
}

This confirms the pre-PR behavior exposed session_api_key in the WebSocket request URL and did not send a first auth frame.

Step 2 — Apply the PR's changes:
Checked out PR commit 0a7e7ea0234f9fd69c28814dd363e863e63683fe in /tmp/qa-ws-head.

Step 3 — Re-run with the fix in place:
Ran the same probe against the PR worktree:

OPENHANDS_SUPPRESS_BANNER=1 uv run --project /tmp/qa-ws-head python /tmp/qa_sdk_ws_client_probe.py

Observed:

{
  "client_class": "WebSocketCallbackClient",
  "first_client_frame": "{"type": "auth", "session_api_key": "1+FYh/SRE=ds 8Q"}",
  "request_path": "/sockets/events/qa-conversation-id"
}

This confirms the PR removes the credential from the URL and sends it as the first WebSocket client frame instead.

Test 2: A real authenticated agent-server accepts no-query first-frame auth

Step 1 — Establish live server baseline:
Started the PR branch's real agent-server with a session API key and created a real conversation through the authenticated HTTP API:

OH_SESSION_API_KEYS_0=qa-server-key OPENHANDS_SUPPRESS_BANNER=1   uv run --project /tmp/qa-ws-head agent-server --host 127.0.0.1 --port 18081

curl -H 'Content-Type: application/json' -H 'X-Session-API-Key: qa-server-key'   --data @/tmp/qa_create_conversation.json   http://127.0.0.1:18081/api/conversations

Observed HTTP_STATUS:201 with conversation ID d70f5fba-c67b-459d-9d34-4cf7882be457, confirming the server and authenticated API were usable.

Step 2 — Exercise WebSocket auth variants:
Connected to the real conversation WebSocket using three user-relevant variants: legacy query auth, no-query invalid first-frame auth, and no-query valid first-frame auth.

OPENHANDS_SUPPRESS_BANNER=1 uv run --project /tmp/qa-ws-head python /tmp/qa_agent_server_ws_probe.py

Observed summary:

[
  {
    "label": "valid-query-fallback-baseline",
    "state": "received-message",
    "url": "ws://127.0.0.1:18081/sockets/events/d70f5fba-c67b-459d-9d34-4cf7882be457?session_api_key=qa-server-key"
  },
  {
    "close_code": 4001,
    "close_reason": "Authentication failed",
    "label": "no-query-invalid-first-frame-auth",
    "state": "closed-after-connect",
    "url": "ws://127.0.0.1:18081/sockets/events/d70f5fba-c67b-459d-9d34-4cf7882be457"
  },
  {
    "label": "no-query-valid-first-frame-auth",
    "state": "received-message",
    "url": "ws://127.0.0.1:18081/sockets/events/d70f5fba-c67b-459d-9d34-4cf7882be457"
  }
]

This shows the server still accepts the legacy query fallback, rejects a bad first-frame key with 4001 Authentication failed, and accepts the PR's intended no-query valid first-frame auth by sending a conversation state event.

Issues Found

None.

This review was created by an AI agent (OpenHands) on behalf of the user.

@simonrosenberg
simonrosenberg merged commit c1c32e6 into main Jul 28, 2026
67 of 68 checks passed
@simonrosenberg
simonrosenberg deleted the fix-websocket-auth-frame branch July 28, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants