In August 2013 the FBI took over Freedom Hosting, a service hosting a large share of onion sites at the time, and served visitors a piece of JavaScript. It exploited a Firefox bug in the version Tor Browser was then based on, ran code on Windows machines, and sent the computer's real IP address and MAC address to a server outside Tor. Users who had JavaScript disabled were not affected.
That incident, covered in our history of Freedom Hosting and the 2013 Firefox exploit, is the clearest illustration of why JavaScript sits at the centre of browser anonymity debates.
Two separate risks
JavaScript causes two different problems, and they're worth keeping apart because the fixes overlap but aren't the same.
Exploitation
A browser's JavaScript engine is a large, complicated piece of software that compiles untrusted code from every website into machine instructions. Most serious browser vulnerabilities, the kind that let a page run code on your computer, live in the JavaScript engine or need JavaScript to trigger. A working exploit can bypass Tor entirely by making the machine connect directly to the attacker, as in 2013. Tails and Whonix are designed partly to limit the damage in that case, since even a compromised browser can't reach the internet except through Tor.
Information leakage
Even without bugs, JavaScript can measure things about your device and behaviour that plain HTML can't:
- Canvas, WebGL and audio fingerprints, screen details and hardware hints (see browser fingerprinting)
- Precise timing, which can reveal CPU characteristics and has been used in side-channel attacks
- Keystroke timing and mouse movement patterns, which differ between people
- What you type into a form before you press submit
- How long you spend on each part of a page
Tor Browser blunts a lot of this by standardising values and reducing timer precision. It can't make you type like everyone else.
What Tor Browser's security levels do
Tor Browser bundles NoScript and controls it through the shield icon's security levels. You don't need to configure NoScript directly, and changing its per-site settings makes your browser stand out.
| Level | JavaScript | Other changes |
|---|---|---|
| Standard | Enabled everywhere | All browser features on |
| Safer | Disabled on non-HTTPS sites; JIT compiler disabled everywhere | Audio and video click-to-play, some fonts and math symbols disabled |
| Safest | Disabled on all sites | Also restricts some images and fonts; many sites partly break |
One detail people miss: onion services count as secure for the Safer level, since the connection is end-to-end encrypted by Tor, so JavaScript runs on .onion sites at Safer. If you browse unfamiliar onion sites, for example ones found through our onion directory, Safest is the setting that actually stops scripts there.
Turning off the JIT compiler at Safer is quietly one of the most useful changes. A lot of engine exploits target the JIT. Scripts still run, just slower, and the exploitable surface shrinks.
The security levels article covers each level in more depth.
The anonymity-set argument
Why not ship with JavaScript off? The Tor Project's reasoning is that people who disable JavaScript become a distinguishable minority. A site can tell, from the absence of script-driven requests, that you've turned it off. If only a small fraction of Tor users browse at Safest, being one of them narrows your anonymity set a little.
That's a real cost, but small compared to the benefit for people at high risk. My view: if your threat model includes an adversary who might deploy exploits (a state agency, or anyone who could compromise the sites you visit), use Safest and live with the broken pages. For everyday privacy reading on the clearnet, Safer is a good compromise. Standard is fine for low-risk browsing where usability matters.
Practical habits
Change security level before you visit a site, not after. Switching reloads the page, but scripts that already ran have already run.
Don't whitelist sites in NoScript by hand. Use the per-level behaviour. If a site needs JavaScript and you trust it, temporarily drop the level for that task, then raise it again.
Keep Tor Browser updated. Many Firefox security fixes are in the JavaScript engine, and Tor Browser releases follow Firefox ESR security updates closely. An out-of-date Tor Browser with JavaScript on is the worst combination.
And watch what you type. A script can read form fields as you type them, so drafting a sensitive message in a web form you don't trust is a bad idea even if you never hit send. Write it in a local text editor first.