Skip to content

fix(auth): bind socket tokens to handshake origin - #1939

Merged
BlueHotDog merged 3 commits into
integration/mcp-2026-07-28from
fix/websocket-handshake-origin
Oct 25, 2026
Merged

BlueHotDog merged 3 commits into
integration/mcp-2026-07-28from
fix/websocket-handshake-origin

Conversation

@BlueHotDog

@BlueHotDog BlueHotDog commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Bind embedded-client WebSocket authentication to the actual handshake Origin, rather than trusting the socket's claimed origin alone.

  • Validate exactly one actual Origin before Phoenix socket dispatch.
  • Replace the internal origin header with the normalized handshake value and pass it through supported connect_info metadata.
  • Authenticate the bearer token against the actual handshake origin only. Ignore legacy claimed-origin params.
  • Stop sending the redundant origin socket parameter from the browser client.
  • Preserve dynamic approved embedding sites, localhost development, existing bearer authentication, and the frame-size limit.
  • Add endpoint upgrade-path regression coverage for forged, mismatched, missing, duplicate, and malformed origins.

This PR changes only origin authentication. The separate MCP interim-result reproduction test is intentionally red and is not included.

Validation

Latest cleanup validation:

  • MIX_TEST_DB_SUFFIX=_delta_origin_cleanup make -C apps/frontman_server precommit TEST_ARGS='test/frontman_server_web/channels/user_socket_test.exs test/frontman_server_web/controllers/client_token_controller_test.exs' — passed compilation, formatting, strict Credo, and all 16 targeted tests.
  • make -C apps/frontman_server strict-compile — passed development and test compilation with warnings treated as errors.
  • Full server precommit — 1,074 of 1,075 tests passed. The sole failure is the inherited MCP input_required regression covered by the next fix layer, not origin authentication.
  • make -C libs/frontman-client check — formatting and build passed; 110 of 111 tests passed, including the new no-origin-param regression. The sole failure is the inherited empty-subscription acknowledgment regression.
  • make build and the pre-commit/pre-push hooks passed, including shared binding compilation, formatting, strict Credo, source-comment checks, and dead-code analysis.
  • Endpoint tests exercise Endpoint.call/2 and Plug's upgrade-capable test adapter. No live-browser/TCP handshake test was run.

This cleanup uses only the actual handshake origin for token authentication. Older clients may still send an origin parameter, but it is ignored. The internal header remains the bridge into Phoenix socket connect metadata; the endpoint replaces it before dispatch.

Checklist

  • Added/updated tests
  • Added a patch changeset
  • Tested locally with make dev

Integration stack

Integration target: integration/mcp-2026-07-28. No PR in this stack targets main.

  1. test(mcp): reproduce interim-result and subscription gaps #1940 — failing reproduction tests (base: integration branch).
  2. fix(auth): bind socket tokens to handshake origin #1939 — origin-authentication fix (base: test(mcp): reproduce interim-result and subscription gaps #1940's branch).
  3. fix(mcp): handle interim results without crashing #1948 — MRTR fix — makes the interim-result regression green.
  4. fix(mcp): support browser subscriptions and server notifications #1949 — subscription fix — makes the acknowledgment regression green and covers lifecycle handling.
  5. Then: remaining findings — reconnect/replay safety, structured-result consumption, schema validation, and contract validation. Establish failing coverage before each corresponding fix; do not encode unresolved product policy as a protocol requirement.

All PRs are regular, non-draft PRs. The test foundation is intentionally red; inherited failures remain expected until the relevant fix layers are present. The origin-only suite passed before inheriting those regressions.

Review and integrate bottom-up. After a predecessor is merged into the integration branch, retarget the next PR to the integration branch before merging it. Do not merge an upper PR into the test branch out of order. A later, separately approved PR will take the completed integration branch to main.

Stack setup has not merged either PR into the integration branch or main. No empty placeholder fix PRs are created.

Current review stack

integration/mcp-2026-07-28 ← #1940 (reproduction tests) ← #1939 (origin authentication) ← #1948 (MRTR decline) ← #1949 (browser subscriptions / notification envelopes).

All four PRs are non-draft. Review bottom-up. After integrating a predecessor, retarget the next PR to the integration branch before merging it. Neither the integration branch nor main has been updated by these fix layers.

At #1949, local validation passes: 1,081 server tests plus precommit checks; 115 browser-client tests plus formatting/build. Both original regressions are green. Independent reviews approved the MRTR layer and the subscription layer after the safe-cancellation-logging follow-up.

Remaining findings stay test-first: replay safety, structured-result consumption, schema validity, and contract validation. No production rollout or merge to main is authorized by this stack setup.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T14:28:24.816460Z d4ce18c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@BlueHotDog
BlueHotDog changed the base branch from main to test/mcp-subscriptions-regression October 22, 2026 14:55
@BlueHotDog
BlueHotDog added this pull request to stack #1955 October 23, 2026 20:37
@BlueHotDog
BlueHotDog force-pushed the fix/websocket-handshake-origin branch from 68399f5 to c598576 Compare October 24, 2026 14:33
Base automatically changed from test/mcp-subscriptions-regression to integration/mcp-2026-07-28 October 24, 2026 14:33
@BlueHotDog
BlueHotDog force-pushed the fix/websocket-handshake-origin branch from c598576 to 961e79b Compare October 24, 2026 14:33
@BlueHotDog
BlueHotDog merged commit 350633c into integration/mcp-2026-07-28 Oct 25, 2026
32 checks passed
@BlueHotDog
BlueHotDog deleted the fix/websocket-handshake-origin branch October 25, 2026 15:06
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.

1 participant