Canvas composite operations and CSS blend modes leak cross-origin data via timing attacks
Canvas globalCompositeOperation and CSS mix-blend-mode operations take different amounts of time depending on pixel values, letting a page infer cross-origin image or iframe contents. An attacker can read pixels one at a time by timing these rendering operations.
- Fixed in 18 months
- Paid in 18 months
- Disclosed after 18 months
Created attachment 8844362
globalCompositeOperation.html
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0
Build ID: 20170125183131
Steps to reproduce:
"Minimized" reproduction cases for the globalCompositeOperation attack and the mix-blend-mode attack are in the first and second attachments, respectively. Just open them up and check the console output (after waiting a while, that is, potentially a long while in the case of the second one). You can have the devtools open, but don't open or close them while the exploits are running. You may have to serve them from a local Web server to get them to work.
While developing the exploit, I used an interface I'd built to make it easier to see how well it was working. A cleaned-up version of this interface is in the third attachment. If the first two don't seem to work for you, I recommend trying the third. Have fun with it. I actually wrote the JavaScript for it in ES6 module format and bundled it using a tool called Rollup, so look in the fourth attachment for the individual source files, which should be easier to navigate.
I tried to minimize the reproduction cases as much as possible without sacrificing the code's clarity, but it's a timing attack, which makes it a rather high-level bug, so I figured you're probably not going to be running it under gdb or anything. I hope it's in a good state to analyze.
Timing is fickle, so the exploit may or may not work on your system. In particular, neither of my current implementations of the exploits work on my Windows machine. I doubt there are any platforms that can't be targeted by both exploits with the proper tuning, however.
Actual results:
Many of the operations supported by CanvasRenderingContext2D.globalCompositeOperation and the CSS mix-blend-mode property take varying lengths of time to complete depending on the contents of the source and destination images. This allows an attacker to infer the contents of a cross-origin image or even an arbitrary HTML element, such as an iframe.
An attacker may read the pixels of a cross-origin image by following these steps:
1. Render a single pixel from the image onto a canvas.
2. Manipulate the canvas so that it may be in one of two states depending on whether that pixel's color has certain properties.
3. Time how long it takes to render the contents of the canvas, scaled up, onto another canvas with a globalCompositeOperation chosen to maximize the difference in timing between those two states.
4. Based on whether the operation from step 3 completed quickly or slowly, it can be determined whether the pixel's color has the properties selected for in step 2.
5. Return to step 1.
Reading the pixels from an HTML element is slower and slightly more complex but, in my experience, no less reliable. This paper from 2013 details a similar exploit targeting SVG filters: <https://www.contextis.com//documents/2/Browser_Timing_Attacks.pdf>
The basic procedure when targeting mix-blend-mode is as follows:
1. By applying the feColorMatrix filter to an HTML element, select a single pixel from that element and turn it red or black depending on whether one of its channels has a value greater than a certain threshold.
2. By applying the feTile filter to the previous filter's result, blow up that single pixel of red or black to take up a large area of the screen.
3. Layer many rectangular elements with random background colors and `mix-blend-mode: saturation` on top of the filtered element.
4. Call requestAnimationFrame. When the browser is finished rendering the changes that have just been made, it will call a callback, which will be able to determine how long the render took.
5. Based on whether the render completed quickly or slowly, it can be determined whether the selected channel of the selected pixel is greater than the selected threshold.
6. Return to step 1.
Expected results:
A Web page should not be able to infer cross-origin data.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the rendering engine's blend and composite operations have data-dependent execution times, and the browser does not pad or otherwise hide those timing differences from page script.
Impact
An attacker could infer the contents of a cross-origin image or an arbitrary HTML element such as an iframe, though the exploit is timing-sensitive and may not work on every system without tuning.
What the attacker needed
Victim visits attacker page; cross-origin image or iframe present; timing-sensitive environment
How it was found
- Render a single pixel from the cross-origin image onto a canvas.
- Manipulate the canvas so it is in one of two states depending on whether that pixel's colour has certain properties.
- Time how long it takes to render the canvas, scaled up, onto another canvas using a globalCompositeOperation chosen to maximise the timing difference.
- Use the fast or slow result to decide whether the pixel's colour has the selected properties.
- Repeat for the next pixel.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Web pages are normally not allowed to read pixels from images or iframes hosted on other sites. This report shows that by measuring how long certain drawing operations take, a page can guess those hidden pixel colours one by one. It is a timing side channel: the time taken leaks information that should have stayed secret.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.