CORS Credentials + Wildcard Origin Error: Practical Fix Guide

Fix the classic browser CORS block when credentials are enabled with Access-Control-Allow-Origin=*.

This is one of the most frequent production CORS failures. Browsers reject credentialed cross-origin requests when wildcard origin is used. You need explicit origin or safe reflection.

Tools in this guide

Symptoms

  • Browser console reports CORS failure despite server returning 200.
  • Cookies/Authorization requests fail only in browser, not in curl.
  • Preflight passes inconsistently across origins.

Root Cause

  • Access-Control-Allow-Credentials=true is used with Access-Control-Allow-Origin=*.
  • Origin reflection is configured but cache layer misses Vary: Origin.
  • Allow-Headers / Allow-Methods do not match real frontend request.

Fix Steps

  1. Set explicit allowed origin (or controlled origin reflection) instead of wildcard.
  2. Regenerate response headers in CORS Header Generator and ensure Vary: Origin appears for dynamic origin.
  3. Recheck request/response header blocks and validate cookie attributes if session auth is used.

Credential-safe CORS response headers

Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Credentials: true
Vary: Origin

FAQ

Can I keep wildcard with credentials?

No. Browsers block this combination by design.

Do I always need Vary: Origin?

You need it whenever origin is dynamic to avoid cache confusion.