Skip to main content

Security and Risk

CORS

CORS is a browser rule about which sites may call which APIs. It surfaces as a confusing error, and the tempting fix removes a real protection.

Definition

CORS is a browser rule governing whether code running on one website is allowed to call an API belonging to another.

What It Actually Means

By default the browser refuses. Without that default, any site you visited could quietly issue requests to your bank, your email or your company systems using your logged-in session, and read the answers. The restriction is one of the load-bearing protections of the web.

CORS is the controlled exception: a way for a server to say which other origins it is willing to accept calls from.

Why You Hear About It

You hear about it because it produces an error at the worst moment, usually when two things your business owns are being connected.

The pattern is familiar: the site is at one address, the API is at another, someone connects them, and the browser blocks the call with a message about the origin not being allowed. Nothing is broken. The server is fine, the API is fine, and the browser is doing its job.

It matters to you for one reason. The quickest fix is to allow every origin, and it works instantly, which makes it very tempting under deadline pressure.

Why The Quick Fix Is A Problem

Allowing all origins means any website can call that API from a visitor’s browser. If the API is entirely public data, that is harmless and sometimes intended.

If it is behind a login, it is a real exposure, because the browser will attach the user’s session to those calls. A malicious page can then make requests as your logged-in user and read the responses. This is the specific attack the default prevents, and the wildcard setting removes it.

The correct fix is barely more work: list the origins that should be permitted. It takes a few minutes and it is a configuration line rather than a project.

What To Ask

  • Do any of our APIs allow all origins? If yes, is that API genuinely public, with no session behind it?
  • Was this set deliberately or to clear an error? The honest answer is often the second, and it is worth revisiting.
  • Which origins do we actually need? Usually two or three, all known.

The Thing To Understand About It

CORS protects your users’ browsers. It is not a protection on your API.

Anything outside a browser ignores it entirely: a script, a command-line tool, another server. CORS headers are instructions to browsers, and only browsers honour them. So a locked-down CORS policy does not make an API private, and an open one does not make it insecure for non-browser callers, because they were never restricted in the first place.

That distinction matters when a supplier describes CORS as securing an endpoint. It does not. Authentication and authorisation secure an endpoint. CORS decides which web pages may call it on a user’s behalf, which is a different question with a different answer.

More terms are in the glossary.

Portrait of Alexander De Sousa, founder of Digital Royalty
Founder-led
“I’ve put everything I know into how this company works — the standards, the method, the care on every project. It runs through the whole team, and I hold us all to it.”

Alexander De Sousa · Founder LinkedIn

Featured on BBC Radio Solent

Get started

Tell us what you need

A few quick questions, then a straight answer from a real person — usually within a few hours.

Tell us what you're working on

Whether it's a new site, a platform, or a process that shouldn't be manual any more — we'll tell you honestly if we can help.