Skip to content
Access control Disclosed report Intermediate

CSP sandbox allows script execution with data: scheme hyperlink

A page protected by a CSP sandbox directive still allowed script to run when a user clicked a hyperlink pointing to a data: URL, which executed on the protected page's origin. An attacker could use this to run arbitrary scripts on resources that were meant to be sandboxed.

Muneaki Nishimura Follow

Originally disclosed on Mozilla

  • Fixed in 3.5 years
  • Paid in 14 months
  • Disclosed after 3.5 years
Text
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36

Steps to reproduce:

Launch following URL and click a hyperlink for data: URL.
Then script in javascript: URL is prohibited but script in data: URL is executed on caller's origin (csp.csrf.jp).
http://csp.csrf.jp/sandbox/



Actual results:

Above URL is protected with CSP sandbox that has been introduced on Nightly 50 but there still be a way to execute script on a protected document.
By using this an attacker can execute arbitrary scripts on protected resources.


Expected results:

W3C spec of CSP sandbox requires UA to apply iframe-sandbox equivalent protection.
https://www.w3.org/TR/CSP2/#sandbox-usage
Firefox's iframe-sandbox in properly prohibits script execution with data: hyperlink like this.
http://alice.csrf.jp/iframe-sandbox.html
CSP sandbox should do so.

The original report as published on Mozilla's Bugzilla, by Muneaki Nishimura. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 5 min read.

What the report shows

The target is Firefox's implementation of the CSP sandbox directive, tracked in the Core: DOM: Security component. The researcher, Muneaki Nishimura, tested a page that is protected by a CSP sandbox, introduced on Nightly 50, and found that script execution was still possible on the protected document.

The test page is:

Text
http://csp.csrf.jp/sandbox/

The steps to reproduce, as given in the report:

  1. Launch the URL above.
  2. Click a hyperlink that points to a data: URL.

The researcher notes that a javascript: URL is prohibited in this context, but a script inside a data: URL is executed on the caller's origin, which in this case is csp.csrf.jp. The user agent string recorded in the report is:

Text
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36

In the actual results, the researcher states that although the page is protected with a CSP sandbox, there is still a way to execute script on the protected document, and that an attacker can use this to execute arbitrary scripts on protected resources.

In the expected results, the researcher cites the W3C CSP2 specification, which requires the user agent to apply protection equivalent to iframe sandboxing:

Text
https://www.w3.org/TR/CSP2/#sandbox-usage

As a comparison, the report points to a page that uses Firefox's iframe sandbox, which the researcher says properly prohibits script execution through a data: hyperlink like this:

Text
http://alice.csrf.jp/iframe-sandbox.html

The report concludes that CSP sandbox should do the same. The platform records the severity as medium, with the weakness classified as privilege escalation. The report does not give a bounty amount or describe the fix.

Root cause

The report points to a gap between two sandboxing mechanisms. CSP sandbox is specified to give a document the same restrictions as the sandbox attribute on an iframe, and Firefox's iframe sandbox already blocks script execution when a data: hyperlink is followed. The CSP sandbox path does not apply the same checks, so a data: document opened from the sandboxed page runs its script with the caller's origin. The javascript: scheme is blocked, while the data: scheme is not.

Impact

A page that relies on CSP sandbox to neutralise untrusted content would not be protected: a data: hyperlink can get script to run in the origin of the sandboxed page. The report hedges this as the ability to execute arbitrary scripts on protected resources. It does not demonstrate a specific attack chain beyond the test page.

How this kind of bug works

Sandboxing is meant to be a capability restriction: the document keeps its origin for some purposes but loses script execution, form submission, top-level navigation and similar powers unless the sandbox flags re-enable them. CSP sandbox reuses the same flag vocabulary, so a correct implementation should funnel both the iframe attribute and the header through one enforcement point.

Bypasses usually come from paths that create a new document rather than executing in the existing one. Following a link to a data: URL, a blob: URL or a javascript: URL can produce a document whose origin and sandbox state are computed separately from the parent's. If the new document is not marked as sandboxed, or if its origin is inherited from the caller, the restriction is lost. The same class of mistake appears when a sandboxed document can navigate itself to a non-sandboxed context, or when a plugin, download or srcdoc frame escapes the flag set.

