HTTPS & cookies

How to fix: CORS configuration

CORS (Cross-Origin Resource Sharing) headers decide which other websites' JavaScript may read responses from your server.

Not sure whether your site has this problem? Check it in seconds.

Why it matters

A public API that returns the same data to everyone is normally fine with Access-Control-Allow-Origin: *. It becomes a risk when responses depend on the logged-in user and the server allows arbitrary origins together with credentials, or blindly reflects whatever Origin it receives.

How to check

Send a request with an Origin header from a site you don't own and look at the Access-Control-Allow-Origin and Access-Control-Allow-Credentials response headers. Our CORS checker does this safely.

How to fix it

Allowlist (Express)

const allowed = new Set(['https://app.example.com', 'https://www.example.com']);
app.use((req, res, next) => {
  const origin = req.headers.origin;
  if (origin && allowed.has(origin)) {
    res.setHeader('Access-Control-Allow-Origin', origin);
    res.setHeader('Vary', 'Origin');
  }
  next();
});

Common mistakes

Frequently asked questions

Can I combine * with credentials?

No. Browsers reject a wildcard origin when credentials are included.

Related guides

Guidance is general. Test header and DNS changes on a staging copy first, and check your hosting provider's documentation for platform-specific steps.