Skip to content

Fix CORSMiddleware to return explicit origin for Authorization header#3127

Closed
KeepALifeUS wants to merge 1 commit intoKludex:mainfrom
KeepALifeUS:fix-cors-authorization-header
Closed

Fix CORSMiddleware to return explicit origin for Authorization header#3127
KeepALifeUS wants to merge 1 commit intoKludex:mainfrom
KeepALifeUS:fix-cors-authorization-header

Conversation

@KeepALifeUS
Copy link

Summary

Changes

  • Added check for "authorization" in request_headers alongside the existing cookie check
  • Updated comment to reflect the expanded scope
  • Added test test_cors_authorization_header_returns_specific_origin that verifies the fix

Background

Per the CORS specification, wildcard * origin is not valid for credentialed requests. The middleware already handled this for requests with cookies, but was missing the case when Authorization header is present. Token-based authentication (Bearer tokens, etc.) is widely used and requires the same handling.

Test plan

  • Added new test for Authorization header handling
  • Existing tests should continue to pass (cookie behavior unchanged)

🤖 Generated with Claude Code

When using `allow_origins=["*"]`, the middleware now correctly returns
the specific origin instead of "*" when the request includes an
Authorization header, matching the existing behavior for Cookie headers.

This fixes a CORS issue where browsers would reject responses for
authenticated requests using Authorization header because "*" is not
a valid Access-Control-Allow-Origin value for credentialed requests.

Fixes Kludex#1832

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Kludex
Copy link
Owner

Kludex commented Feb 14, 2026

I've merged #3137 instead, but thank you for the PR! :)

@Kludex Kludex closed this Feb 14, 2026
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.

CORSMiddleware does not provide explicit origin although Authorization header is present

2 participants