fix(security): strip wildcard CORS origin when credentials are enabled#1366
Draft
glitch-ux wants to merge 1 commit into
Draft
fix(security): strip wildcard CORS origin when credentials are enabled#1366glitch-ux wants to merge 1 commit into
glitch-ux wants to merge 1 commit into
Conversation
Starlette's CORSMiddleware with allow_origins=["*"] and allow_credentials=True reflects the request's Origin header in the response, allowing any website to make authenticated cross-origin requests. This is a well-known CORS misconfiguration (CWE-942). Changes: - WebUI Gateway and Platform Service: detect '*' in allowed origins at middleware setup time, log a security warning, and remove it. - When no origins remain after stripping, auto-construct safe localhost origins from the component's configured host/port (matching the existing platform service auto-construction pattern). - Change the code-level default for cors_allowed_origins from ["*"] to [] in both components and their app config schemas. YAML templates already set explicit origins, so this only affects unconfigured deployments. - Update webhook gateway example to use explicit origins. - Add 8 new unit tests covering wildcard stripping, auto-construction, HTTPS detection, and pass-through of explicit origins. - Update test factories and assertions to use explicit origins. Signed-off-by: José Maia <glitch-ux@users.noreply.github.com>
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
CORS is configured with
allow_credentials=Trueacross the WebUI Gateway and Platform Service. Whenallow_originscontains"*", Starlette'sCORSMiddlewarereflects the request'sOriginheader in the response — effectively allowing any website to make authenticated cross-origin requests (session cookies, tokens). This is CWE-942.This PR:
"*"fromallow_originsat middleware setup time in both the WebUI Gateway and Platform Service, with a clear warning log explaining the issue and how to suppress ithost/portwhen no origins remain (matching the existing Platform Service auto-construction pattern)cors_allowed_originsfrom["*"]to[]— YAML templates already set explicit origins (http://localhost:3000, etc.), so this only affects unconfigured deployments"*"Files changed
src/.../gateway/http_sse/main.py_setup_middlewaresrc/.../services/platform/api/main.py_setup_middlewaresrc/.../gateway/http_sse/component.py["*"]→[]src/.../services/platform/component.py["*"]→[]src/.../gateway/http_sse/app.pysrc/.../services/platform/app.pyexamples/gateways/webhook_gateway_example.yamltests/unit/.../test_http_sse_main.pytests/unit/.../test_cors_auto_construction.pyBackward compatibility
sam init(YAML templates) are unaffected — templates already set explicit originscors_allowed_originsconfig are unaffected["*"]code default will now get auto-constructed localhost origins instead, with a warning log. This is a security improvement, not a regressionTest plan
TestCORSWildcardHandling)sam init && sam runand verify the Web UI athttp://localhost:8000works (CORS headers should show the auto-constructed origin, not*)cors_allowed_origins: ["*"]in webui.yaml and verify the warning log appears at startup