CORS Misconfiguration
CORS Misconfiguration
Description
CORS (Cross-Origin Resource Sharing) misconfiguration occurs when a web application improperly configures its CORS policy, allowing unauthorized domains to access its resources, leading to potential data leaks or unauthorized actions.
Example with Scenario
Scenario: A web application has a misconfigured CORS policy that allows any origin to access its API. An attacker can exploit this to steal sensitive data by making requests from a malicious site.
Payloads and Test Cases
Payloads
Wildcard Origin:
Insecure Allow-Origin Header:
Allowed Methods:
Test Cases
Wildcard Origin:
Payload:
Test Case:
Insecure Allow-Origin Header:
Payload:
Test Case:
Allowed Methods:
Payload:
Test Case:
Mitigation
Restrict Allowed Origins:
Specify a strict allow-list of trusted origins.
Avoid using wildcard (*) in the Access-Control-Allow-Origin header.
Limit Allowed Methods:
Restrict the allowed HTTP methods to only those necessary.
Avoid allowing all methods (e.g., GET, POST, PUT, DELETE).
Validate Preflight Requests:
Validate and properly handle preflight OPTIONS requests.
Ensure the Access-Control-Allow-Origin and other headers are correctly set.
Use Credentials Securely:
Avoid using
Access-Control-Allow-Credentials: true
unless necessary.Ensure the allowed origins are secure when using credentials.
Content Security Policy (CSP):
Implement a strict Content Security Policy to mitigate the impact of CORS misconfigurations.
Use CSP to control the sources of content and reduce the risk of data leaks.
Last updated