Brave Browser Script Blocker Bypass Vulnerability
Brave browser's built-in JavaScript blocker failed to block inline scripts when JavaScript was disabled for a domain, allowing an attacker to execute arbitrary JavaScript. The bypass was demonstrated with a simple proof-of-concept that showed inline scripts running despite the blocker.
Published on medium.com
{{media:0}}
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Brave browser is an open-source browser that features ads blocking and tracking protection. Among its features is a built-in JavaScript blocker, which lets users optionally block JavaScript on user-specified domains. The write-up describes a way to bypass that blocker: external JavaScript files were correctly blocked, but inline JavaScript was mistakenly allowed, even when script was set to disabled.

The bug was inspired by the recently disclosed Tor Browser NoScript bypass vulnerability, CVE-2018-16983. In the NoScript issue, if you set the Content-Type of a webpage to text/html;/json, the page can execute JavaScript even if users set the security level to "Safest" in Tor. NoScript is a Firefox plugin, while Brave was based on muon, a framework modified from Electron, so it seemed unlikely that Brave's built-in script blocker suffered from the same vulnerability. The researcher decided to test it on Brave anyway.

Setup
The testing was done against Brave's built-in script blocker, with script set to disabled. The tool used to control the response was Fiddler, specifically its AutoResponder feature, which was used to hook a URL and set the Content-Type of the response. No accounts, roles or specific Brave version are described for the testing phase; the fixed version is given later.
Finding it
The starting point was the NoScript bypass: a page served with a malformed Content-Type of text/html;/json could still execute JavaScript under Tor's "Safest" security level. Because Brave's blocker was built on a different foundation (muon, modified from Electron), the researcher expected it not to share the flaw, but tested it regardless.
Exploitation
Step 1: Write a simple PoC page
The researcher wrote a very simple PoC containing both an inline script and an external script reference:
<script>alert(1);</script>
<script src="js.js"></script>
The inline script calls alert(1); the second tag loads an external file, js.js.
Step 2: Hook the URL and set the Content-Type
To set Content-Type, Fiddler AutoResponder was used to hook a URL, like http://example.com/index.html:

Step 3: Observe the result
It turned out <script>alert(1);</script> was executed, but <script src="js.js"></script> was blocked. The inline JavaScript ran even though script was set to disabled, while the external file was correctly blocked.
Step 4: Rule out Content-Type
The Content-Type was then changed to the normal text/html. The outcome was the same. So it was clear that Content-Type was irrelevant: external JavaScript was correctly blocked, but inline JavaScript was mistakenly allowed, even if script was set to disabled.
Demo:

Root cause
The report does not describe the code path behind the bypass. What it establishes from testing is that the blocker's decision depended on whether the script was inline or external: external script files were blocked, inline script was not, and the response Content-Type played no part. The exact mistake in the implementation is not stated, so any explanation of it would be speculation.
Impact
Under the tested condition, a user who had disabled JavaScript for a domain would still have inline JavaScript executed on pages from that domain. The report does not go further into what an attacker could achieve with that, beyond the demonstrated alert(1).
Fix
The vulnerability was reported to Brave Software on HackerOne on September 26, 2018. It was quickly triaged and fixed. The fixed version was released on October 8 in version 0.25.2. The vulnerability was also independently discovered by David Albert.
Variants to test
- Serve a page with a malformed
Content-Typesuch astext/html;/jsonand check whether inline script executes while the blocker is enabled. A positive result is an alert or other script effect appearing despite script being disabled. - Keep the blocker enabled and compare inline versus external script on the same page. A positive result is inline script running while the external file is blocked, which is the asymmetry seen here.
- Change the
Content-Typeback totext/htmland repeat. If the behaviour is unchanged, theContent-Typeis not the deciding factor, as in this case. - Test other browsers or extensions that implement per-domain script blocking, using the same inline versus external comparison. A positive result is inline script executing on a domain where the user disabled JavaScript.
What happened, in plain words
Brave is a web browser, a program you use to open websites. Like other browsers it is open source, meaning its code is public and anyone can read it. Brave advertises two privacy features: it blocks ads and it blocks tracking, which is the practice of websites and advertisers following you from page to page. On top of that, Brave includes a built-in JavaScript blocker.
JavaScript is the programming language that makes web pages interactive: it is what runs when a page shows a pop-up, updates a counter, or loads new content without a reload. It is also a common way for attackers to make a page do something you did not intend. A JavaScript blocker is a switch that lets you say "do not run JavaScript on this particular website". Brave's blocker lets you block JavaScript on domains you choose, one by one.

