Skip to content
Info disclosure Disclosed report Advanced CVE-2020-16012

drawImage timing depends on alpha-channel value, allowing to read cross-origin images

A timing side-channel in the drawImage canvas API allows an attacker to infer the alpha channel of pixels in cross-origin images. By measuring how long drawImage takes for different alpha values, an attacker can reconstruct the outline of a remote image.

Aleksejs Popovs Follow

Originally disclosed on Mozilla

  • Fixed in 4 months
  • Paid in 4 months
  • Disclosed after 4 months
Text
Created attachment 9152894
drawimage-timing.zip

Greetings,

I have discovered a timing side-channel that can be used recover parts of images located on 3rd party origins.

At least on my machine, calling drawImage(img, 0, 0, 1, 1, 0, 0, 1024, 1024) on a CanvasRenderingContext2D (which draws the top-left pixel of img onto the canvas, blown up to be 1024x1024) takes a measurably shorter amount of time when the top-left pixel is completely transparent (A = 0) than when it is completely opaque (A = 255), which in turn takes a measurably shorter time than when it is partially opaque (1 <= A <= 254).

Because img can be an image from a different origin, this can be used to figure out which of its pixels are transparent, thus inferring its outline.

I am attaching an archive that contains two proofs of concept:

- in the folder "benchmark" is a page that measures the performance of drawImage using source images of different colors and outputs a CSV (warning: it will lock up the renderer for a couple minutes). "drawimage_timing.png" is a chart generated from the output of this benchmark on my machine, showing clearly the three different performance levels.
- in the folder "exploit" is a complete exploit that will reconstruct a 5x5 remote image in about 10s. Note that opening it will make a remote request to my server to load the target image. "exploit_screenshot.png" is a screenshot showing it working successfully on my machine.

I am not sure how to make a PoC that would be easily integrated into a test suite, and am open to suggestions. Perhaps a version of "benchmark" that also runs a statistical test on its output could be helpful?

I have tested this on an empty profile on Firefox 76.0.1 64-bit, running on Linux 5.6.14 using X. As far as I can tell, here this behavior is ultimately caused by optimizations in Cairo, the graphics library used on this platform:

- CanvasRenderingContext2D::drawImage calls DrawTargetCairo::DrawSurface (gfx/2d/DrawTargetCairo.cpp),
- which calls PaintWithAlpha (gfx/2d/DrawTargetCairo.cpp),
- which calls cairo_paint (gfx/cairo/cairo/src/cairo.c),
- which calls _cairo_gstate_paint (gfx/cairo/cairo/src/cairo-gstate.c),
- which calls _cairo_surface_paint (gfx/cairo/cairo/src/cairo-surface.c),
- which calls _cairo_pattern_is_clear in the same file. This function returns TRUE if the source is fully transparent, in which case _cairo_surface_paint returns and we get the super-fast behavior for A = 0.

I am not yet sure where the difference in behavior in the 1 <= A <= 254 vs A = 255 cases is coming from, though that also sounds like a reasonable optimization a graphics library might perform.

I imagine similar behavior might be present on other platforms using other graphics libraries, but don't have a machine running a different OS to check. The benchmarking code I include should hopefully be helpful for diagnosing that.

The original report as published on Mozilla's Bugzilla, by Aleksejs Popovs. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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 graphics library (Cairo) optimises drawing fully transparent pixels by skipping work, and also treats fully opaque pixels differently from partially transparent ones, creating measurable timing differences.

Impact

An attacker could reconstruct the outline of a cross-origin image, potentially leaking sensitive visual information, though the exploit is limited to timing differences and may vary by platform.

What the attacker needed

Victim visits a malicious page; target image is cross-origin; browser uses Cairo graphics library

How it was found

  1. Load a cross-origin image into an image element.
  2. Call drawImage on a canvas context, scaling a single pixel to a large size.
  3. Measure the time taken for the drawImage call.
  4. Repeat for different pixels to infer transparency and reconstruct the image outline.

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.

When you draw an image from another website onto a canvas, the browser normally blocks you from reading its pixels to protect privacy. This report shows that the time it takes to draw a single pixel depends on whether that pixel is transparent, opaque, or partially transparent. By timing many draws, an attacker can guess the shape of the image without ever reading its pixels directly.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More by Aleksejs Popovs

View all

2 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.