CORS (Misconfigurations)
What is it
Cross-Origin Resource Sharing (CORS) is a mechanism that allows web browsers to securely access resources (such as data, images, or scripts) on a different domain than the one from which the web page was originally served. By default, web browsers restrict such access due to security concerns, but CORS provides a standardized way to relax these restrictions.
When a web page loaded from one origin (domain, protocol, and port) tries to request resources from another origin, the browser sends an initial "preflight" request to the target server. This preflight request asks for permission to make the actual request and includes information about the intended request (e.g., HTTP method, headers, and content type). The server, in turn, responds with a set of headers indicating whether it allows the requested resource to be accessed by the requesting origin.
These headers are known as CORS headers and are part of the HTTP response. The key CORS headers are:
Access-Control-Allow-Origin: This header specifies the allowed origin(s) that can access the resource. For example, if a server sends "Access-Control-Allow-Origin: example.com", it means that only requests originating from "example.com" will be allowed.
Access-Control-Allow-Methods: This header lists the HTTP methods (e.g., GET, POST, PUT) allowed by the server for the requested resource.
Access-Control-Allow-Headers: This header specifies the allowed headers in the actual request. It helps control which custom headers can be included in the request.
Access-Control-Allow-Credentials: This header indicates whether the requesting origin is allowed to include credentials (such as cookies or authorization headers) in the request.
CORS operates as a security measure to protect users and prevent unauthorized access to resources. It allows server administrators to define fine-grained access policies for their resources, ensuring that only trusted origins can access sensitive data or perform certain actions.
If misconfigured CORS can be abused. Here is a brillant and very well detailed explaination of this.
Exploitation Example
Let's practice with the Lab CORS vulnerability with basic origin reflection from PortSwigger Web Academy
wiener:peterare our creds for the labLet's launch the lab and go to "my account" in our and login with the provided creds

In Burp it looks like this. We are redirected to the
/accountDetailspage that has an apikey.

We need to send this request to the repeater and check if it is vulnerable to CORS. This article on OWASP is really helpful for this purpose.
To do this we add an Origin header and put a random value. We can see that our random value appears in the response header
Access-Control-Allow-Originand that on top of this theAccess-Control-Allow-Credentialsis set to true.See our modified request and the response here

Knowing this we can now make a script to try to get more informations. In our example we will use the exploit server provided along with burp collaborator because the Access logs from the lab is buggy.
Thanks to Lisandre for the exploit script. (I just removed the encoding to base64) It is the cleanest one I have seen so far and also the most readable.
Let's put our script in the exploit server and click on Deliver Exploit to victim

Once stored we click on "deliver to victim"
Now we can check our collaborator. We will have a new request with the content we need.

If we select the string the inspector will decode it from URL encoding for more readability

We just need to take the apikey value and paste it in submit solution and we successfuly exploited a cors misconfiguration.

How to report
Note: Here is an example on how to report it, CVSS score is here as a reference but you should always check out the context of your customer to calculate it
Resources
Last updated