Skip to content

fix: remove hardcoded * allowed origin for sse#3054

Merged
Yuan325 merged 3 commits intomainfrom
remove-sse-access-control
Apr 16, 2026
Merged

fix: remove hardcoded * allowed origin for sse#3054
Yuan325 merged 3 commits intomainfrom
remove-sse-access-control

Conversation

@Yuan325
Copy link
Copy Markdown
Contributor

@Yuan325 Yuan325 commented Apr 14, 2026

Remove the hardcoded "Access-Control-Allow-Origin" header in sseHandler. This are only affecting users that are using SSE via MCP specs from v2024-11-05.

Tested with MCP inspector that removing this does not break SSE connection. Added regression test for checking security with allowedOrigin and allowedHost values.

🛠️ Fixes #3053

@Yuan325 Yuan325 requested a review from a team as a code owner April 14, 2026 16:28
@Yuan325 Yuan325 force-pushed the remove-sse-access-control branch from 37bf148 to 09af442 Compare April 14, 2026 16:32
Copy link
Copy Markdown
Collaborator

@kurtisvg kurtisvg left a comment

Choose a reason for hiding this comment

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

Can we ensure we add a regression test?

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request removes the hardcoded 'Access-Control-Allow-Origin' header from the SSE handler. Feedback was provided to further improve the SSE response headers for better security and compatibility, including adding 'no-transform' to Cache-Control, setting 'X-Accel-Buffering' and 'X-Content-Type-Options', and ensuring the 'Connection' header is only set for HTTP/1.1 requests.

Comment thread internal/server/mcp.go
@Yuan325 Yuan325 force-pushed the remove-sse-access-control branch from 09af442 to 8b2af71 Compare April 14, 2026 20:45
@Yuan325
Copy link
Copy Markdown
Contributor Author

Yuan325 commented Apr 14, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new Addr() method to the Server struct and removes the hardcoded wildcard Access-Control-Allow-Origin header from the SSE handler to support configurable CORS. It also adds comprehensive security tests for origin and host validation. The review feedback identifies several issues in the newly added tests, including goroutine leaks caused by unbuffered and unread error channels when starting the test server, and potential panics due to unhandled errors from http.NewRequest calls.

Comment thread internal/server/server_test.go Outdated
Comment thread internal/server/server_test.go Outdated
Comment thread internal/server/server_test.go Outdated
Comment thread internal/server/server_test.go Outdated
@Yuan325 Yuan325 force-pushed the remove-sse-access-control branch from 56fdbd1 to f66d3da Compare April 15, 2026 17:19
@Yuan325 Yuan325 requested review from averikitsch and kurtisvg April 15, 2026 20:45
@Yuan325 Yuan325 enabled auto-merge (squash) April 16, 2026 17:28
@Yuan325 Yuan325 merged commit c4c7bd9 into main Apr 16, 2026
18 checks passed
@Yuan325 Yuan325 deleted the remove-sse-access-control branch April 16, 2026 17:29
@github-actions
Copy link
Copy Markdown
Contributor

🧨 Preview deployments removed.

Cloudflare Pages environments for pr-3054 have been deleted.

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.

[SECURITY] Hardcoded CORS bypass on SSE endpoint in internal/server/mcp.go

3 participants