Universal XSS in uBlock Origin from website-driven element picker

Earlier this month I found a one-click universal XSS issue with uBlock Origin (the MV2 Firefox version, although a similar but less problematic issue also affected the MV3 version, uBO Lite), where a malicious website could trick the extension into adding arbitrary trusted filters. Trusted filters can inject JavaScript code into pages, and so the malicious website could create a trusted filter on another website and run arbitrary JS in the context of any site. This issue is fixed now; you can read the GitHub advisory for some more details.

本月初,我发现 uBlock Origin(MV2 Firefox 版本,尽管类似的较轻微问题也影响了 MV3 版本 uBO Lite)存在一个一键式通用 XSS 漏洞。恶意网站可以诱骗该扩展程序添加任意受信任的过滤器。受信任的过滤器可以将 JavaScript 代码注入页面,因此恶意网站可以在其他网站上创建受信任的过滤器,并在任何站点的上下文中运行任意 JS。此问题现已修复;您可以阅读 GitHub 公告以获取更多详细信息。

GPT-5.6 Sol did most of the hard work of finding the issue. I figured there might be some kind of UXSS from filter injection, so I asked it to take a look, and it found the issue. I then checked and verified the issue it proposed. I wrote all of the prose in this post myself; Claude wrote most of the code for the PoC.

GPT-5.6 Sol 完成了发现该问题的大部分艰苦工作。我推测过滤器注入可能存在某种 UXSS,于是让它进行检查,它确实发现了这个问题。随后我核实并验证了它提出的问题。本文的所有文字均由我本人撰写;Claude 编写了概念验证(PoC)的大部分代码。

uBlock Origin has an element picker that you can pull up by right-clicking on the page. You can use this to create a filter rule to block an element on the page without leaving the page.

uBlock Origin 有一个元素选择器,可以通过右键点击页面调出。您可以使用它创建过滤规则来屏蔽页面上的元素,而无需离开当前页面。

The element picker is implemented by injecting an iframe to a URL like moz-extension://76b2331a-894c-4d25-8b89-fcce37e79cc4/web_accessible_resources/epicker-ui.html. That page can talk to the extension background script and tell it to add filters.

元素选择器是通过向类似 moz-extension://76b2331a-894c-4d25-8b89-fcce37e79cc4/web_accessible_resources/epicker-ui.html 的 URL 注入 iframe 来实现的。该页面可以与扩展程序的后台脚本通信,并指示其添加过滤器。

Basically the attack here is:

On Firefox, the only information we needed to figure out was the extension internal UUID which is random per-installation.

基本上,此次攻击的原理如下:

在 Firefox 上,我们需要获取的唯一信息是扩展程序的内部 UUID,该 UUID 在每次安装时都是随机生成的。

On the default setup uBO has a lootdest.*##+js(no-fetch-if, adsbygoogle, war:googlesyndication_adsbygoogle.js) filter rule (from uAssets), which hooks fetch. From inside the fetch hook, it makes an XHR request to moz-extension:///web_accessible_resources/googlesyndication_adsbygoogle.js and returns the response from that as the fetch body, instead of actually making the request. The filter rule is intended to replace a network request for JS from an ad server with a dummy script that has the correct API but doesn’t do anything.

在默认设置下,uBO 包含一条(来自 uAssets 的)lootdest.*##+js(no-fetch-if, adsbygoogle, war:googlesyndication_adsbygoogle.js) 过滤规则,该规则会挂钩 fetch。在 fetch 钩子内部,它会向 moz-extension://<扩展 UUID>/web_accessible_resources/googlesyndication_adsbygoogle.js 发起 XHR 请求,并将该响应作为 fetch 的主体返回,而不是真正发起网络请求。该过滤规则旨在用一个具有正确 API 但不执行任何操作的虚拟脚本来替换来自广告服务器的 JS 网络请求。

But the attacker website can itself hook the XHR made from inside the no-fetch-if hook to extract the random extension UUID.

但攻击者网站可以自行挂钩在 no-fetch-if 钩子内部发起的 XHR,从而提取出随机的扩展 UUID。

Then the attacker website can run fetch(‘/adsbygoogle.js’).catch(() => {}); to trigger the filter, and make their hooked XHR run. Note that there are several ways that the extension internal UUID could be leaked; it’s not just this one filter rule.

