Cross-Origin Resource Sharing (CORS)
A mechanism allowing servers to specify which origins can access their resources, relaxing Same-Origin Policy. Misconfigurations can expose sensitive data.
Cross-Origin Resource Sharing (CORS) is a mechanism that allows servers to specify which origins can access their resources, relaxing the Same-Origin Policy in a controlled manner. Misconfigured CORS can lead to sensitive data exposure.
How CORS Works
When a browser makes a cross-origin request, it sends an Origin header. The server responds with Access-Control-Allow-* headers specifying what's permitted. For complex requests, a preflight OPTIONS request is sent first.
CORS Response Headers
Access-Control-Allow-Origin: https://trusted.com
Access-Control-Allow-Methods: GET, POST, PUT
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 86400