fix: restrict CORS headers to localhost origins instead of wildcard#1
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
fix: restrict CORS headers to localhost origins instead of wildcard#1devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Replace Access-Control-Allow-Origin: * with origin validation that only allows requests from local addresses (127.0.0.1, localhost, [::1]). The helper server already binds to 127.0.0.1 (loopback only), but the wildcard CORS header unnecessarily allows any web page to make cross-origin requests to it. This hardens the security posture by: - Adding cors_allowed_origin() to extract and validate the Origin header - Adding is_local_origin() to whitelist only loopback addresses - Adding cors_headers_for_origin() to conditionally emit CORS headers - Adding Vary: Origin header for correct caching behavior - Updating all 4 CORS locations: inline responses, write_http_response, write_http_stream_headers, and all proxy handler call sites Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The helper server's HTTP responses included
Access-Control-Allow-Origin: *in all 4 CORS emission points — the inline OPTIONS/general responses inhandle_helper_connection, pluswrite_http_responseandwrite_http_stream_headers. While the server already binds to127.0.0.1(loopback only), the wildcard CORS policy allows any web page (e.g. a malicious site a user visits) to make cross-origin requests to the local helper, potentially exfiltrating data or triggering actions.Fix: Three new functions replace the hardcoded
*:The
allowed_originis computed once inhandle_helper_connectionand threaded throughhandle_models_proxy_connection,handle_protocol_proxy_connection,handle_chat_completions_proxy_connection,write_http_response, andwrite_http_stream_headers. Non-local origins receive no CORS headers (browser blocks the request).Link to Devin session: https://app.devin.ai/sessions/dff844c4d3f9469e8748f06ca1cecd92
Requested by: @ManhND226677