The researcher, Xiaoyin Liu, found a way around that switch. When JavaScript was set to disabled for a domain, Brave still ran JavaScript that was written directly inside the page, while it correctly blocked JavaScript loaded from a separate file. That difference is the whole bug: the blocker was checking one kind of script and letting the other kind through.
Where the idea came from
Before testing Brave, the researcher had read about a similar problem in another product. Tor Browser is a browser built for anonymity, and it ships with an extension called NoScript, which is a script blocker. NoScript is a Firefox plugin, meaning it is an add-on that plugs into the Firefox browser to add a feature. In the NoScript case, tracked as CVE-2018-16983, a page could still run JavaScript even when the user had set Tor's security level to its strictest setting, "Safest", if the page was served with an unusual Content-Type value of text/html;/json.
Content-Type is a label that a web server attaches to everything it sends back. It tells the browser what kind of content is coming: a web page, an image, a video, and so on. The browser uses that label to decide how to handle the content. In the NoScript case, a page served with that malformed label could still run JavaScript under the strictest setting.
Brave at the time was built on a framework called muon, which was itself a modified version of Electron. Electron is a toolkit for building desktop applications with web technology. Because Brave's blocker sat on a completely different foundation from NoScript, the researcher thought it was unlikely that Brave had the same flaw. Testing it anyway is the sensible habit in security work: a bug in one product is a hint to check the same idea elsewhere, not proof that the other product is affected.

Setting up the test
The test targeted Brave's built-in script blocker, with script set to disabled for the domain being tested. To control what the browser received, the researcher used a tool called Fiddler. Fiddler sits between your computer and the internet and lets you watch and change the traffic going back and forth. Its AutoResponder feature lets you intercept a request for a particular address and send back a response of your own instead of the real one.
That is how the Content-Type label was set: by hooking a URL, meaning telling Fiddler "when the browser asks for this address, answer it yourself". The address used as an example was http://example.com/index.html. No accounts, roles or specific Brave version are described for the testing phase; the fixed version is given later.
Finding it
Step 1: Write a simple proof of concept page
A proof of concept, usually shortened to PoC, is a small demonstration that a bug is real. It does not need to do damage; it only needs to show that something happens which should not. The researcher wrote a very simple one containing two script tags, one inline and one external:
<script>alert(1);</script>
<script src="js.js"></script>
Line by line:
<script>alert(1);</script>is an inline script. The JavaScript is written directly between the opening and closing tags, inside the page itself.alert(1)is the simplest possible JavaScript instruction: it asks the browser to show a small pop-up box containing the number 1. It is harmless, and it is used everywhere in security testing because if you see the box, you know the script ran.<script src="js.js"></script>is an external script. There is no code between the tags; instead, thesrcattribute points to a separate file calledjs.js, and the browser has to fetch that file and then run it. The two tags look similar to a person, but to the browser they are two different mechanisms: one is code already present in the page, the other is a request for another file.
Having both on the same page is the point of the test. It lets you compare how the blocker treats each kind side by side.
Step 2: Hook the URL and set the Content-Type
To set Content-Type, Fiddler AutoResponder was used to hook a URL, like http://example.com/index.html:

