paulserban.eu

Writing Edition

Paul Serban

Writing, snippets & book notes

Cheat sheet - Post

Systematic CORS Debugging: A Diagnostic Methodology

← Back to Debugging CORS Errors: A Systematic Troubleshooting Guide for Frontend Developers

CORS errors are identical-looking messages with wildly different root causes, so resolving them fast requires a repeatable diagnostic process rather than trial-and-error configuration changes.

Overview

Key Concepts

Reading CORS error messages correctly

Preflight requests (OPTIONS)

// If only this OPTIONS request appears in DevTools Network tab,
// with no follow-up GET/POST/etc., the preflight is the failure point:
// OPTIONS /users/123
// Access-Control-Request-Method: GET
// Access-Control-Request-Headers: authorization, content-type

DevTools Network tab over Console tab

Credentials and wildcard restrictions

Infrastructure and caching pitfalls

Environment- and framework-specific failure modes

Trade-offs / Caveats

Example in Practice

A team's checkout flow works in staging but throws CORS errors immediately after a production deploy. Following the systematic process:

# Step 1: Confirm the API is reachable outside the browser
curl -v -H "Origin: https://app.example.com" https://api.example.com/health

# Step 2: If curl succeeds but the browser fails, check DevTools Network tab
# for the OPTIONS preflight and compare its response headers:
# Access-Control-Allow-Origin: https://app.example.com  (must match exactly)
# Access-Control-Allow-Methods: GET, POST, PUT, DELETE
# Access-Control-Allow-Headers: authorization, content-type

If the preflight succeeds but duplicate Access-Control-Allow-Origin headers appear in the actual response, the next step is testing each infrastructure layer independently (direct to app server, through load balancer, through CDN) with curl -v to identify which layer is adding a redundant header - a scenario common when a CDN's own CORS handling wasn't disabled after application-level CORS was added.

Related topics