Node.jsInterview preparation
Foundation·Concept·2 min read

What is CORS? Does it protect an API from all clients?

Practice this question

Definition:

CORS is a browser-enforced protocol that lets a server permit selected cross-origin response access. The browser checks response headers and may send a preflight request before the actual request. It is not a firewall: clients outside the browser can still call the API, and some cross-origin requests can be sent even without readable responses.

Key points:

  • CORS tells browsers which origins may read cross-origin responses.

  • It does not stop server clients or replace authentication or CSRF protection.

  • Allow only needed origins, methods and headers for private browser APIs.

  • Credentialed browser requests need explicit permitted origins; a wildcard origin is not a substitute for that configuration.

Interview point:

  • Explain who enforces CORS—the browser—and keep it separate from authorization and CSRF defenses.
Adapted from 02_NODE_EXPRESS_HTTP.md · “What is CORS? Does it protect an API from all clients?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.