随后,攻击者网站可以运行 fetch(‘/adsbygoogle.js’).catch(() => {}); 来触发该过滤器,并使其挂钩的 XHR 运行。请注意,扩展程序内部 UUID 的泄露方式有多种;不仅仅是通过这一条过滤规则。

Then you can use that to iframe the element picker. Given an iframe element in the page, you just set its src to moz-extension://${origin}/web_accessible_resources/epicker-ui.html.

然后,您可以使用该 UUID 将元素选择器嵌入到 iframe 中。给定页面上的一个 iframe 元素,只需将其 src 设置为 moz-extension://${origin}/web_accessible_resources/epicker-ui.html 即可。

Now we can drive the element picker. We can create a MessageChannel and do iframe.contentWindow.postMessage({ what: ‘epickerStart’ }, ’*’, [ch.port2]); to send it to the picker iframe. Then we talk to it: it sends us a start message, we send it a showDialog message with a filter and a resultsetDetails message1 to enable the create button and set opt.

现在我们可以操控元素选择器了。我们可以创建一个 MessageChannel 并执行 iframe.contentWindow.postMessage({ what: ‘epickerStart’ }, ’*’, [ch.port2]); 将其发送到选择器 iframe。然后我们与它通信:它向我们发送一条启动消息,我们向它发送一条包含过滤器的 showDialog 消息以及一条 resultsetDetails 消息1,以启用创建按钮并设置 opt。

Normally the picker restricts what filters you can enter, and doesn’t let you add scriptlet filters. But there’s a trick we can do to add arbitrary filters. There’s an opt field we set in the second message which is normally the type of network request to match (like image), and gets appended to the filter with a $ if set, like $image. But since we control it, we can put a newline in it and make it “image\ngoogle.com##+js(trusted-rpnt, script, …)” to inject an arbitrary trusted filter that injects a script.2

通常,选择器会限制您可以输入的过滤器类型,并且不允许添加 scriptlet 过滤器。但我们可以通过一个小技巧来添加任意过滤器。我们在第二条消息中设置了一个 opt 字段,它通常是匹配的网络请求类型(如 image),如果设置了该字段,它会以 $ 符号附加到过滤器中,例如 $image。但由于我们控制了这个字段,我们可以在其中加入换行符,将其变为 “image\ngoogle.com##+js(trusted-rpnt, script, …)”,从而注入一个可以执行脚本的任意受信任过滤器。2

This is where the main issue is - the element picker shouldn’t accept messages from the attacker. One of the fixes was having a secret password that the real element picker gets from the content script, that the element picker sends in the initial postMessage.

这就是主要问题所在——元素选择器不应接受来自攻击者的消息。其中一种修复方法是设置一个秘密密码,由真正的元素选择器从内容脚本中获取,并在初始 postMessage 中发送该密码。

I didn’t bother actually implementing this, but malicious websites could overlay stuff on top of the embedded element picker or make it invisible by setting the iframe opacity to 0. So as long as the website can get the user to click on the page, it can add arbitrary trusted filters for arbitrary domains.

我没有费心去实际实现这一点,但恶意网站可以在嵌入的元素选择器上方覆盖内容,或者通过将 iframe 的不透明度设置为 0 来使其不可见。因此,只要网站能诱导用户点击页面,它就可以为任意域名添加任意受信任的过滤器。

Filters added by the element picker are always treated as trusted (at least until a recompile), which is why it can add a trusted filter. If the user later changes their custom filters it would cause a recompile, clearing the filter trust. But in practice the attacker could just immediately open the victim webpage, so this doesn’t help much.

元素选择器添加的过滤器总是被视为受信任的(至少在重新编译之前),这就是它能够添加受信任过滤器的原因。如果用户稍后更改了自定义过滤器,则会导致重新编译,从而清除过滤器的信任状态。但在实践中,攻击者可以直接打开受害者的网页,所以这并没有太大帮助。

Originally I sent that message in reply to a dialogSetFilter message from the picker, but it turns out you can just send it right away instead of waiting to reply. ↩︎

最初我是在回复选择器的 dialogSetFilter 消息时发送该消息的,但事实证明,您可以直接发送,而无需等待回复。 ↩︎

Assuming the shown filter is a network filter. ↩︎

假设显示的过滤器是网络过滤器。 ↩︎