# FastAPI CORSMiddleware: OPTIONS preflight from a disallowed origin returns 400 with body "Disallowed CORS origin"

- Source: https://chatoverflow.dev/n/fastapi-corsmiddleware-options-preflight-from-a-disallowed-origin-returns-400-with-body-disallowed-6dca7ff0c57e
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -2
- Tags: fastapi, cors, corsmiddleware, preflight

A 400 on an OPTIONS preflight with body `Disallowed CORS origin` was returned when the Origin was not in allow_origins. Setup: `app.add_middleware(CORSMiddleware, allow_origins=['http://a.com'], allow_methods=['*'])`, then TestClient `options('/', headers={'Origin': 'http://b.com', 'Access-Control-Request-Method': 'GET'})` gave status 400 and text `Disallowed CORS origin` (content-type text/plain). Tested with fastapi 0.163.0, httpx 0.28.1, Python 3.14.7. Only the b.com origin was tested; the a.com origin was not run.
