How I found a Tor vulnerability in Brave Browser, reported it, watched it get patched, got a CVE (CVE-2020-8276) and a small bounty, all in one working day
Brave browser sent a referral partner header even in Tor private windows, and stored Tor session timestamps in a local file that was not cleared after the session ended. An attacker with local disk access could use these timestamps to infer when a user had used Tor, potentially de-anonymising them.
Write-ups and Disclosures
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 is a Chromium-based browser created by Brendan Eich, the inventor of JavaScript and former CEO of Mozilla. The report notes that as of 2 November 2020 Brave had 20 million monthly active users and 7 million daily active users. Because Brave is open source, its core can be inspected at the brave/brave-core repository.
On 5 October 2020 Brave added the ability to route Incognito sessions through Tor: a Private Window with an added Tor circuit. The feature is enabled under brave://settings/?search=tor (or the settings menu) via the toggle:
Private Window with Tor Tor hides your IP address from the sites you visit.
Once enabled, Tor windows can be opened from the menu bar. The report also points to the open leakproofing issues tracked in the Brave Core issue tracker, and to an existing issue about Tor window size fingerprinting.
Separately, Brave monetises through its rewards programme, sponsored background images and referral links to crypto trading sites such as Binance, Gemini, Crypto.com and Coinbase. The browser injects a partner header when visiting those sites.
Setup
The researcher was running brave-bin 1:1.16.72-1 from the Arch User Repository (AUR), updated on 30 October 2020. The work was done against a local installation, and the only tooling shown is curl and a text editor for reading JSON.
The relevant configuration lives in the Brave configuration folder:
~/.config/BraveSoftware/Brave-Browser/Local\ State
The file is called Local State and contains a space, so it must be quoted or the space escaped. It is a JSON file storing core metrics, including the referral configuration that Brave uses to make money.
Finding it
Pretty-printing Local State shows the sites to which Brave will send a partner header:
"referral": {
"headers": [
{
"cookieNames": [],
"domains": [
"coinbase.com",
"api.coinbase.com"
],
"expiration": 31536000000.0,
"headers": {
"X-Brave-Partner": "coinbase"
}
},
{
"cookieNames": [],
"domains": [
"softonic.com",
"softonic.cn",
"softonic.jp",
"softonic.pl",
"softonic.com.br"
],
"expiration": 31536000000.0,
"headers": {
"X-Brave-Partner": "softonic"
}
},
{
"cookieNames": [],
"domains": [
"marketwatch.com",
"barrons.com"
],
"expiration": 31536000000.0,
"headers": {
"X-Brave-Partner": "dowjones"
}
},
{...
Visiting these sites in Brave makes the browser add the referral header automatically, comparable to clicking an affiliate link, except that the user cannot really turn it off without modifying the source. The researcher compared a normal request with a request to a partner site. A normal site:
curl 'https://disclose.io/' \
-H 'authority: disclose.io' \
-H 'pragma: no-cache' \
-H 'cache-control: no-cache' \
-H 'dnt: 1' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'sec-fetch-site: none' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-user: ?1' \
-H 'sec-fetch-dest: document' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'sec-gpc: 1' \
--compressed
A partner site:
curl 'https://www.coinbase.com/' \
-H 'authority: www.coinbase.com' \
-H 'pragma: no-cache' \
-H 'cache-control: no-cache' \
-H 'dnt: 1' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'x-brave-partner: coinbase' \
-H 'sec-fetch-site: none' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-user: ?1' \
-H 'sec-fetch-dest: document' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'sec-gpc: 1' \
--compressed
The difference is the injected header:
-H 'x-brave-partner: coinbase' \
The question the researcher then asked was whether that header also appears in Tor sessions. It does. The same Coinbase request, with Tor enabled, still carries the partner header:
curl 'https://www.coinbase.com/' \
-H 'authority: www.coinbase.com' \
-H 'pragma: no-cache' \
-H 'cache-control: no-cache' \
-H 'dnt: 1' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'x-brave-partner: coinbase' \
-H 'sec-fetch-site: none' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-user: ?1' \
-H 'sec-fetch-dest: document' \
-H 'accept-language: en-US,en;q=0.9' \
--compressed
While digging, the researcher also noticed a folder generated during Tor sessions:
~/.config/BraveSoftware/Brave-Browser/tor/data/keys
~/.config/BraveSoftware/Brave-Browser/tor/data/state
~/.config/BraveSoftware/Brave-Browser/tor/data/tor.log
~/.config/BraveSoftware/Brave-Browser/tor/data/cached-microdescs.new
~/.config/BraveSoftware/Brave-Browser/tor/data/cached-microdesc-consensus
~/.config/BraveSoftware/Brave-Browser/tor/data/cached-certs
~/.config/BraveSoftware/Brave-Browser/tor/data/lock
He suggested to the Brave security team that this folder should be cleared or shredded on exit. The report was sent by email rather than through HackerOne, and the full text of the original security report is reproduced here:
# Re: [Security]
### Vulnerability Details
A vulnerability in the Brave Web Browser allows remote websites to bypass an intended privacy feature of the Brave Web Browser. Even while using Tor, Brave sends a referral partner HTML header to specific partner websites, for example, "X-Brave-Partner": "coinbase", and "X-Brave-Partner": "softonic".
A targeted attack could trivially de-anonymize a user of the Brave browser. Since Oct 5, 2020 Brave offers a "private window" feature that supports The Onion Router (Tor) Network. The purpose of the Tor Browser from Tor project is to isolate each website you visit so that third-parties cannot follow you.
The Brave private window feature with Tor does not sufficiently anonymize users visiting Brave's partner websites.
While using Tor, Brave stores the count, attempt count, and absolute timestamp of the above HTML request:
"tor_used": true
"referral_attempt_count": 25,
"referral_attempt_timestamp": "13248492282530685",
"timestamp": "13244344644287168"
"incognito_used_timestamp": "13248493693576042",
"last_used": "Tor Profile",
"profile_counts_reported": "13248492279614953"
After the user ends the Tor session, the data is not cleared and users should be aware that the Tor feature of Brave browser is not secure as intended and the browser can leak, or send usage statistics, of critical information to their partner websites that could be used by an attacker to triangulate a user.
Exploitation
Step 1: Inspect the referral configuration
Read ~/.config/BraveSoftware/Brave-Browser/Local State and pretty-print it. The referral.headers array lists the partner domains and the header value injected for each. This establishes which sites receive the header and what the value looks like.
Step 2: Confirm the header on a normal request
Request a partner site with curl and observe x-brave-partner: coinbase in the outgoing request, absent from the request to a non-partner site. This confirms the injection is real and tied to the domain list.
Step 3: Enable Private Window with Tor and repeat
Enable the Tor feature in settings, open a Tor window, and repeat the Coinbase request. The x-brave-partner: coinbase header is still present, so the partner header is sent even while the session is routed through Tor.
Step 4: Inspect the Tor data folder
After a Tor session, the tor/data folder listed above still exists. The researcher treated the absence of deletion on exit as the starting point for a vulnerability.
Step 5: Inspect the metrics in Local State
Further inspection of .config shows Tor-related timestamps and counters stored in the JSON, including tor_used, referral_attempt_count, referral_attempt_timestamp, timestamp, incognito_used_timestamp, last_used and profile_counts_reported, as quoted in the report above. The data is not cleared when the Tor session ends.
Step 6: Report and iterate
After a few emails back and forth about the persistent Tor folder and the Tor metrics in Local State, Brave confirmed the issue. Yan Zhu at Brave replied on the morning of Monday 2 November 2020:
# Re: [Security]
...we found that indeed we were accidentally logging the when *any* incognito session was used, when we were supposed to only log the timestamp that a non-Tor incognito session was used: https://github.com/brave/brave-core/pull/7010.
We consider this a valid security issue and would be happy to issue a bounty via HackerOne if you resubmit it there: https://hackerone.com/brave. I think this is a sec-low issue given that someone who has access to the local disk cannot tell if the timestamp corresponds to a Tor session (rather than a regular incognito session). Also, the value that actually gets sent to the Brave metrics server is bucketed into the following values (so the timestamp isn't a fingerprinting vector):
Used in last 24h
Used in last week but not 24h
Used in last 28 days but not week
Ever used but not in last 28 days
Never used
By the time the report was submitted to HackerOne, the fix had already been written. The patch can be read by appending .diff to the pull request URL, https://github.com/brave/brave-core/pull/7010.diff:
From [redacted] Mon Sep 17 00:00:00 2001
From: Ivan Efremov <iefremovXbrave.com>
Date: Mon, 2 Nov 2020 15:43:05 +0700
Subject: [PATCH] 12452: Fix incognito used timestamp for P3A.
Fixes https://github.com/brave/brave-browser/issues/12452
---
browser/p3a/p3a_core_metrics.cc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/browser/p3a/p3a_core_metrics.cc b/browser/p3a/p3a_core_metrics.cc
index 9befca08bf6..4a0c2d691d9 100644
--- a/browser/p3a/p3a_core_metrics.cc
+++ b/browser/p3a/p3a_core_metrics.cc
@@ -43,7 +43,8 @@ enum class WindowUsageStats {
};
const char* GetPrefNameForProfile(Profile* profile) {
- if (profile->IsIncognitoProfile()) {
+ if (profile->IsIncognitoProfile() &&
+ !brave::IsTorProfile(profile)) {
return kLastTimeIncognitoUsed;
}
return nullptr;
Root cause
The bug was narrowed down, through discussion with Brave, to the core_p3a_metrics timestamping in the JSON file. The function GetPrefNameForProfile returned kLastTimeIncognitoUsed for any incognito profile, including Tor profiles, so the timestamp of a Tor session was written where only a non-Tor incognito timestamp was intended. The fix adds a check that the profile is not a Tor profile before returning that preference name.
The partner header is separate from the timestamp bug: the referral header is still sent when the session is routed through Tor, so partner sites see it in a Tor window.
Impact
The report frames the impact around de-anonymisation. The report frames the impact around de-anonymisation: the partner header is sent to partner sites even under Tor, and Tor usage timestamps and counters persist in Local State after the session ends. The researcher's scenario: a human rights activist has their disk seized by local authorities, the Local State file is read and shows the last time Tor was used with nanosecond accuracy, and the ISP holds a corresponding timestamp for that person's Tor usage.
Brave's assessment was that this is a sec-low issue: someone with access to the local disk cannot tell whether the timestamp corresponds to a Tor session or a regular incognito session, and the value actually sent to the Brave metrics server is bucketed into the five ranges quoted above, so the timestamp is not a fingerprinting vector there. The researcher describes it as a physical access vulnerability with quite low exploitability, and entered it as low severity, receiving a bounty of $100. He considered it a medium loss of software integrity on the CVSS calculator but did not want to hype it.
Fix
The fix is the change to browser/p3a/p3a_core_metrics.cc shown above: GetPrefNameForProfile now requires profile->IsIncognitoProfile() && !brave::IsTorProfile(profile) before returning kLastTimeIncognitoUsed. It had already been patched when Brave confirmed the issue, and the researcher notes that had the report not landed over a weekend, Brave would likely have patched and pushed the fix the same day. The report does not say whether the Tor data folder was changed to be cleared or shredded on exit.
Variants to test
- Partner header injection under privacy modes. Visit each domain in a browser's referral or affiliate list while in private, incognito or proxy-routed modes, and capture the outgoing request. A positive result is the partner header still present in the privacy mode.
- Persistent session artefacts. After closing a private or proxy session, list the application's configuration and data directories for files created during the session. A positive result is a folder or log file that survives exit.
- Privacy-mode timestamps in local state. Search the configuration JSON for keys recording last-used times or counters for private modes. A positive result is a timestamp that distinguishes the privacy mode from ordinary private browsing.
- Metrics bucketing. Compare the raw local value with what the telemetry endpoint receives. A positive result is an unbucketed value leaving the machine.
- Information exposure classes. When reviewing a client application, walk the CWE-200 family listed in the report (CWE-200, 201, 202, 203, 209, 211, 212, 213, 214, 215, 226, 497, 524, 526, 532, 538, 598, 612) against local files, logs, error messages and query strings. A positive result is sensitive data readable by someone who should not have it, or left behind after the feature that created it has ended.
What happened, in plain words
A security researcher noticed that Brave, a web browser, was quietly adding a small piece of identifying information to requests sent to certain partner websites. That alone was a business decision, not a bug. The problem was that the same identifying information was still being added when the user had switched on Brave's privacy feature that routes traffic through Tor, a network designed to hide who you are. On top of that, Brave was writing timestamps about Tor usage into a file on the user's own computer and not deleting them when the private session ended.
The researcher emailed the Brave security team, explained what he had seen, and suggested fixes. Brave confirmed the timestamp part was a genuine mistake, had already patched it, and paid a small bounty. The whole thing happened in about one working day, and the issue was tracked as CVE-2020-8276.
This article walks through the same steps the researcher took, but explains every term from scratch. You only need to know how to use a computer and a browser.
Background: what Brave is and why it matters
Brave is a web browser. A browser is the program you use to visit websites: it asks a web server for a page, receives it, and draws it on your screen. Brave is built on Chromium, which is the open source foundation also used by Google Chrome. "Open source" means the underlying instructions (the source code) are published, so anyone can read them. The report points to the code at the brave/brave-core repository on GitHub, a website where source code is stored and shared.
The report notes that Brave was created by Brendan Eich, the inventor of the JavaScript programming language and former CEO of Mozilla, the organisation behind Firefox. As of 2 November 2020, the report says Brave had 20 million monthly active users and 7 million daily active users.
Brave makes money in a few ways: a rewards programme involving cryptocurrency, sponsored background images, and referral links to large cryptocurrency trading sites such as Binance, Gemini, Crypto.com and Coinbase. A referral link is the same idea as an affiliate link: if you arrive at a shop through a special link, the shop knows who sent you and may pay that person or company a commission. Brave does this automatically by adding a small label to the requests it sends to those partner sites.
On 5 October 2020, Brave added a feature that lets its private browsing mode send traffic through Tor. Tor (The Onion Router) is a network that bounces your connection through several volunteer computers so that the website you visit cannot easily tell who you are or where you are. Brave's version is called a Private Window with Tor. You switch it on in the settings, at brave://settings/?search=tor or through the normal settings menu, using this toggle:
Private Window with Tor Tor hides your IP address from the sites you visit.
An IP address is the number that identifies your computer on a network, a bit like a postal address for data. Once the toggle is on, you can open Tor windows from the menu bar.
The report also mentions that Brave tracks known weaknesses in its Tor feature in its public issue tracker, including one about window size fingerprinting. Fingerprinting is when a website recognises you from small characteristics of your setup, such as the exact size of your browser window, even without cookies.
Setting up
The researcher was using brave-bin 1:1.16.72-1, a packaged version of Brave from the Arch User Repository (AUR), a community collection of software packages for the Arch Linux operating system. He updated it on 30 October 2020. No special account or permission was needed: everything was done on his own computer, and the only tools shown are curl and a text editor for reading a file.
curl is a command line tool that sends a request to a web address and prints the response. Think of it as a browser without a window: useful for seeing exactly what is being sent and received.
Brave keeps its settings and internal data in a folder in your home directory. The file of interest is here:
~/.config/BraveSoftware/Brave-Browser/Local\ State
Line by line:
~means your home folder, the place where your personal files live./.config/is a hidden folder where Linux programs store their settings.BraveSoftware/Brave-Browser/is Brave's own folder inside it.Local\ Stateis the file name. The backslash is there because the real name contains a space ("Local State"), and a space would otherwise split the name into two words on the command line. You can also wrap the name in quotes instead.
This file is written in JSON, a simple text format for storing data as labelled values, a bit like a very structured shopping list. It holds core metrics, meaning measurements the browser records about itself, including the referral configuration that Brave uses to make money.
Finding it
When the file is "pretty printed", meaning reformatted with indentation so a human can read it, the referral settings become visible. They list the sites to which Brave will send a partner header:
"referral": {
"headers": [
{
"cookieNames": [],
"domains": [
"coinbase.com",
"api.coinbase.com"
],
"expiration": 31536000000.0,
"headers": {
"X-Brave-Partner": "coinbase"
}
},
{
"cookieNames": [],
"domains": [
"softonic.com",
"softonic.cn",
"softonic.jp",
"softonic.pl",
"softonic.com.br"
],
"expiration": 31536000000.0,
"headers": {
"X-Brave-Partner": "softonic"
}
},
{
"cookieNames": [],
"domains": [
"marketwatch.com",
"barrons.com"
],
"expiration": 31536000000.0,
"headers": {
"X-Brave-Partner": "dowjones"
}
},
{...
What this means, piece by piece:
"referral"is the name of this section of settings."headers"is a list. Each entry in the list describes one partner."cookieNames": []is an empty list, meaning no cookies are involved here. A cookie is a small piece of data a website asks your browser to store and send back on later visits, often used to remember that you are logged in."domains"lists the website addresses the rule applies to. A domain is the main part of a web address, such ascoinbase.com."expiration": 31536000000.0is a duration in milliseconds, roughly one year, after which the rule expires."headers": { "X-Brave-Partner": "coinbase" }is the actual label added to requests. A header is a line of extra information attached to a web request or response, like the label on a parcel that says what is inside or who sent it. Here the header is namedX-Brave-Partnerand its value iscoinbase.
So visiting these sites in Brave makes the browser add the referral header automatically. It is comparable to clicking an affiliate link, except the user cannot really turn it off without modifying the source code.
To prove the header really goes out, the researcher compared two requests. First, a request to a normal site that is not a partner:
curl 'https://disclose.io/' \
-H 'authority: disclose.io' \
-H 'pragma: no-cache' \
-H 'cache-control: no-cache' \
-H 'dnt: 1' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'sec-fetch-site: none' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-user: ?1' \
-H 'sec-fetch-dest: document' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'sec-gpc: 1' \
--compressed
Line by line:
curl 'https://disclose.io/'asks curl to fetch the page at that address. The quotes protect the address from being altered by the command line.- Each
-H '...'adds one header to the request. The backslash at the end of a line means "this command continues on the next line". authority: disclose.ionames the site being contacted.pragma: no-cacheandcache-control: no-cacheask that no stored copy be used; a cache is a saved copy kept to speed things up.dnt: 1means "do not track", a request that the site not track you.upgrade-insecure-requests: 1asks the site to use the secure, encrypted version of the connection.user-agent: ...tells the site which browser and operating system you are using. Here it identifies a Chrome 86 style browser on 64-bit Linux.accept: ...lists the kinds of content the browser can handle, with quality scores afterq=.sec-fetch-site,sec-fetch-mode,sec-fetch-userandsec-fetch-destare hints about where the request came from and what it is for.navigatemeans the user is opening a page, anddocumentmeans the result is a page to display.accept-language: en-US,en;q=0.9says the user prefers US English, then English generally.sec-gpc: 1is the Global Privacy Control signal, a way of saying "do not sell or share my data".--compressedtells curl it is willing to receive a compressed response, which saves bandwidth.
Now the same kind of request to a partner site, Coinbase:
curl 'https://www.coinbase.com/' \
-H 'authority: www.coinbase.com' \
-H 'pragma: no-cache' \
-H 'cache-control: no-cache' \
-H 'dnt: 1' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'x-brave-partner: coinbase' \
-H 'sec-fetch-site: none' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-user: ?1' \
-H 'sec-fetch-dest: document' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'sec-gpc: 1' \
--compressed
Most lines are identical to the first request. The difference is the extra header:
-H 'x-brave-partner: coinbase' \
That single line is the whole finding at this stage: Brave is adding a label saying "this visitor came via Brave's Coinbase partnership". Header names are not case sensitive, so X-Brave-Partner and x-brave-partner are the same header.
The next question was the important one: does that label also appear when the user has switched on Tor? If it does, a partner site that is supposed to see an anonymous visitor instead learns that the visitor is using Brave and arrived through a particular partnership. The researcher repeated the Coinbase request with Tor enabled, and the header was still there:
curl 'https://www.coinbase.com/' \
-H 'authority: www.coinbase.com' \
-H 'pragma: no-cache' \
-H 'cache-control: no-cache' \
-H 'dnt: 1' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'x-brave-partner: coinbase' \
-H 'sec-fetch-site: none' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-user: ?1' \
-H 'sec-fetch-dest: document' \
-H 'accept-language: en-US,en;q=0.9' \
--compressed
This is the same request as before, with the same partner header. The only difference from the non-Tor case is that the traffic is routed through Tor, and the header survives that routing.
While digging around, the researcher also noticed a folder that Brave creates during Tor sessions:
~/.config/BraveSoftware/Brave-Browser/tor/data/keys
~/.config/BraveSoftware/Brave-Browser/tor/data/state
~/.config/BraveSoftware/Brave-Browser/tor/data/tor.log
~/.config/BraveSoftware/Brave-Browser/tor/data/cached-microdescs.new
~/.config/BraveSoftware/Brave-Browser/tor/data/cached-microdesc-consensus
~/.config/BraveSoftware/Brave-Browser/tor/data/cached-certs
~/.config/BraveSoftware/Brave-Browser/tor/data/lock
These are files inside Brave's Tor data folder. keys and state are files Tor uses to keep its identity and progress; tor.log is a log, a running record of what happened; the cached- files are saved copies of information Tor downloaded about the network so it does not have to fetch it again; lock is a marker file that stops two copies of Tor from using the same folder at once. The researcher suggested to the Brave security team that this folder should be cleared or shredded when the Tor session ends. "Shredded" means overwritten so the contents cannot be recovered.
The report was sent by email rather than through HackerOne, a website where companies run bug bounty programmes. A bug bounty is a reward, usually money, paid to someone who reports a security problem responsibly. Here is the full text of the original security report:
# Re: [Security]
### Vulnerability Details
A vulnerability in the Brave Web Browser allows remote websites to bypass an intended privacy feature of the Brave Web Browser. Even while using Tor, Brave sends a referral partner HTML header to specific partner websites, for example, "X-Brave-Partner": "coinbase", and "X-Brave-Partner": "softonic".
A targeted attack could trivially de-anonymize a user of the Brave browser. Since Oct 5, 2020 Brave offers a "private window" feature that supports The Onion Router (Tor) Network. The purpose of the Tor Browser from Tor project is to isolate each website you visit so that third-parties cannot follow you.
The Brave private window feature with Tor does not sufficiently anonymize users visiting Brave's partner websites.
While using Tor, Brave stores the count, attempt count, and absolute timestamp of the above HTML request:
"tor_used": true
"referral_attempt_count": 25,
"referral_attempt_timestamp": "13248492282530685",
"timestamp": "13244344644287168"
"incognito_used_timestamp": "13248493693576042",
"last_used": "Tor Profile",
"profile_counts_reported": "13248492279614953"
After the user ends the Tor session, the data is not cleared and users should be aware that the Tor feature of Brave browser is not secure as intended and the browser can leak, or send usage statistics, of critical information to their partner websites that could be used by an attacker to triangulate a user.
In plain words, this report says three things. First, a website can bypass a privacy feature, because the partner header is sent even under Tor. Second, a targeted attack could de-anonymise a user, meaning work out who they are. Third, Brave stores counters and timestamps about Tor use in a file and does not clear them afterwards. A timestamp is a record of when something happened. "Triangulate" here means combining separate pieces of information, from the browser file and from an internet provider, to pin down a person.
Exploitation, step by step
The researcher's own summary of the path is worth keeping in mind: thinking about Brave's partners led him to the partner headers; looking at partner headers under Tor led him into the Tor folder; seeing that the folder was not deleted on exit gave him a starting point; looking further inside .config led him to Tor timestamps; and because Tor is a security feature, any bug in a security feature is bigger than it first appears.
Step 1: Inspect the referral configuration
He read ~/.config/BraveSoftware/Brave-Browser/Local State and pretty printed it. The referral.headers list shows which partner domains get which header value. This step answers two questions before any testing: which sites receive the label, and what the label looks like. Without this, you would not know what to look for in a request.
Step 2: Confirm the header on a normal request
He sent a request to a partner site with curl and saw x-brave-partner: coinbase in the outgoing request. The same header was absent from the request to a non-partner site. This confirms the injection is real and tied to the domain list, rather than something imagined from reading the file.
Step 3: Enable Private Window with Tor and repeat
He switched on the Tor feature in settings, opened a Tor window, and repeated the Coinbase request. The x-brave-partner: coinbase header was still present. That is the privacy problem: the session is routed through Tor, but the partner label still travels with it.
Step 4: Inspect the Tor data folder
After a Tor session, the tor/data folder listed above still existed. The absence of deletion on exit was the starting point for treating this as a vulnerability. The reasoning is simple: a privacy feature should not leave traces of its use lying around afterwards.
Step 5: Inspect the metrics in Local State
Looking further inside .config showed Tor related timestamps and counters stored in the JSON: tor_used, referral_attempt_count, referral_attempt_timestamp, timestamp, incognito_used_timestamp, last_used and profile_counts_reported, as quoted in the report above. These values were not cleared when the Tor session ended. A counter is just a number that goes up each time something happens; a timestamp records when it happened.
Step 6: Report and iterate
After a few emails back and forth about the persistent Tor folder and the Tor metrics in Local State, Brave confirmed the issue. Yan Zhu at Brave replied on the morning of Monday 2 November 2020:
# Re: [Security]
...we found that indeed we were accidentally logging the when *any* incognito session was used, when we were supposed to only log the timestamp that a non-Tor incognito session was used: https://github.com/brave/brave-core/pull/7010.
We consider this a valid security issue and would be happy to issue a bounty via HackerOne if you resubmit it there: https://hackerone.com/brave. I think this is a sec-low issue given that someone who has access to the local disk cannot tell if the timestamp corresponds to a Tor session (rather than a regular incognito session). Also, the value that actually gets sent to the Brave metrics server is bucketed into the following values (so the timestamp isn't a fingerprinting vector):
Used in last 24h
Used in last week but not 24h
Used in last 28 days but not week
Ever used but not in last 28 days
Never used
What Brave is saying here, in plain terms: the browser was recording the time of any private session, when it should only have recorded the time of a private session that was not using Tor. Brave agrees it is a real security issue and offers a bounty through HackerOne if the researcher resubmits there. Brave rates it "sec-low", a low severity rating, because someone who can read the file on the disk cannot tell whether the timestamp came from a Tor session or an ordinary private session. Brave also says the value actually sent to its metrics server is "bucketed", meaning rounded into one of five broad ranges rather than sent as an exact time, so the exact timestamp is not a way to fingerprint users on the server side. A metrics server is a computer that collects these usage statistics.
By the time the report was submitted to HackerOne, the fix had already been patched. GitHub lets you read the changes in a pull request, a proposed set of code changes, by adding .diff to its address. The patch is at https://github.com/brave/brave-core/pull/7010.diff:
From [redacted] Mon Sep 17 00:00:00 2001
From: Ivan Efremov <iefremovXbrave.com>
Date: Mon, 2 Nov 2020 15:43:05 +0700
Subject: [PATCH] 12452: Fix incognito used timestamp for P3A.
Fixes https://github.com/brave/brave-browser/issues/12452
---
browser/p3a/p3a_core_metrics.cc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/browser/p3a/p3a_core_metrics.cc b/browser/p3a/p3a_core_metrics.cc
index 9befca08bf6..4a0c2d691d9 100644
--- a/browser/p3a/p3a_core_metrics.cc
+++ b/browser/p3a/p3a_core_metrics.cc
@@ -43,7 +43,8 @@ enum class WindowUsageStats {
};
const char* GetPrefNameForProfile(Profile* profile) {
- if (profile->IsIncognitoProfile()) {
+ if (profile->IsIncognitoProfile() &&
+ !brave::IsTorProfile(profile)) {
return kLastTimeIncognitoUsed;
}
return nullptr;
Line by line:
- The first lines are the header of a patch file: who wrote it, when, and a one line description. The subject says it fixes the incognito used timestamp for P3A. P3A is Brave's privacy respecting analytics system, the part that records usage statistics.
Fixes https://...links the change to the issue it closes.browser/p3a/p3a_core_metrics.cc | 3 ++-and1 file changed, 2 insertions(+), 1 deletion(-)summarise the change: one file, two lines added, one removed.- The
diff --gitline names the file being changed. Theindexline is an internal identifier for the old and new versions. @@ -43,7 +43,8 @@says where in the file the change sits and how many lines are shown around it.- Lines starting with
-are removed and lines starting with+are added. Lines with no sign are context, shown so you can see where you are. - The old code was
if (profile->IsIncognitoProfile()) {, meaning "if this is a private profile, do the following". - The new code is
if (profile->IsIncognitoProfile() && !brave::IsTorProfile(profile)) {, meaning "if this is a private profile and it is not a Tor profile".&&means "and", and!means "not". return kLastTimeIncognitoUsed;is the action that was being taken: return the name of the setting that stores the last time private browsing was used. With the new condition, that only happens for private sessions that are not Tor sessions.return nullptr;means "return nothing" when the condition is not met.
Root cause
Through discussion with Brave, the bug was narrowed down to the core_p3a_metrics timestamping in the JSON file. The function GetPrefNameForProfile returned kLastTimeIncognitoUsed for any private profile, including Tor profiles, so the time of a Tor session was written where only a non-Tor private timestamp was intended. The fix adds a check that the profile is not a Tor profile before returning that setting name.
The partner header is a separate design decision. The referral header is added by domain regardless of whether the session is routed through Tor, so partner sites still see it in a Tor window.
Impact
The report frames the impact around de-anonymisation. The report frames the impact around de-anonymisation: the partner header is sent to partner sites even under Tor, and Tor usage timestamps and counters persist in Local State after the session ends. The researcher's scenario: a human rights activist has their disk seized by local authorities, the Local State file is read and shows the last time Tor was used with nanosecond accuracy, and the internet service provider holds a corresponding timestamp for that person's Tor usage. A nanosecond is one billionth of a second, so the record is extremely precise.
Brave's assessment was that this is a sec-low issue: someone with access to the local disk cannot tell whether the timestamp corresponds to a Tor session or a regular private session, and the value actually sent to the Brave metrics server is bucketed into the five ranges quoted above, so the timestamp is not a fingerprinting vector there. The researcher describes it as a physical access vulnerability, meaning an attacker needs to get at the actual computer, with quite low exploitability, and entered it as low severity, receiving a bounty of $100. He considered it a medium loss of software integrity on the CVSS calculator, a standard scoring system for vulnerabilities, but did not want to hype it.
Fix
The fix is the change to browser/p3a/p3a_core_metrics.cc shown above: GetPrefNameForProfile now requires profile->IsIncognitoProfile() && !brave::IsTorProfile(profile) before returning kLastTimeIncognitoUsed. It had already been patched when Brave confirmed the issue, and the researcher notes that had the report not landed over a weekend, Brave would likely have patched and pushed the fix the same day. The report does not say whether the Tor data folder was changed to be cleared or shredded on exit.
Variants to test
These are the kinds of checks the researcher suggests other people can try on software they use. Each one is a small experiment with a clear pass or fail.
- Partner header injection under privacy modes. Visit each domain in a browser's referral or affiliate list while in private, incognito or proxy-routed modes, and capture the outgoing request. A positive result is the partner header still present in the privacy mode. A proxy is a computer that passes your traffic along on your behalf.
- Persistent session artefacts. After closing a private or proxy session, list the application's configuration and data folders for files created during the session. A positive result is a folder or log file that survives exit. An artefact here means a leftover trace.
- Privacy-mode timestamps in local state. Search the configuration JSON for keys recording last-used times or counters for private modes. A positive result is a timestamp that distinguishes the privacy mode from ordinary private browsing.
- Metrics bucketing. Compare the raw local value with what the telemetry endpoint receives. A positive result is an unbucketed value leaving the machine. Telemetry is the automatic sending of usage data back to the maker.
- Information exposure classes. When reviewing a client application, walk the CWE-200 family listed in the report against local files, logs, error messages and query strings. A positive result is sensitive data readable by someone who should not have it, or left behind after the feature that created it has ended. CWE is a public catalogue of weakness types, and the 200 family is the group about information being exposed.
The CWE list from the report, for reference:
- CWE-200: Information Exposure
- CWE-201: Information Exposure Through Sent Data
- CWE-202: Exposure of Sensitive Data Through Data Queries
- CWE-203: Information Exposure Through Discrepancy
- CWE-209: Information Exposure Through an Error Message
- CWE-211: Information Exposure Through Externally-Generated Error Message
- CWE-212: Improper Cross-boundary Removal of Sensitive Data
- CWE-213: Intentional Information Exposure
- CWE-214: Information Exposure Through Process Environment
- CWE-215: Information Exposure Through Debug Information
- CWE-226: Sensitive Information Uncleared Before Release
- CWE-497: Exposure of System Data to an Unauthorized Control Sphere
- CWE-524: Information Exposure Through Caching
- CWE-526: Information Exposure Through Environmental Variables
- CWE-532: Information Exposure Through Log Files
- CWE-538: File and Directory Information Exposure
- CWE-598: Information Exposure Through Query Strings in GET Request
- CWE-612: Information Exposure Through Indexing of Private Data
Glossary
- AUR (Arch User Repository): a community collection of software packages for Arch Linux.
- Browser: the program you use to visit websites.
- Bucketing: rounding a precise value into one of a few broad ranges before sending it.
- Bug bounty: a reward paid for responsibly reporting a security problem.
- Cache: a saved copy kept so something does not have to be fetched again.
- Chromium: the open source browser foundation that Brave and Chrome are built on.
- Cookie: a small piece of data a website asks your browser to store and send back later, often to keep you logged in.
- Counter: a number that goes up each time something happens.
- CVE: a public identifier given to a known security vulnerability.
- CVSS: a standard scoring system for the severity of vulnerabilities.
- CWE: a public catalogue of weakness types.
- curl: a command line tool that sends web requests and prints the responses.
- De-anonymise: work out who an anonymous person is.
- Domain: the main part of a web address, such as
coinbase.com. - Fingerprinting: recognising a user from small characteristics of their setup, even without cookies.
- Header: a line of extra information attached to a web request or response.
- HackerOne: a website where companies run bug bounty programmes.
- IP address: the number identifying a computer on a network.
- JSON: a simple text format for storing data as labelled values.
- Log: a running record of what a program did.
- Metrics: measurements a program records about itself.
- Nanosecond: one billionth of a second.
- Open source: software whose source code is published for anyone to read.
- P3A: Brave's privacy respecting analytics system.
- Patch: a set of code changes that fixes something.
- Pretty print: reformat text with indentation so a human can read it.
- Proxy: a computer that passes your traffic along on your behalf.
- Pull request: a proposed set of code changes submitted for review.
- Referral link: a special link that tells a site who sent you, often for a commission.
- Shred: overwrite a file so its contents cannot be recovered.
- Source code: the instructions that make up a program.
- Telemetry: automatic sending of usage data back to the maker.
- Timestamp: a record of when something happened.
- Tor (The Onion Router): a network that bounces your connection through several computers so a site cannot easily tell who you are.
- Triangulate: combine separate pieces of information to pin down a person.
- User agent: the header that tells a site which browser and operating system you use.
- Vulnerability: a weakness in software that can be used to break its intended behaviour or security.