Defences are structural: apply the sandbox flags to every document created from a sandboxed one, treat inherited origins as still sandboxed, and block script-bearing schemes consistently rather than one scheme at a time.

How to test for it

  1. Find a page that sets CSP sandbox in a response header, ideally without allow-scripts. Pages that render user content are the best candidates.
  2. Confirm the baseline: inline script and javascript: links should not run. If they do, the header is not being applied at all and you are looking at a different bug.
  3. Try navigations that create a new document: a link to a data:text/html URL containing a script, a link to a blob: URL, a form target, and a link with target pointing at a new window.
  4. Observe whether the new document's script runs and, if it does, which origin it reports. A positive result is script execution plus an origin equal to the sandboxed page's origin, or access to that page's DOM or storage.
  5. Repeat with the iframe sandbox attribute on the same content. If the attribute blocks the payload but the header does not, you have a strong comparison to include in the report.

Common false positives: the payload runs but in an opaque origin, so it cannot read anything belonging to the target; the page also sets allow-scripts together with allow-same-origin, which is a known and documented weakness rather than a bypass; or the script only executes because the header was missing on that particular response, for example on an error page or a cached variant.

How it is fixed

Hunting notes

This class of bug hides in features that render untrusted HTML under a restrictive header: webmail, documentation and wiki renderers, pastebins, issue trackers and preview endpoints. Recon signals include a CSP header containing sandbox without allow-scripts, or with allow-scripts but no allow-same-origin, and any place where user content is served from the application's own origin.

To make a report land, show the exact header, the payload, and the observed execution with the origin it ran in. A side-by-side with the iframe sandbox attribute, as in this report, makes the deviation from the specification obvious and removes any argument that the behaviour is intended.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 7 min read.

What happened, in plain words

Websites can send instructions to your browser along with each page. One of those instructions is called a Content Security Policy, or CSP. It is a list of rules the browser must follow while showing that page. One rule in that list is sandbox. When a page is served with a CSP sandbox rule, the browser is supposed to treat the page as untrusted: the page should lose powerful abilities, most importantly the ability to run scripts.

A script is a small program that runs inside your browser. If a page can run scripts, it can read things on the page, change what you see, and act on your behalf towards the site that served it. That is why a site that shows content written by strangers, such as comments or pasted HTML, may wrap that content in a sandbox: even if the content contains a script, the browser should refuse to run it.

The researcher, Muneaki Nishimura, tested Firefox's implementation of the CSP sandbox rule. The rule had been introduced on Nightly 50, an early test build of Firefox. The test page was:

Text
http://csp.csrf.jp/sandbox/

The steps to reproduce, as given in the report:

  1. Launch the URL above.
  2. Click a hyperlink that points to a data: URL.

A data: URL is a way of putting a whole document inside the address itself, instead of pointing at a file on a server. For example, a link can carry a small HTML page, script included, directly in its address. Clicking such a link makes the browser build a new page from that text.

The researcher found that a javascript: URL was correctly blocked in this situation. A javascript: URL is an address that contains script instead of a page; clicking it asks the browser to run that script. That one was stopped. But a script hidden inside a data: URL still ran, and it ran as if it belonged to the site that hosted the link, csp.csrf.jp. In other words, the sandbox stopped one route to running script and left another route open.

The browser version recorded in the report is:

Text
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36

In the actual results, the researcher states that although the page is protected with a CSP sandbox, there is still a way to execute script on the protected document, and that an attacker can use this to execute arbitrary scripts on protected resources. In plain terms: the lock was on the door, but a window had been left open.

In the expected results, the researcher cites the W3C CSP2 specification, which requires the browser to apply protection equivalent to iframe sandboxing:

Text
https://www.w3.org/TR/CSP2/#sandbox-usage

An iframe is a page embedded inside another page, like a picture frame on a wall. The sandbox attribute on an iframe is the older, well-known way to restrict such an embedded page. The specification says the CSP sandbox rule should give a page the same restrictions as that attribute. As a comparison, the report points to a page that uses Firefox's iframe sandbox, which the researcher says properly prohibits script execution through a data: hyperlink like this:

Text
http://alice.csrf.jp/iframe-sandbox.html

The report concludes that CSP sandbox should do the same. The platform records the severity as medium, with the weakness classified as privilege escalation. The report does not give a bounty amount or describe the fix.

