Error Codes Wiki

Browser CORS Error Explained — Cross-Origin Request Blocked

Warningweb development

Overview

Complete guide to CORS (Cross-Origin Resource Sharing) errors: why browsers block cross-origin requests, how to configure CORS headers, and common misconfiguration fixes.

Key Details

  • CORS is a browser security feature that blocks requests from one origin to a different origin
  • An origin = protocol + domain + port (e.g., https://example.com:443)
  • The server must send Access-Control-Allow-Origin header to permit cross-origin requests
  • Preflight requests (OPTIONS) are sent for non-simple requests to check permissions first
  • CORS only applies in browsers — server-to-server requests (cURL, Postman) are not affected

Common Causes

  • Server not sending Access-Control-Allow-Origin header for the requesting origin
  • Preflight OPTIONS request not handled by the server (returns 404 or 405)
  • Credentials (cookies) included but Access-Control-Allow-Credentials not set
  • Access-Control-Allow-Origin set to * but credentials are also requested (not allowed)
  • Custom headers used but not listed in Access-Control-Allow-Headers

Steps

  1. 1Server-side: add Access-Control-Allow-Origin: https://your-frontend.com header
  2. 2Handle OPTIONS preflight: respond with 200 and appropriate Access-Control-* headers
  3. 3For credentials: set Access-Control-Allow-Credentials: true and specify exact origin (not *)
  4. 4List custom headers: Access-Control-Allow-Headers: Content-Type, Authorization
  5. 5For development: use a local proxy (Vite proxy, webpack devServer) to avoid CORS entirely

Tags

browsercorscross-originsecurityapi

More in Web Development

Frequently Asked Questions

CORS is enforced only by browsers. Postman, cURL, and server-side code do not enforce CORS restrictions.