Skip to content
ScanAnt

What is CORS (cross-origin resource sharing)?

CORS (cross-origin resource sharing) is a browser mechanism that lets a server say which other origins may read its responses. By default a page from one site cannot read data from another site's API; CORS headers are how the API opts in.

How it works

The browser compares the page's origin (scheme, host and port) with the API's. For a cross-origin request it checks the response header Access-Control-Allow-Origin. If the header names the page's origin, the script may read the reply. For non-simple requests the browser first sends an OPTIONS preflight. CORS protects users' browsers, not your server: tools such as curl ignore it entirely. The dangerous setups are reflecting any Origin back while also allowing credentials, or answering with a wildcard on an endpoint that returns private data.

HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Credentials: true
Vary: Origin

# Risky: the server copies whatever Origin it receives
Access-Control-Allow-Origin: https://evil.example
Access-Control-Allow-Credentials: true

How to tell if your site is affected

  • Your API sends Access-Control-Allow-Origin: * on endpoints that return user-specific or private data.
  • The server reflects the request Origin header back without checking it against a list.
  • Access-Control-Allow-Credentials: true is combined with a reflected or very broad origin.
  • You accept the origin "null", or match with a loose pattern such as endsWith(".example.com") that also matches evil-example.com.

How to fix it

  1. Keep an explicit allow-list of origins that really need access and echo back only a matching value.

  2. Send Vary: Origin whenever the header depends on the request origin, so caches do not mix responses.

  3. Use a wildcard only for fully public, credential-free resources such as open data or fonts.

  4. Allow credentials only for specific origins, and never together with a wildcard.

  5. In Next.js set headers in route handlers or next.config; in Express use the cors package with an origin function; in Supabase Edge Functions list your site's origin instead of *.

How ScanAnt checks for it

Verified scanDeep scan

In the verified scan ScanAnt looks for wildcard CORS combined with credentials on pages and endpoints of your own site. In the deep scan with the separate level 3 opt-in, it sends preflight requests and one POST with a foreign Origin to state-changing endpoints that need no login, and records only statuses and headers. Response bodies are not stored. The free quick scan does not test CORS.

Questions

Does CORS protect my API from attackers?

No. It only controls what scripts in other websites can read in a browser. Anyone can call your API with curl, so authentication and authorisation are still required.

Is Access-Control-Allow-Origin: * always a vulnerability?

No. It is fine for public data. It becomes a problem when the endpoint returns data tied to the visitor, and browsers do not send cookies to a wildcard origin anyway.

Why do I see a CORS error in my console?

Your API did not allow the page's origin, or it failed on the preflight request. The fix belongs on the server, not in the browser.

Is CORS the same as CSRF protection?

No. CORS limits reading responses. A cross-site form post is still sent, so CSRF needs SameSite cookies, tokens or Origin checks.

See if your site is affected

Free for any public site, no signup. Need the verified or deep scan? Choose the level on the scan page.

Choose a scan level →