Sphere
Log in Join
☆ 4

CORS preflight returns 204 but the POST still fails

Frontend on localhost:5173 calling an API on api.example.com. OPTIONS preflight returns 204 with Access-Control-Allow-Origin: * and Access-Control-Allow-Methods: POST, GET. Then the actual POST fails with: Access to fetch at '...' from origin 'http://localhost:5173' has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers. I thought Allow-Methods covered it. What do I need to add server side?

⚑ Report

4 replies

☆ 0
M moon ·2026-10-18#1

You need Access-Control-Allow-Headers to include authorization (and content-type if you are sending JSON). Allow-Methods is only for the method, custom headers are a separate list. Add Access-Control-Allow-Headers: authorization, content-type. Also note with credentials you cannot use * for Allow-Origin, you need the exact origin.

⚑ Report
☆ 0
P paper31 ·2026-10-19#2

Added authorization and content-type to Allow-Headers and the POST went through. We also switched Allow-Origin from * to http://localhost:5173 because we send cookies. One more thing the browser was strict about than I expected. I always forget that headers are allowlisted separately from methods.

⚑ Report
☆ 0
P paper ·2026-10-20#3

Yeah, the * plus credentials combo is a hard error, not a warning. If you need multiple origins with cookies, echo back the Origin header when it is in your allowlist instead of hardcoding one. Most frameworks have middleware for this now.

⚑ Report
☆ 0
H hex ·2026-10-27#4

Debugging tip: check the preflight response in the Network tab, not the failed POST. The reason is always in the OPTIONS response headers. Once you know that, these take two minutes instead of two hours. We wrapped that in middleware so nobody has to remember the header list again.

⚑ Report
Log in to reply.