- Newest
- Most votes
- Most comments
This is almost certainly infrastructure-level CORS handling before the request reaches FastAPI, not a FastAPI bug. When Cloudflare sits in front of an AWS Application Load Balancer, Cloudflare can intercept or synthesize responses to OPTIONS preflight requests (via proxying, cache rules, WAF, or “Automatic OPTIONS” behavior), which means the request never reaches your FastAPI app and its CORS middleware never runs—hence the “Disallowed CORS origin.” This explains why it works from the Amplify domain (likely bypassing Cloudflare) but fails from your custom domain. The fix is to ensure Cloudflare forwards OPTIONS requests to the origin unmodified: disable caching/WAF rules for OPTIONS, avoid Transform Rules adding/removing CORS headers, set the backend hostname to DNS-only (gray cloud) for testing, or explicitly allow/forward OPTIONS in Cloudflare. Also confirm the ALB listener allows OPTIONS and does not return fixed responses. Once Cloudflare stops handling preflight itself, FastAPI’s CORS middleware will execute correctly.
answered 10 months ago
Relevant content
asked 2 years ago
- AWS OFFICIALUpdated 3 months ago
