view-source: pages can be used to gain cross-origin access to restricted domains
A browser extension could execute code in a view-source page of a restricted domain, which then linked to the normal page and gained access to a privileged API. This allowed the extension to access navigator.mozAddonManager, which should be blocked on that domain.
Originally disclosed on Mozilla
- Fixed in 17 months
- Paid in 17 months
- Disclosed after 17 months
Created attachment 8941930
AMO.zip
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Steps to reproduce:
1. Install attached extension
2. Click on the green browser action
3. Click on the button that appears
I noticed that the browserAction popup can execute any code on 'view-source:https://addons.mozilla.org/' and then I noticed that the view-source'd AMO page can link to the non-view-source'd one and has access to it.
I use this to my advantage as the 'navigator.mozAddonManager' is not available in the view-source version but is in the normal web page one.
Actual results:
We have access to navigator.mozAddonManager
Expected results:
Block view-source:https://addons.mozilla.org/ from being accessed by browser.tabs.executeScript (coming from browserAction popup) as it is blocked within 'https://addons.mozilla.org/' (without view-source)
What the report shows
The target is a WebExtension, and the feature under scrutiny is the browserAction popup. The researcher supplied a proof-of-concept extension as an attachment (AMO.zip) and gave three reproduction steps:
- Install the attached extension.
- Click on the green browser action.
- Click on the button that appears.
The observation behind the report is that the popup can execute arbitrary code in the context of view-source:https://addons.mozilla.org/. From there, the researcher noticed that the view-source'd AMO page can link to the non-view-source'd page and has access to it. The reason this matters is stated directly: navigator.mozAddonManager is not available in the view-source version, but it is available in the normal web page.
The reported outcome is access to navigator.mozAddonManager. The expected behaviour, in the researcher's words, is that view-source:https://addons.mozilla.org/ should be blocked from being accessed by browser.tabs.executeScript coming from a browserAction popup, in the same way it is blocked within https://addons.mozilla.org/ without the view-source prefix.
The report is filed against WebExtensions.
Root cause
The report points to a mismatch in how the same origin is treated depending on the scheme prefix. The normal AMO page is protected: script injection into it from the popup is blocked. The view-source: variant of the same URL is not blocked, so browser.tabs.executeScript can run code there. The report does not explain why the check fails for the view-source: variant.
The second half of the issue is the link from the view-source document to the live page. The view-source'd AMO page can link to the non-view-source'd page and has access to it, so code in the view-source context can reach navigator.mozAddonManager, which the view-source page itself does not expose.
Impact
Within the report's own framing, the impact is privilege escalation: an extension popup gains script execution against a restricted domain and, through it, access to navigator.mozAddonManager. The report does not enumerate what an attacker could do with that object, so the practical consequences beyond the access itself are not described.
How this kind of bug works
Browsers restrict which pages an extension may script. The restriction is usually expressed as a set of match patterns and a check performed when tabs.executeScript (or an equivalent API) is called. The check has to answer one question: is this tab's document one the extension is allowed to touch?
Bugs appear when the answer is computed from something that does not faithfully represent the document's origin. Schemes such as view-source:, blob:, filesystem: and data: wrap or derive from another document, and a naive comparison against the raw URL string can miss the wrapped origin. If the guard blocks https://example.com/ but not view-source:https://example.com/, the wrapper becomes a bypass.
The second ingredient is inherited privilege. A document loaded through a wrapper may still be able to navigate to, or hold a reference to, the underlying page, and the underlying page may expose privileged interfaces that the wrapper does not. Any code that reaches the wrapper then reaches those interfaces indirectly. Defences are straightforward in principle: canonicalise the URL to its effective origin before applying the allow or block decision, treat wrapper schemes as their inner document for permission purposes, and avoid exposing privileged objects to documents whose origin is ambiguous.
How to test for it
- Identify the domains the browser or extension platform treats as restricted, for example the vendor's own add-on store, and confirm the restriction works: attempt script injection into the plain URL and check that it is refused.
- Repeat the same injection against the same URL with each wrapper scheme prepended (
view-source:, and where applicableblob:anddata:variants), from the same extension context and with the same permissions. - If injection succeeds on a wrapper, inspect what the injected code can reach. Check whether the wrapper document can navigate to or reference the unwrapped page, and whether privileged objects (vendor-specific namespaces, management APIs, install prompts) are visible from there.
- Record the exact API call, the tab URL, and the object you obtained. A positive result is script execution in a context the platform intends to block, plus access to something the wrapper should not expose.
Common false positives: injection that succeeds only because the extension holds broad host permissions for all URLs, which is expected behaviour rather than a bypass; execution in an extension-owned page that merely looks like the restricted domain; and access to an object that is also available to ordinary web content, which removes the privilege boundary. Confirm the plain URL is genuinely blocked under identical conditions before claiming a bypass.
How it is fixed
- Normalise the target URL to its effective origin before the permission check, so wrapper schemes resolve to the inner document.
- Explicitly deny script injection into
view-source:and similar wrapper documents for restricted origins. - Prevent wrapper documents from retaining scripted access to the unwrapped page, or strip privileged interfaces from any document reached through a wrapper.
- Add regression tests that exercise each wrapper scheme against the restricted-origin list.
Hunting notes
This class tends to hide wherever a platform keeps a list of protected origins and applies it by string comparison: extension APIs, in-app browsers, embedded webviews, and any feature that grants elevated capability to a page. Recon signals include vendor documentation that names restricted domains, error messages that reveal a permission check, and any UI that renders one URL inside another (viewers, previews, source views).
To make a report land, show the blocked case and the bypass side by side, name the exact API and URL involved, and demonstrate the privileged object you reached rather than only the script execution. State the boundary you crossed in the platform's own terms, as this report does when it asks for the view-source URL to be treated like the plain one.
What happened, in plain words
This report is about a browser extension for Firefox and a gap in how the browser decides which web pages an extension is allowed to run code on. To follow it you only need to know a few everyday ideas.
A browser extension is a small add-on program you install into your browser to give it extra features. Extensions are written in JavaScript, the same language web pages use, and they can ask the browser to do things on their behalf.
A WebExtension is the standard format Firefox uses for extensions. One of its features is the browser action: the small icon that appears in the browser toolbar. When you click that icon, the extension can show a little panel, called a popup, with buttons or other content.
A popup here is just a small web page owned by the extension. Because it is a web page, it can run JavaScript.
browser.tabs.executeScript is an extension command that tells the browser: run this piece of JavaScript inside a particular tab, on the page that tab is showing. Think of it as the extension reaching into a page and moving its hands around. Browsers deliberately restrict this, because running code inside someone else's page is powerful. Some pages, such as the browser vendor's own add-on store, are treated as restricted: extensions are not allowed to inject code into them.
The site in question is AMO, https://addons.mozilla.org/, Mozilla's add-on store. The researcher found that the restriction works on the normal address but not on a variant of it.
That variant uses the view-source: scheme. A scheme is the first part of a web address, the bit before the :// (for example https). view-source: is a special scheme that tells the browser: show me the raw HTML source code of the page at the address that follows, rather than the rendered page. So view-source:https://addons.mozilla.org/ displays the source of the AMO page.
The researcher supplied a proof-of-concept extension as an attachment, AMO.zip, and gave three steps to reproduce the problem:
- Install the attached extension.
- Click on the green browser action.
- Click on the button that appears.
Each step matters. Step 1 puts the extension in place. Step 2 opens the popup, which is the extension's own page and therefore allowed to run the extension's code. Step 3 triggers the actual test: the popup asks the browser to run code in a tab showing the AMO page.
The key observation is that the popup can execute arbitrary code in the context of view-source:https://addons.mozilla.org/. In other words, the browser refuses to let the extension script the plain AMO page, but it happily lets it script the source-view version of the same page.
The researcher then noticed something further: the view-source'd AMO page can link to the non-view-source'd page and has access to it. So code running in the source view can reach the real page behind it.
Why does that matter? Because of a special object called navigator.mozAddonManager. This is a privileged interface that is not available in the view-source version but is available in the normal web page. It is not available in the view-source version, but it is available in the normal web page. By starting in the source view and reaching through to the real page, the extension's code ends up with access to that privileged object.
The reported outcome is exactly that: access to navigator.mozAddonManager.
The expected behaviour, in the researcher's words, is that view-source:https://addons.mozilla.org/ should be blocked from being accessed by browser.tabs.executeScript coming from a browserAction popup, in the same way it is blocked within https://addons.mozilla.org/ without the view-source prefix.
The report is filed against WebExtensions.
In general, how this kind of bug works
Browsers keep a list of pages an extension may script, and they check that list whenever the extension asks to inject code. The check has to answer one question: is this tab's page one the extension is allowed to touch?
Bugs appear when the answer is worked out from something that does not faithfully represent the page's real identity. Schemes such as view-source:, blob:, filesystem: and data: wrap or derive from another page. A naive comparison against the raw address string can miss the wrapped page underneath. If the guard blocks https://example.com/ but not view-source:https://example.com/, the wrapper becomes a way around the guard.
The second ingredient is inherited privilege. A page loaded through a wrapper may still be able to navigate to, or hold a reference to, the underlying page, and the underlying page may expose privileged interfaces that the wrapper does not. Any code that reaches the wrapper then reaches those interfaces indirectly.
Defences are straightforward in principle: work out the address's real origin before applying the allow or block decision, treat wrapper schemes as their inner page for permission purposes, and avoid exposing privileged objects to pages whose origin is ambiguous.
To test for this kind of bug:
- Identify the domains the platform treats as restricted, for example the vendor's own add-on store, and confirm the restriction works: attempt script injection into the plain address and check that it is refused.
- Repeat the same injection against the same address with each wrapper scheme prepended (
view-source:, and where applicableblob:anddata:variants), from the same extension context and with the same permissions. - If injection succeeds on a wrapper, inspect what the injected code can reach. Check whether the wrapper page can navigate to or reference the unwrapped page, and whether privileged objects (vendor-specific namespaces, management APIs, install prompts) are visible from there.
- Record the exact API call, the tab address, and the object you obtained. A positive result is script execution in a context the platform intends to block, plus access to something the wrapper should not expose.
Common false positives: injection that succeeds only because the extension holds broad host permissions for all addresses, which is expected behaviour rather than a bypass; execution in an extension-owned page that merely looks like the restricted domain; and access to an object that is also available to ordinary web content, which removes the privilege boundary. Confirm the plain address is genuinely blocked under identical conditions before claiming a bypass.
Fixes for this class of bug:
- Work out the target address's real origin before the permission check, so wrapper schemes resolve to the inner page.
- Explicitly deny script injection into
view-source:and similar wrapper pages for restricted origins. - Prevent wrapper pages from keeping scripted access to the unwrapped page, or strip privileged interfaces from any page reached through a wrapper.
- Add regression tests that exercise each wrapper scheme against the restricted-origin list.
This class tends to hide wherever a platform keeps a list of protected origins and applies it by string comparison: extension APIs, in-app browsers, embedded webviews, and any feature that grants elevated capability to a page. Signals worth watching include vendor documentation that names restricted domains, error messages that reveal a permission check, and any interface that renders one address inside another (viewers, previews, source views).
To make a report land, show the blocked case and the bypass side by side, name the exact API and address involved, and demonstrate the privileged object you reached rather than only the script execution. State the boundary you crossed in the platform's own terms, as this report does when it asks for the view-source address to be treated like the plain one.
Glossary
- Browser extension: a small add-on program installed into a browser to add features.
- WebExtension: the standard format Firefox uses for extensions.
- browser action: the extension's icon in the browser toolbar; clicking it can open a popup.
- Popup: a small web page owned by the extension, shown when the browser action is clicked.
- JavaScript: the programming language used by web pages and extensions.
browser.tabs.executeScript: an extension command that runs JavaScript inside a particular tab's page.- Restricted page: a page the browser forbids extensions from injecting code into, such as the vendor's add-on store.
- AMO:
https://addons.mozilla.org/, Mozilla's add-on store. - Scheme: the first part of a web address, before
://, such ashttpsorview-source. view-source:: a scheme that shows the raw HTML source of the page at the address that follows.- Origin: the identity of a page, made up of its scheme, host and port; browsers use it to decide what a page may access.
navigator.mozAddonManager: a privileged browser interface available in the normal AMO page but not in the view-source version.- Privilege escalation: gaining access to capabilities or data that should be out of reach.
- Wrapper scheme: a scheme such as
view-source:,blob:,filesystem:ordata:that wraps or derives from another page. - Injection: running code inside a page that the code did not originally belong to.
- False positive: a test result that looks like a bug but is actually expected behaviour.
- Regression test: an automated test that checks a fixed bug stays fixed.