In plain terms: the browser was pointed at http://example.com/index.html, Fiddler caught that request, and Fiddler replied with the PoC page and a Content-Type label chosen by the researcher. This step exists because the NoScript bug was triggered by a strange Content-Type, so the first question was whether the same strange label would fool Brave's blocker too.
Step 3: Observe the result
It turned out <script>alert(1);</script> was executed, but <script src="js.js"></script> was blocked. In other words, the pop-up appeared, proving that inline JavaScript ran even though script was set to disabled, while the external file was correctly stopped.
That is the bypass. The switch the user had turned off was not being honoured for one of the two kinds of script.
Step 4: Rule out Content-Type
A good test does not stop at the first interesting result; it checks whether the thing you changed is actually the cause. So the Content-Type was then changed to the normal text/html. The outcome was the same. So it was clear that Content-Type was irrelevant: external JavaScript was correctly blocked, but inline JavaScript was mistakenly allowed, even if script was set to disabled.
This is an important conclusion. The NoScript bug depended on a malformed label; Brave's bug did not. The deciding factor was simply whether the script was inline or external. The test ruled out the borrowed idea and pointed at a different, simpler mistake.
Demo:

Why it happened
The report does not describe the code path behind the bypass. What it establishes from testing is that the blocker's decision depended on whether the script was inline or external: external script files were blocked, inline script was not, and the response Content-Type played no part. The exact mistake in the implementation is not stated, so any explanation of it would be speculation.
What it means for a user
Under the tested condition, a user who had disabled JavaScript for a domain would still have inline JavaScript executed on pages from that domain. The report does not go further into what an attacker could achieve with that, beyond the demonstrated alert(1).
The fix
The vulnerability was reported to Brave Software on HackerOne on September 26, 2018. HackerOne is a platform where security researchers report bugs to companies and the companies can respond, triage and reward them. It was quickly triaged, meaning the report was reviewed and confirmed as a genuine issue, and fixed. The fixed version was released on October 8 in version 0.25.2. The vulnerability was also independently discovered by David Albert.
Variants to test
If you want to try the same line of thinking yourself, these are the variations the technical account lists. Each one changes a single thing and asks whether the result changes with it.
- Serve a page with a malformed
Content-Typesuch astext/html;/jsonand check whether inline script executes while the blocker is enabled. A positive result is an alert or other script effect appearing despite script being disabled. - Keep the blocker enabled and compare inline versus external script on the same page. A positive result is inline script running while the external file is blocked, which is the asymmetry seen here.
- Change the
Content-Typeback totext/htmland repeat. If the behaviour is unchanged, theContent-Typeis not the deciding factor, as in this case. - Test other browsers or extensions that implement per-domain script blocking, using the same inline versus external comparison. A positive result is inline script executing on a domain where the user disabled JavaScript.
Glossary
- Browser: a program used to open and view websites, such as Brave, Firefox or Chrome.
- Open source: software whose code is published and can be read by anyone.
- JavaScript: the programming language that makes web pages interactive; it runs inside the browser.
- JavaScript blocker: a feature that stops JavaScript from running, either everywhere or on chosen websites.
- Domain: the part of a web address that identifies a site, such as
example.com. - Inline script: JavaScript written directly inside the page, between
<script>and</script>. - External script: JavaScript stored in a separate file and loaded by the page through the
srcattribute. - PoC (proof of concept): a small, harmless demonstration that a bug is real.
alert(1): a JavaScript instruction that shows a pop-up box containing 1; used to prove that script ran.Content-Type: a label a server attaches to a response saying what kind of content it is, such astext/htmlfor a web page.- CVE: a public identifier given to a known security vulnerability, here CVE-2018-16983.
- NoScript: a script-blocking extension for the Firefox browser.
- Tor Browser: a browser designed for anonymity, which ships with NoScript.
- Plugin / extension / add-on: software that plugs into a browser to add a feature.
- muon: the framework Brave was built on at the time, a modified version of Electron.
- Electron: a toolkit for building desktop applications using web technology.
- Fiddler: a tool that sits between your computer and the internet so you can watch and change traffic.
- AutoResponder: a Fiddler feature that answers a chosen URL with a response you supply instead of the real one.
- Hook a URL: configure a tool to intercept requests for a particular address and reply itself.
- Bypass: getting past a protection that is supposed to stop you.
- Triage: the step where a company reviews a bug report and confirms it is genuine.
- HackerOne: a platform for reporting security bugs to companies.
- Variant: a slightly changed version of a test, used to check whether a detail matters.