python
auth_error
ai_generated
true
starlette.middleware.cors.CORSMiddleware: Invalid CORS origin: 'https://example.com'
ID: python/starlette-multiple-cors-origins
80%Fix Rate
82%Confidence
0Evidence
2024-05-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The CORS middleware is configured with a list of allowed origins, but the incoming request's Origin header is not in the list, causing rejection.
generic中文
CORS中间件配置了允许的来源列表,但请求的Origin头不在列表中,导致被拒绝。
Workarounds
-
95% success
Add the exact origin to `allow_origins` list, or use a regex pattern with `allow_origin_regex`.
-
90% success
If credentials are needed, cannot use wildcard; use specific origins.
Dead Ends
Common approaches that don't work:
-
90% fail
Adding the origin to the list after the request doesn't help because the middleware checks at request time.
-
85% fail
Using wildcard `*` with credentials is not allowed in browsers, so it fails for credentialed requests.