CORSMiddleware does not provide explicit origin although client credential is present #1823
Unanswered
gyusang
asked this question in
Potential Issue
Replies: 2 comments 3 replies
-
I did some reading, I think it makes sense to include |
Beta Was this translation helpful? Give feedback.
0 replies
-
If a reporter doesn't provide references, you'll just make a maintainer spend time finding them. Reference: https://fetch.spec.whatwg.org/#cors-protocol-and-credentials |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When sending a CORS request with credentials, wildcard origin is rejected by the standard.
The fifth row of the Notes column in [1] says,
[1] also says,
Therefore, the server should check if any credentials exist inside the request and provide appropriate
Access-Control-Allow-Origin
to make CORS requests succeed.HTTP cookies are already checked in the current version, so TLS client certificates (mTLS) and authentication entries support should be added.
starlette/starlette/middleware/cors.py
Lines 164 to 165 in 31164e3
Authentication entries used for HTTP authentication are associated using
Authorization
headers ([4]).Thus, we need to respond with explicit(not
*
)Access-Control-Allow-Origin
response headers when the request includesHowever, since this library creates a HTTP server, it cannot know the details of the TLS handshake unless the TLS termination proxy(e.g. uvicorn) provides such information. So the second case can be skipped (Using CORS with mTLS and a wildcard
allow_origins
would be very rare anyway).Therefore I propose responding with explicit(not
*
)Access-Control-Allow-Origin
response headers whenAuthorization
request header is present and CORSMiddleware hasallow_credentials
option enabled.Or, responding with explicit
Access-Control-Allow-Origin
response header when CORSMiddleware hasallow_credentials
option enabled (regardless of the Authorization header).The second option allows supporting mTLS credentials being provided.
References:
[1] https://fetch.spec.whatwg.org/#cors-protocol-and-credentials
[2] https://fetch.spec.whatwg.org/#credentials
[3] https://fetch.spec.whatwg.org/#authentication-entries
[4] https://www.rfc-editor.org/rfc/rfc9110#section-11.6.2
[5] https://httpwg.org/specs/rfc7231.html#rfc.section.7.1.4
Beta Was this translation helpful? Give feedback.
All reactions