Skip to content

[Server] Fix CORS preflight behind authorization - #576

Merged
chr-hertel merged 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:fix-cors-preflight-auth
Oct 13, 2026
Merged

chr-hertel merged 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:fix-cors-preflight-auth

Conversation

@chr-hertel

Copy link
Copy Markdown
Member

Browser clients could not reach a server protected by AuthorizationMiddleware:

  • A CORS preflight carries no Authorization header, so it got a 401 and the browser blocked the request. AuthorizationMiddleware now lets OPTIONS through; the transport answers it without dispatching.
  • The default CorsMiddleware did not allow Mcp-Method, Mcp-Name and Mcp-Param-*, which every 2026-07-28 request sends. An $allowedHeaders entry ending in * now matches requested headers by prefix.

Follow-up to #566.

🤖 Generated with Claude Code

@chr-hertel chr-hertel added bug Something isn't working Server Issues & PRs related to the Server component labels Oct 10, 2026
@chr-hertel chr-hertel added this to the 0.9.0 milestone Oct 10, 2026
@chr-hertel
chr-hertel requested a balanced review from Copilot October 12, 2026 20:08

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.

🟢 Approval recommended

The focused implementation is consistent with transport behavior and adequately covered by unit tests.

0 open findings

What changed in this PR

Fixes browser CORS preflight requests when MCP authorization and modern request headers are enabled.

Changes:

  • Allows unauthenticated OPTIONS requests through authorization middleware.
  • Adds default MCP headers and prefix-based header matching to CORS handling.
  • Adds tests and documentation for the updated behavior.
File Description
src/​Server/​Transport/​Http/​Middleware/​AuthorizationMiddleware.php Bypasses token validation for OPTIONS.
src/​Server/​Transport/​Http/​Middleware/​CorsMiddleware.php Supports MCP headers and header-prefix patterns.
tests/​Unit/​Server/​Transport/​Http/​Middleware/​AuthorizationMiddlewareTest.php Tests unauthenticated preflight handling.
tests/​Unit/​Server/​Transport/​Http/​Middleware/​CorsMiddlewareTest.php Tests default MCP headers and prefix matching.
docs/​run/​authorization.md Documents middleware ordering and preflight behavior.
CHANGELOG.md Records both CORS fixes.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chr-hertel
chr-hertel force-pushed the fix-cors-preflight-auth branch from a0334c8 to b4a1d17 Compare October 13, 2026 21:24
@chr-hertel
chr-hertel merged commit a1ed54c into modelcontextprotocol:main Oct 13, 2026
28 checks passed
@chr-hertel
chr-hertel deleted the fix-cors-preflight-auth branch October 13, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants