Universal XSS Vulnerability Found in uBlock Origin ~ Ibrahim Kaya
×
Cybersecurity

Universal XSS Vulnerability Found in uBlock Origin

İbrahim Kaya Published: Updated: 2 min read
Universal XSS Vulnerability Found in uBlock Origin
Contents

A Universal XSS (UXSS) vulnerability in uBlock Origin allowed websites to register trusted filters and run arbitrary JavaScript in the context of other domains, mainly affecting the Manifest V2 build on Firefox.

How the attack worked

uBlock Origin includes an element picker that lets users select and hide page elements from the context menu. The extension displays this interface inside an iframe that loads internal resources. To turn this into code execution, an attack required four steps:

  • Retrieve the browser's randomized extension UUID
  • Load the element picker interface inside an invisible (opacity: 0) iframe on the malicious site
  • Send crafted cross-origin messages to the picker dialog
  • Use clickjacking to make the user click the invisible Create button

Leaking the extension UUID

Firefox assigns each extension installation a randomized internal UUID to prevent fingerprinting. uBlock Origin's default rules, however, used a no-fetch-if scriptlet to replace ad scripts with local stubs. When triggered, this scriptlet sent an XMLHttpRequest to an internal extension file, exposing the random UUID to any page that hooked the open method:

JavaScript
const origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(m, url, ...a) {
    const e = /^moz-extension://[^/]+/.exec(url);
    if (e) {
        // e[0] reveals the internal extension UUID
    }
    return origOpen.call(this, m, url, ...a);
};

Injecting trusted filters through the picker

Once the page had the UUID, it loaded moz-extension://<UUID>/web_accessible_resources/epicker-ui.html inside an iframe and opened a communication line via a MessageChannel.

The picker normally limits users to cosmetic hiding rules and prevents scriptlet injection. However, the message parser accepted an opt parameter intended for network request options like $image. By inserting a newline character into this parameter, an attacker could break out of the intended rule syntax and append a trusted scriptlet:

text
image
google.com##+js(trusted-rpnt, script, ...)

Filters created through the picker are automatically marked as trusted. After tricking the user into clicking the invisible button, the rule was saved to the extension, letting the attacker run JavaScript on third-party sites like webmail or banking services whenever the user visited them.

Fix and mitigation

The developers resolved the issue by changing how the picker communicates with background scripts. The picker now verifies messages with an internal token generated by the content script, ignoring unauthorized messages from external web pages. The filter parameter parser was also updated to reject unexpected newline characters. Users should make sure they are running the latest version of the extension.