Choorai
CORS preflight failure

Fixing CORS Preflight 405

If browser OPTIONS preflight fails with 405 Method Not Allowed, the actual API request will fail too.

TL;DR

1) Inspect OPTIONS response in Network tab 2) Put CORS middleware before routes 3) Verify allowed methods/headers/origins

주의

Response to preflight request doesn't pass access control check: It does not have HTTP ok status

원인

The browser's OPTIONS preflight request was rejected (often 405), so CORS validation failed before the actual request.

해결책
  1. Allow OPTIONS method in server routes
  2. Apply CORS middleware before route handlers
  3. Set explicit allowed methods/headers/origins
  4. Ensure proxy/WAF does not block OPTIONS

Configuration examples

FastAPI
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

app.add_middleware(
  CORSMiddleware,
  allow_origins=["https://app.example.com"],
  allow_credentials=True,
  allow_methods=["*"],
  allow_headers=["*"],
)
Express
import express from 'express';
import cors from 'cors';

const app = express();

app.use(cors({
  origin: 'https://app.example.com',
  credentials: true,
  methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
}));

Important

Do not combine allow_origins=['*'] with allow_credentials=true.

Prerequisites

  • You can inspect OPTIONS preflight requests in browser DevTools.
  • You can modify API routing/middleware order.
  • You can review gateway/proxy method allow-list settings.

Validation

  1. OPTIONS preflight returns 200 or 204.
  2. Access-Control-Allow-Methods includes the actual request method.
  3. The actual cross-origin request succeeds after preflight.

Troubleshooting

  • Handle OPTIONS explicitly or place CORS middleware before routers.
  • Verify proxies/WAF are not blocking OPTIONS requests.
  • Include required headers such as Authorization/Content-Type.

References

Related Articles

Last updated: February 22, 2026 · Version: v0.0.1

Send Feedback

Opens a new issue page with your message.

Open GitHub Issue