In general, how this kind of bug works

Sandboxing is a way of taking abilities away from a page on purpose. The page still exists and is still displayed, but it loses script execution, form submission, the ability to navigate the whole window, and similar powers, unless the sandbox settings explicitly give them back. Think of a visitor badge that lets someone into the lobby but not into the offices.

CSP sandbox and the iframe sandbox attribute use the same vocabulary of settings, so a correct implementation should send both through one enforcement point. When they do not, the two can drift apart, and one of them ends up weaker than the other.

Bypasses usually come from paths that create a new document rather than running code in the existing one. Following a link to a data: URL, a blob: URL or a javascript: URL can produce a document whose origin and sandbox state are worked out separately from the parent page. Origin is the identity a page has in the browser: pages with the same origin can read each other's content and storage. If the new document is not marked as sandboxed, or if its origin is inherited from the page that linked to it, the restriction is lost. The same class of mistake appears when a sandboxed document can navigate itself to a context that is not sandboxed, or when a plugin, a download or an srcdoc frame escapes the set of restrictions.

Defences are structural: apply the sandbox settings to every document created from a sandboxed one, treat inherited origins as still sandboxed, and block script-bearing schemes consistently rather than one scheme at a time.

In general, how to test for it

  1. Find a page that sets CSP sandbox in a response header, ideally without allow-scripts. Pages that render user content are the best candidates.
  2. Confirm the baseline: inline script and javascript: links should not run. If they do, the header is not being applied at all and you are looking at a different bug.
  3. Try navigations that create a new document: a link to a data:text/html URL containing a script, a link to a blob: URL, a form target, and a link with target pointing at a new window.
  4. Observe whether the new document's script runs and, if it does, which origin it reports. A positive result is script execution plus an origin equal to the sandboxed page's origin, or access to that page's DOM or storage.
  5. Repeat with the iframe sandbox attribute on the same content. If the attribute blocks the payload but the header does not, you have a strong comparison to include in the report.

Common false positives: the payload runs but in an opaque origin, so it cannot read anything belonging to the target; the page also sets allow-scripts together with allow-same-origin, which is a known and documented weakness rather than a bypass; or the script only executes because the header was missing on that particular response, for example on an error page or a cached variant.

In general, how it is fixed

In general, where this bug hides

This class of bug hides in features that render untrusted HTML under a restrictive header: webmail, documentation and wiki renderers, pastebins, issue trackers and preview endpoints. Recon signals include a CSP header containing sandbox without allow-scripts, or with allow-scripts but no allow-same-origin, and any place where user content is served from the application's own origin.

To make a report land, show the exact header, the payload, and the observed execution with the origin it ran in. A side-by-side with the iframe sandbox attribute, as in this report, makes the deviation from the specification obvious and removes any argument that the behaviour is intended.

Glossary

  • CSP (Content Security Policy): a set of rules a website sends to the browser to limit what a page may do, such as which scripts may run.
  • sandbox directive: a CSP rule that tells the browser to treat a page as untrusted and remove powerful abilities, most importantly script execution.
  • Script: a small program that runs inside the browser as part of a page.
  • data: URL: an address that carries a whole document inside itself rather than pointing at a server file.
  • javascript: URL: an address that contains script; clicking it asks the browser to run that script.
  • blob: URL: an address that points to data held in the browser's memory, often created by a script.
  • Origin: the identity of a page in the browser, made of scheme, host and port; pages with the same origin can read each other's content and storage.
  • Opaque origin: an origin that matches nothing else, so the page cannot read anything belonging to another site.
  • Iframe: a page embedded inside another page.
  • sandbox attribute: an attribute on an iframe that restricts what the embedded page may do.
  • allow-scripts: a sandbox setting that gives script execution back to a sandboxed page.
  • allow-same-origin: a sandbox setting that lets a sandboxed page keep its normal origin.
  • srcdoc frame: an iframe whose content is written directly in the attribute rather than loaded from a URL.
  • User agent: the browser and its version, as reported to websites.
  • Privilege escalation: a situation where something gains a power it was not meant to have.
  • W3C specification: a written standard that describes how web technology should behave.
  • Regression test: a test kept in place to make sure a fixed bug does not come back.
  • False positive: a test result that looks like a bug but is not one.

More by Muneaki Nishimura

View all

74 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.