Exploiting Misconfigured CORS
Exploiting Misconfigured CORS
Exploiting Misconfigured CORS
Utkarsh Tiwari
Hi! Hope you guys are doing well. CORS was introduced along with HTML 5. It is a great feature which allows user to
overcome the restrictions placed by Same Origin Policy and make cross-origin HTTP request. But if not configured
properly, it capable of producing disastrous results. Below I have explained different scenarios for exploiting CORS.
1. https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
2. https://www.keycdn.com/support/cors
3. https://enable-cors.org/
4. https://www.maxcdn.com/one/visual-glossary/cors/
Point to consider while testing CORS Misconfiguration:
1) You can’t disable SOP entirely and expose your site to public by using configuration like:
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Then you’ll get an error in your browser console stating that wildcard (*) in Access-Control-Allow-Origin header
is not allowed when credential flag is true.
2) Whenever you come across any response in which Access-Control-* headers are present but in request no
Origin header is present, then in those cases there is possibility that application is dynamically generating the
Access-Control-* headers in response based on the user supplied values in request.
3) It is important to remember that in scenarios where Origin header and Access-Control-* headers are not
present in the request and response, there also there is possibility that application can dynamically generate
Access-Control-* in response on receiving the Origin header in request.
4) If the server specifies a single origin rather than the * wildcard, then the server should also include Origin in
the Vary response header — to indicate to clients that server responses will differ based on the value of
the Origin request header.
Because of the above reasons/restrictions, many servers programmatically generate the Access-Control-Allow-Origin
header based on the user-supplied Origin value.
• Case 2: Check application for instances where application is sending sensitive information in response specific to
the logged in user without validating the session of the user, create a working exploit and report it.
• Case 2: When regex used on server is accepting all origins which ends with example.com
Change the value of origin header in the request to evilexample.com and see whether it is over-riding value of
Access-Control-Allow-Origin (that is: example.com) in response or not.
Figure 7: Response of application showing that the regex placed on server for validating origin has been bypassed
• Case 3: When regex used on server is accepting all origins which begins with example.com
Change the value of origin header in the request to example.com.evil.com and see whether it is over-riding
value of Access-Control-Allow-Origin (that is: example.com) in response or not.
Figure 9: Response of application showing that the regex placed on server for validating origin has been bypassed
Figure 13: Image showing request generated by the malicious page and response received from the server
Figure 14: Image showing malicious page was successfully able to make the Cross Origin request, bypassing the protection placed by the application
Note: The above exploitation was successful because the HTML file containing CORS exploitation code was residing on
the local file system and thus the Origin: Null header was automatically appended in the request.
• References:
a) https://yassineaboukir.com/blog/cors-exploitation-data-exfiltration-when-allowed-origin-is-set-to-null/
b) https://paper.tuisec.win/detail/748995db294e600