How does CORS behave differently for requests made from a mobile app or server-to-server call compared to a browser-based web app?
Short answer
CORS is exclusively a browser-enforced restriction -- it has no effect whatsoever on non-browser HTTP clients like mobile apps (using HttpClient/URLSession), server-to-server calls, or tools like curl/Postman, since there's no browser present to enforce the same-origin policy or…
Advertisement
AModel answer
CORS is exclusively a browser-enforced restriction -- it has no effect whatsoever on non-browser HTTP clients like mobile apps (using HttpClient/URLSession), server-to-server calls, or tools like curl/Postman, since there's no browser present to enforce the same-origin policy or send preflight requests. This is a common point of confusion: developers sometimes mistakenly believe CORS provides genuine API security, when it's purely a client-side browser convenience/safety mechanism that a non-browser client can simply ignore entirely.
Example
// This works perfectly fine from a mobile app or curl, with ZERO CORS restrictions: // curl https://api.mycompany.com/orders -H "Authorization: Bearer xyz" // No preflight, no Origin header check -- CORS simply doesn't apply outside a browser
Real-world example
A security review corrects a misconception that a strict CORS policy was 'protecting' an API, clarifying that anyone using Postman, curl, or a mobile app can call the API directly with zero CORS restrictions -- real authorization checks are the actual security boundary, not CORS.
Likely follow-ups
- What IS the actual security boundary if CORS doesn't protect against non-browser clients?
- Why do developers commonly conflate CORS with API security?
Related topics