Repaso
EspaƱol
Backend & APIsIntermediateAPI-12

Which statement about CORS is correct?

Options

  1. It protects your API from curl and from server-to-server calls
  2. It is enforced by browsers; the server lists the allowed origins (Correct option)
  3. It encrypts the traffic that moves between browser and server
  4. It replaces authentication on the API for trusted websites

Answer

It is enforced by browsers; the server declares allowed origins via Access-Control-Allow-Origin

Why

Browsers block a web page from reading responses from a different origin (domain/port) by default: the same-origin policy.

CORS is how a server says 'it's OK, pages from https://myapp.com may read my responses', via Access-Control-Allow-Origin.

Only browsers enforce it. curl, Postman or another server ignore CORS completely, so it is not a security wall for your API.

Remember

CORS is a browser rule, not API protection.

Key terms

Practice this question in Repaso