Security

Static Access-Control-* text. Not a CORS audit.

One Allow-Origin value, methods, headers, optional credentials / Max-Age / Expose-Headers → Apache Header set or Nginx add_header … always. We refuse * with credentials. We never send OPTIONS. Multi-origin allowlists belong in your API, not this snippet.

Exact origin (recommended) or * for anonymous requests — not with credentials.

Access-Control-Allow-Methods

Validate with browser DevTools Network or curl -i -H "Origin: …". You may still need explicit OPTIONS handling in your app or edge layer. Pair with TLS review via our SSL Certificate Checker and Apache patterns from the .htaccess Generator.

When to use this — and when not to

Use it to paste a starting Apache or Nginx block for one front-end origin talking to one API. Then still send a real OPTIONS from the browser (or curl -X OPTIONS -i) and watch the response.

Do not use * with credentials — we refuse that combination because browsers do. Do not expect a multi-origin allowlist. Echoing Origin from a server allowlist is application code, not this snippet. CORS is not authentication.

What the generator actually emits

Apache: Header set inside <IfModule mod_headers.c>. Nginx: add_header … always;. One Allow-Origin, methods, headers, optional Max-Age, credentials, Expose-Headers. Preferences sit in localStorage on this origin.

Worked example

Front-end https://app.example.com, API on Apache, GET+POST+OPTIONS, credentials off:

Header set Access-Control-Allow-Origin "https://app.example.com"
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
Header set Access-Control-Allow-Headers "Content-Type, Authorization"

If preflight still fails, your edge is not answering OPTIONS or Nginx nested add_header dropped the set. Fix routing, not this form. Related: HTTP request builder for the client side of the same call.

Mistakes people make

  • Stacking add_header in server and location until duplicates or missing headers appear.
  • Allowing * and cookies. Browsers refuse it; we do too.
  • Treating CORS as a lock on the API. curl still works.

Related

.htaccess generator · HTTP request builder

Frequently asked questions

Does this send OPTIONS?

No. Text only. You still test the live origin.

Multiple front-end origins?

Not here. Implement an allowlist in the API or gateway.

Need mod_headers?

Yes for Apache Header set. Missing module → ignore or 500 depending on host.

Is this enough for production?

It is a starting snippet. Test error responses too — some stacks omit CORS on 4xx/5xx.