Cross-origin resource sharing meaning, in plain words

CORS lets a server permit another site to use its data in the browser. What the WHATWG Fetch Standard defines, and what the OWASP CORS cheat sheet warns against.

Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated

CORS is a mechanism that permits data use from another site. It stands for cross-origin resource sharing. The browser's same-origin policy blocks reading from another site, and CORS lets the server declare that this reading is allowed. The WHATWG Fetch Standard describes CORS as a mechanism layered on HTTP by which a response can declare that it may be shared with other origins.

How does CORS work?

It resembles a company reception desk where a list says in advance, "documents may be shown to people from this business partner". Only those on the list can receive the documents.

When a browser sends a request to another origin, it attaches its own origin in the Origin header. If the server permits that origin in the Access-Control-Allow-Origin header of the response, the browser hands the response to the page's script. The Fetch Standard allows this header to return the value of the request's Origin, or "*", which means every party. When credentials such as cookies are involved, Access-Control-Allow-Credentials also comes into play.

Depending on conditions, a confirmation request (a preflight) is sent before the real request. Examples of permission granted wrongly are collected in the page on CORS misconfiguration. The free URL check gives an outside view of your site, but it is not a review of your CORS rules.

Why does CORS matter?

The OWASP CORS Security Cheat Sheet states that CORS is not access control. It is a rule that applies only to scripts in the browser. For that reason it advises the server to apply authentication and authorization to every request, as if CORS did not exist.

A typical mistake is a configuration that returns the request's Origin as permission without checking it. OWASP warns that doing this on a response that carries credentials lets any site read an authenticated response. It also lists allowing null and loosely written pattern matching as settings to avoid.

Ask your production company for the list of origins it allows, and the reason for each. A permission nobody can explain is a candidate for review.

Related terms

  • Same-origin policy: a browser rule that stops one site from reading data from another
  • CORS misconfiguration: permission granted so widely that other sites can read information
  • CSRF: an attack that makes a logged-in user perform an action they did not intend
  • API: a defined entrance through which software exchanges data

Frequently asked questions

If a CORS error appears, will allowing every site fix it?

The display may work, but that does not make it safe. OWASP lists allowing without checking the requester, and a wide permission on responses that carry credentials, as settings to avoid. Allow only the parties that need access.

If I configure CORS correctly, do I still need access control?

You still need it. OWASP says CORS is only a rule that works inside the browser, and advises that the server check authentication and authorization on every request as if CORS did not exist.

Next step

The page on CORS misconfiguration shows wrongly granted permission and the order of review. To talk through your settings, contact us.

Frequently asked questions

If a CORS error appears, will allowing every site fix it?

The display may work, but that does not make it safe. OWASP lists allowing without checking the requester, and a wide permission on responses that carry credentials, as settings to avoid. Allow only the parties that need access.

If I configure CORS correctly, do I still need access control?

You still need it. OWASP says CORS is only a rule that works inside the browser, and advises that the server check authentication and authorization on every request as if CORS did not exist.

See what an attacker can see, today

The free URL check returns a grade in under a minute. For costs and next steps, book a free consultation.