Lesson 2 of 9 · 23m
CORS, Preflights, and Credential Boundaries
Read CORS as a consent mechanism for cross-origin reads and dangerous request shapes, not as a general server authorization control.
CORS is one of the most misunderstood controls in web security. It does not stop attackers from sending requests. It does not authenticate users. It is the browser asking, on behalf of a web origin, whether another origin is willing to expose a response or accept a non-simple request shape. When you treat it as a server security boundary, you end up protecting the wrong thing.
Start with what the browser already allows
HTML forms have sent cross-site requests since long before CORS existed. Plain navigation, image embedding, script inclusion, and form submission do not need CORS permission.
<form method="POST" action="https://api.service.example/profile">
<input name="display_name" value="Mira">
<button>Save</button>
</form>This is why a server cannot rely on the absence of CORS headers to stop state-changing requests. CSRF defenses belong to the application: SameSite cookies, anti-CSRF tokens, strict authorization checks, and careful content-type handling.
Simple versus preflighted requests
A request is “simple” only when it uses limited methods, headers, and content types. JSON APIs often cross the preflight line because of content-type: application/json or custom authorization headers.
OPTIONS /v1/report HTTP/1.1
Origin: https://dashboard.example
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type, x-csrf-tokenThe server answers with permission metadata:
Access-Control-Allow-Origin: https://dashboard.example
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: content-type, x-csrf-token
Access-Control-Max-Age: 600
Vary: OriginA missing or mismatched preflight response means the browser never sends the actual request in that mode. That does not mean other clients cannot send it.
Credentials change the rules
When fetch uses credentials: 'include', cookies and other ambient credentials are part of the request. The response exposure rules get stricter:
fetch('https://api.service.example/v1/me', {
credentials: 'include'
});The response cannot use a wildcard origin with credentials:
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: trueThat combination is invalid. Reflecting arbitrary Origin values while allowing credentials is worse: it can turn cross-site request sending into cross-site response reading. Use an explicit allowlist and cache Vary: Origin correctly.
CORS is response exposure control
A successful CORS exchange means “this response may be exposed to that requesting origin under these constraints.” It does not mean “this user is allowed to perform this action.” Authorization still belongs server-side, per object and per operation.
Browser check: may this web origin read the response?
Server check: may this principal perform this operation?When a scanner reports “CORS misconfiguration,” ask what sensitive data becomes readable cross-origin and what ambient credentials are included. Without that impact chain, the finding is often noise.
Field notes
Access-Control-Allow-Origin: nullis dangerous because sandboxed documents and some local contexts can produce anullorigin.- Preflight success does not prove actual response exposure; inspect the final response headers too.
Access-Control-Allow-Headersis not an authorization mechanism for custom security headers.- Caching a CORS response without varying on
Origincan leak permissions to the wrong caller. - Non-browser clients ignore CORS. If curl can perform the action, CORS was never the control protecting it.
Was this lesson helpful?