CORS protects the user, not your server. By default, the same-origin policy stops a page from reading responses from other origins. CORS (Cross-Origin Resource Sharing) is the way a server relaxes that rule for origins it trusts.
Why this protects the user: the user's browser holds their cookies and sits on their network. Without the same-origin policy, any site they visit could read their email, their bank page or their company's intranet. CORS decides which other sites may read those responses.
Why it doesn't protect your API:
- Only browsers follow CORS.
curl, Postman and scripts ignore it and can call your API directly. - It doesn't stop requests from being sent. Simple requests reach the server, and CORS only hides the response. So CORS is not a CSRF defence.
- It can't hide API keys or data you send to the browser.
So your server still needs authentication, authorization, validation and rate limits on every endpoint.
When you see a CORS error in development, fix the server's CORS settings or use a dev-server proxy. Don't install extensions that turn CORS off.
- CORS protects the user's data in the browser from other sites.
- CORS is a controlled way to relax the same-origin policy.
- Tools like
curlignore CORS, so it doesn't protect the server. - Simple requests still reach the server, so CORS doesn't stop CSRF.
- The API still needs authentication, authorization and rate limits.