Skip to content
XSS Disclosed report Advanced CVE-2018-5172

Content scripts sometimes match the document URI rather than the principal URI

A content script in a browser extension could match the document URI of a built-in feed preview page rather than the principal URI, letting injected JavaScript run inside that privileged preview. With user interaction, this allowed an attacker to download and execute an arbitrary file.

Abdulrahman Alqabandi Follow

Originally disclosed on Mozilla

  • Fixed in 58 days
  • Paid in 2 months
  • Disclosed after 58 days
Text
Created attachment 8949127
feedPreviewPoC.xpi

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36

Steps to reproduce:

1. Install attached PoC extension
2. Once a page appears, click on the button.
3. A prompt will appear, paste by hitting (CTRL+V) then hit 'Enter'
4. Executable file is downloaded and executed.

This is just an example on one content handler, you can do the same with PDFs. Interestingly, JSON previewer cannot have code injected to it.


Actual results:

Injected JS into feed preview which results in RCE with user interaction. 
Video: https://youtu.be/TRrdmuaFzuQ



Expected results:

In bug 1422231 I described how the feed reader preview page can be clickjacked to run arbitrary executable files. Although these previews are not accessible to web, they are for webextensions. This is bad because usually these have other API's that may be used to escalate privilege.

The original report as published on Mozilla's Bugzilla, by Abdulrahman Alqabandi. 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 Mozilla's WebExtensions platform, specifically the built-in preview pages that Firefox renders for certain content types. The researcher, Abdulrahman Alqabandi, filed the report against the general WebExtensions component. The report was disclosed on 6 April 2018.

The report's title frames the issue as content scripts sometimes matching the document URI rather than the principal URI. In practice this means a content script intended for ordinary web pages can be injected into a privileged preview document, and from there escalate to running code on the user's machine.

The reproduction steps are short and depend on an attached proof-of-concept extension, feedPreviewPoC.xpi:

  1. Install the attached PoC extension.
  2. Once a page appears, click on the button.
  3. A prompt appears; paste with CTRL+V and press Enter.
  4. An executable file is downloaded and executed.

The researcher notes this is one example on one content handler and that the same approach works with PDFs. They also observed that the JSON previewer cannot have code injected into it, so the behaviour is not uniform across all preview types.

The stated actual result is injected JavaScript into the feed preview, which results in remote code execution with user interaction. A video walkthrough is linked in the report:

Text
https://youtu.be/TRrdmuaFzuQ

The expected-results section refers back to an earlier bug, 1422231, where the researcher described how the feed reader preview page can be clickjacked to run arbitrary executable files. The key point made there is that these preview pages are not reachable from the web but are reachable from WebExtensions. That matters because extensions usually hold other APIs that can be used to escalate privilege.

The report does not give a bounty amount, a CVSS score, or a description of the fix.

Root cause

The report does not walk through the matching mechanism; it demonstrates the behaviour with a proof-of-concept extension. Content script matching is normally performed against the principal of the page, the origin that owns the document. If matching instead consults the document URI, a privileged internal page whose document URI looks like an ordinary web address can satisfy a content script's match pattern. The extension's script then runs with the privileges of the preview page rather than the sandbox of a normal web page.

The report states the mechanism as a title-level observation rather than walking through the matching code, so the exact code path is not documented here. The report notes only that the JSON previewer cannot have code injected into it.

Impact

An attacker who can get a victim to install a malicious extension can have script injected into a privileged preview page. Combined with user interaction, the researcher demonstrated download and execution of an executable file. The report frames the real danger as privilege escalation: preview pages are closed to the web but open to extensions, and extensions carry APIs that a web page does not. The hedges matter: execution requires the user to click a button and paste into a prompt, so this is not silent compromise.

How this kind of bug works

Browsers isolate privileged internal pages from web content by giving them a principal that web origins cannot obtain. Content scripts are the exception: they are injected by the extension system into pages the extension is allowed to touch, and the decision of which pages those are is made by matching rules against a URI. If the wrong URI is used for that decision, the isolation boundary is drawn in the wrong place.

The general pattern is a confused deputy. The component that decides access (the matching logic) trusts one identifier, while the component that enforces privilege (the document loader) trusts another. Anywhere two identifiers for the same resource can diverge, for example a document URI versus a principal, a redirect target versus the original request, or a fragment versus the path, there is room for a match that should not happen.

Defences are straightforward in principle: match on the principal, not on a URI that can be influenced; treat internal schemes and preview documents as a distinct class that content scripts cannot match by default; and keep the set of privileged pages that extensions may touch explicit and small.

How to test for it

  1. Enumerate the browser's internal and preview pages: feed previews, PDF viewers, JSON viewers, error pages, and anything rendered from a resource:, about: or similar scheme.
  2. Build a minimal extension whose content script uses a broad match pattern, and observe whether the script executes on those pages. Log the document URI and the principal the page reports.
  3. Compare the two. A positive result is a privileged page where the content script runs and where the document URI differs from the principal, or where the page exposes APIs a normal web page would not.
  4. Test the same page reached through different routes: direct navigation, a link from a web page, a redirect, and a download or handler invocation. Matching bugs often appear on only one route.
  5. Check whether injected script can reach privileged actions, for example triggering a download or invoking an extension API, rather than merely rendering text.

Common false positives: the script running on a page that is genuinely a normal web origin; the page being privileged but the injected script still confined to a sandbox with no useful capability; and behaviour that only reproduces with an extension the user would never install, which weakens the impact argument.

How it is fixed

The report does not describe a fix.

Hunting notes

This class hides wherever a browser or application renders trusted content from an untrusted source: previewers, viewers, error pages, and handler-generated documents. Recon signals include internal schemes appearing in navigation, preview pages that are reachable from extensions but not from the web, and any place where a document URI is logged differently from the origin.

