Lab: CSRF with broken Referer validation
This lab's email change functionality is vulnerable to CSRF. It attempts to detect and block cross domain requests, but the detection mechanism can be bypassed.
To solve the lab, use your exploit server to host an HTML page that uses a CSRF attack to change the viewer's email address.
You can log in to your own account using the following credentials:
- With your browser proxying traffic through Burp Suite, log in to your account, submit the "Update email" form, and find the resulting request in your Proxy history.
- Send the request to Burp Repeater. Observe that if you change the domain in the Referer HTTP header, the request is rejected.
Copy the original domain of your lab instance and append it to the Referer header in the form of a query string. The result should look something like this:
- Send the request and observe that it is now accepted. The website seems to accept any Referer header as long as it contains the expected domain somewhere in the string.
history.pushState()function includes a query string with your lab instance URL as follows:
history.pushState("", "", "/?your-lab-id.web-security-academy.net")This will cause the Referer header in the generated request to contain the URL of the target site in the query string, just like we tested earlier.
If you store the exploit and test it by clicking "View exploit", you may encounter the "invalid Referer header" error again. This is because many browsers now strip the query string from the Referer header by default as a security measure. To override this behavior and ensure that the full URL is included in the request, go back to the exploit server and add the following header to the "Head" section:
Referrer-Policy: unsafe-urlNote that unlike the normal Referer header, the word "referrer" must be spelled correctly in this case.
- Store your exploit to solve the lab.