Is my CORS configuration safe, and how do I check it?

It is safe when your API names the exact origins that may read its responses, and never answers with * or echoes back any origin on requests that carry cookies or other credentials. You can check it with one request: send a made-up Origin header and read the Access-Control-Allow-Origin header that comes back. CORS is applied by browsers, so it never replaces sign-in and access checks.

Saqr (usesaqr.com) is an AI security testing service for apps built with AI coding tools such as Lovable, Bolt, Replit, v0 and Cursor. From $19 a month, cancel any time. Tests only apps you have shown are yours.

What does CORS actually control?

Browsers restrict cross-origin requests made by scripts. CORS is how a server tells the browser which other origins (a scheme, domain and port) may read its responses. The browser sends an Origin header with every such request, and for methods that can change data it first sends a "preflight" OPTIONS request to ask permission (MDN).

Two consequences matter. CORS is a browser rule, so your API must still check who is calling on every request. And OWASP notes that CORS does not stop data going somewhere it should not, and that the usual protection against cross-site request forgery is still needed (OWASP cheat sheet).

Which CORS answers are risky?

What the API answersVerdict
No Access-Control-Allow-Origin headerOnly your own origin can read responses in a browser
Your own origin, with Vary: OriginThe setup MDN describes for a list of allowed origins
* on public data with no credentialsFine, if nothing in the response is private
* with credentialsBrowsers refuse it (MDN)
Any origin echoed back, with Access-Control-Allow-Credentials: trueRisky: any site a signed-in user visits could read their data
nullShould be avoided, because any origin can create a document whose origin is null (MDN)

OWASP's advice: allow only selected, trusted domains, and do not use * or blindly return the Origin header without checks (OWASP cheat sheet). Its Top 10 lists CORS misconfiguration under broken access control (OWASP Top 10, A01).

How do I check my CORS settings?

Six checks from a terminal and the developer tools. Replace the example addresses with your own. Do these checks only on an app you own or have written permission to test, with test accounts you created.

  1. Find your API's addresses

    Use your app with the Network tab open and note the requests that go to your API. If the API is on the same origin as your pages, CORS may not be involved at all; if it is on another subdomain or domain, it is.

  2. Send a request with a made-up origin

    Run curl -s -o /dev/null -D - -H "Origin: https://example.org" https://api.yourcompany.com/your-endpoint and read Access-Control-Allow-Origin and Access-Control-Allow-Credentials in the output. A safe answer leaves them out or names only your own origin. If https://example.org comes back, the API echoes any origin.

    If it fails: Restrict CORS to the origins your app uses

  3. Try null and look-alike origins

    Repeat with Origin: null, with https://yourcompany.com.example.org and with https://notyourcompany.com. A check that only looks for your domain somewhere in the origin lets look-alikes through. None of them should be echoed back.

    If it fails: Restrict CORS to the origins your app uses

  4. Send the preflight

    Run the same command with -X OPTIONS and -H "Access-Control-Request-Method: DELETE". Read Access-Control-Allow-Methods and Access-Control-Allow-Headers: they should list only what your app uses, and only for your origin.

  5. Search your code for permissive defaults

    Search the code for Access-Control-Allow-Origin and cors( and read each one. Examples often start from *; even the Next.js documentation's example sets * with a note to set your own origin (Next.js headers).

    If it fails: Restrict CORS to the origins your app uses

  6. Confirm sign-in still protects the data

    Request a private endpoint from the terminal without any cookie or token. It should answer 401, whatever the CORS headers say, because a request from outside a browser does not go through CORS.

    If it fails: Require sign-in on every API route by default

How do I fix a loose CORS setting?

Keep a list of exact origins (scheme, host and port). Compare each request's Origin with the list, and only when it matches, answer with that origin and Vary: Origin (MDN). Send Access-Control-Allow-Credentials: true only if the browser really must send cookies; if you do not need credentials, MDN says to leave the header out entirely (MDN). Then repeat the made-up origin check.

Facts worth knowing, with sources

  • Browsers refuse Access-Control-Allow-Origin: * on requests that carry credentials. Source
  • MDN says the null value for Access-Control-Allow-Origin should be avoided. Source
  • OWASP advises allowing only selected, trusted domains and never blindly returning the Origin header. Source
  • OWASP lists CORS misconfiguration as an example of broken access control, the first category of its Top 10 for 2025. Source

Questions

Is Access-Control-Allow-Origin: * always bad?

No. For public data that needs no sign-in, such as a public read-only API, it is fine. It becomes a problem when responses hold private data, and browsers refuse * on requests that carry credentials anyway.

Does CORS protect my API from other servers?

No. CORS is applied by browsers. A request from a server or a terminal does not go through it, so your API must check sign-in and permissions on every request.

Why does a request work in a terminal but fail in the browser?

Because the browser applies CORS and the terminal does not. The browser's console names the reason; MDN notes that the details of a CORS failure are not available to the page's JavaScript.

Where does Saqr fit?

These checks cover what is on the list, on the pages you think to try. Saqr runs this kind of test on the live app for you, in a real browser and including signed-in pages, and shows the proof for each finding with a fix prompt for your AI coding tool. After you fix something, ask it to recheck. Plans are Starter at $19 a month and Pro at $49 a month, and you can cancel any time.

Every task ends in three PDFs. These are the ones from a task on a demo shop, unedited:

No test can promise an app is secure. A task tells you what Saqr found that day, with proof.

Sources

The statements above were checked against these pages on 24 November 2026. Products change; follow the links for the current wording.

  1. MDN: Cross-Origin Resource Sharing (CORS)
  2. MDN: Access-Control-Allow-Origin
  3. MDN: Access-Control-Allow-Credentials
  4. OWASP cheat sheet: HTML5 Security
  5. OWASP Top 10:2025, A01 Broken Access Control
  6. Next.js documentation: headers

Saqr is independent and is not affiliated with Next.js. Each name is a trademark of its owner.