To make a report land, show the full chain: the match that should not happen, the privileged context reached, and a concrete action taken from there. State the user interaction required, as this report does, and note which variants of the feature are and are not affected, since that helps triage and shows the boundary of the bug.

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. 6 min read.

What happened, in plain words

Firefox can show built-in preview pages for certain kinds of content instead of just downloading them. When you open a news feed, for example, Firefox may render a special page that displays the feed nicely. These preview pages are part of the browser itself, not a website, so they are trusted more than ordinary web pages.

Abdulrahman Alqabandi reported a problem with how browser extensions (add-ons) get their code injected into pages. Extensions can add small scripts, called content scripts, to pages they are allowed to touch. The browser decides which pages those are by comparing the page's address against rules the extension declares. The report demonstrates an extension's script running inside a trusted preview page. In plain terms: the browser looked at the address the page appears to have, instead of the identity that actually owns the page. That let an extension's script run inside a trusted preview page, where it should not have been allowed.

From there the researcher showed that the injected script could get an executable file downloaded and run on the user's computer. That is remote code execution, meaning code from outside ends up running on your machine. It was not silent: the user had to click a button and paste something into a prompt.

The report was filed against Mozilla's WebExtensions component. It was disclosed on 6 April 2018.

The reproduction steps rely on an attached proof-of-concept extension, feedPreviewPoC.xpi:

  1. Install the attached PoC extension.
  2. Once a page appears, click on the button.
  3. A prompt appears; paste with CTRL+V and press Enter.
  4. An executable file is downloaded and executed.

The researcher notes this is one example on one content handler and that the same approach works with PDFs. They also observed that the JSON previewer cannot have code injected into it, so not every preview type behaves the same way.

The stated actual result is injected JavaScript into the feed preview, which results in remote code execution with user interaction. A video walkthrough is linked in the report:

Text
https://youtu.be/TRrdmuaFzuQ

The expected-results section refers back to an earlier bug, 1422231, where the researcher described how the feed reader preview page can be clickjacked to run arbitrary executable files. Clickjacking means tricking someone into clicking something they did not intend to click. The key point is that these preview pages are not reachable from the web but are reachable from WebExtensions. That matters because extensions usually hold other APIs, programming interfaces that give access to browser features, and those can be used to escalate privilege.

The report does not give a bounty amount, a CVSS score, or a description of the fix.

In general, how this kind of bug works

Browsers keep their own internal pages separate from websites. A website should not be able to reach into a browser settings page or a built-in viewer, because those pages are trusted and often have powers a website does not. Think of it like the staff-only area of a shop: customers can walk the floor, but the back room is off limits.

Content scripts are the exception. They are pieces of code an extension injects into pages, and the browser decides which pages are allowed by matching rules against an address. If the wrong address is used for that decision, the line between "allowed" and "not allowed" is drawn in the wrong place, and a script slips into a room it should never enter.

The general pattern is called a confused deputy. One part of the system checks one label, while another part enforces access based on a different label. Whenever two labels for the same thing can disagree, for example the address a document appears to have versus the identity that actually owns it, there is room for a match that should not happen.

The usual defences are simple in principle: decide access using the real owner of the page, not an address that can be influenced; treat internal and preview pages as a separate category that extensions cannot touch by default; and keep the list of trusted pages an extension may reach short and explicit.

If you want to look for this kind of issue yourself, a sensible approach is:

  1. List the browser's internal and preview pages: feed previews, PDF viewers, JSON viewers, error pages, and anything built from internal schemes.
  2. Build a small extension whose content script uses a broad matching rule, and see whether the script runs on those pages. Record the address the page reports and the identity it reports.
  3. Compare the two. A useful finding is a trusted page where the script runs and the two differ, or where the page offers powers a normal website would not.
  4. Try reaching the same page by different routes: typing the address, following a link, a redirect, or opening a file. Matching bugs often show up on only one route.
  5. Check whether the injected script can actually do something privileged, such as starting a download, rather than only changing text on screen.

Watch out for false alarms: a script running on a page that is really an ordinary website; a trusted page where the script still cannot do anything useful; and behaviour that only appears with an extension nobody would install, which weakens the case.

The report does not describe a fix.

This class of bug hides wherever a browser or application displays trusted content built from an untrusted source: previewers, viewers, error pages and documents generated by handlers. Signs worth watching for include internal schemes appearing in navigation, preview pages reachable from extensions but not from the web, and places where the address a page reports differs from its real owner.

To make a report convincing, show the whole chain: the match that should not happen, the trusted context reached, and a concrete action taken from there. Say what user interaction is required, as this report does, and note which variants of the feature are and are not affected, because that helps the people triaging the bug see its boundaries.

Glossary

  • WebExtensions: Mozilla's system for building browser add-ons that can add features to Firefox.
  • Content script: a small piece of code an extension injects into web pages it is allowed to touch.
  • Document URI: the address a page appears to have.
  • Principal URI: the identity that actually owns a page, used to decide what it is allowed to do.
  • Privilege escalation: gaining more power or access than you should have.
  • Remote code execution (RCE): code from outside ends up running on your computer.
  • Proof of concept (PoC): a small demonstration that shows a bug is real.
  • Content handler: the part of the browser that decides how to display or deal with a type of content.
  • Clickjacking: tricking someone into clicking something they did not mean to click.
  • API: a programming interface that lets code use features of a system, such as the browser.
  • Confused deputy: a situation where one part of a system checks one label while another enforces access using a different label.
  • CVSS: a standard scoring system for rating the severity of a security bug.
  • Bounty: a payment some organisations give for reporting a security bug.

More by Abdulrahman Alqabandi

View all

33 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.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.