Skip to content

Add same-origin validation helper for WebSockets - #1234

Open
Shane32 wants to merge 1 commit into
masterfrom
codex/websocket-same-origin-check
Open

Shane32 wants to merge 1 commit into
masterfrom
codex/websocket-same-origin-check

Conversation

@Shane32

@Shane32 Shane32 commented Nov 22, 2026

Copy link
Copy Markdown
Member

Browsers allow cross-origin WebSocket connections independently of HTTP CORS policies. Add UseWebSocketsWithSameOriginCheck() to enable WebSockets and reject requests with HTTP 403 when a supplied Origin does not match the request's scheme, host, and port. Requests without an Origin header remain allowed, matching AllowedOrigins behavior.

The helper also accepts WebSocketOptions. Update the README and sample startup pipelines to recommend the helper for same-origin clients, and show UseWebSockets() with WebSocketOptions.AllowedOrigins for clients hosted on other origins. Add origin validation tests and update the public API snapshots for all target frameworks.

Validation:

  • All six transport target frameworks build with no warnings or errors.
  • 950 transport tests pass, including 20 new origin validation cases.
  • 91 sample tests pass, including the .NET Framework sample.
  • All 5 API approval tests pass.
  • Formatting verification for the changed C# files and git diff --check pass.

@Shane32

Shane32 commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Tests should pass after #1235 ...

@Shane32

Shane32 commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Basically, the suggested implementation prior to this PR leaves GraphQL.NET servers open to CSRF attacks (apparently) since any query or mutation can execute over a WebSocket connection. This only matters of course if authentication information is stored within cookies.

@Shane32 Shane32 self-assigned this Nov 22, 2026
@Shane32
Shane32 requested a review from gao-artur November 22, 2026 06:07
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