Skip to content
Info disclosure Disclosed report Advanced CVE-2019-9817

Security: Cross-origin theft of images in fillText and CanvasPattern

A canvas could be filled with a cross-origin image used as a text fill pattern, and the resulting canvas could then be exported with toDataURL, leaking the image pixels. An attacker could steal images from other origins that the victim's browser had loaded.

Luật Nguyễn Follow

Originally disclosed on Mozilla

  • Fixed in 24 days
  • Paid in 24 days
  • Disclosed after 24 days
Text
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36

Steps to reproduce:

1. Navigate to https://cyberjutsu.io/files/cross_origin_fillText.html
2. You can see the Google logo has been stolen, then print it out as the textarea value

Tested on latest Stable && Nightly (Windows 10)




Actual results:

At https://dxr.mozilla.org/mozilla-central/source/dom/canvas/CanvasRenderingContext2D.cpp?redirect_type=single#3527

'''

      if (state->gradientStyles[style]) {  // Gradient
        pattern = GetGradientFor(style);
      } else if (state->patternStyles[style]) {  // Pattern
        pattern = GetPatternFor(style); 
      } else {
        MOZ_ASSERT(false, "Should never reach here.");
        return;
      }
      MOZ_ASSERT(pattern, "No valid pattern.");

      if (style == Style::FILL) {
        params.context->SetPattern(pattern);
      } else {
        params.textStrokePattern = pattern;
      }

'''

it's possible to draw a canvaspattern (which can be loaded with an image) as background of a text.

Due to lacking of checking mWriteonly/Principal/CORs later on, we can extract the whole canvas by calling .toDataURL() for example.

'''
    ctx.font = "10000px Arial"; // <-- make the dot "." to big, to leak the whole image. we can fix it dynamically depends on image's size.
    ctx.fillStyle = pattern; 
    ctx.fillText(".", 0, 200);
'''




Expected results:

canvas.toDataURL() should not be invoked successfully due to invalid CORs.

The original report as published on Mozilla's Bugzilla, by Luat Nguyen. 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 text fill-pattern path did not mark the canvas as tainted or check the image's origin, so the cross-origin restriction was skipped.

Impact

A malicious page could read pixels of cross-origin images the victim's browser can load, potentially stealing private or authenticated image content.

What the attacker needed

Victim visits a malicious page; target image is loadable cross-origin

The fix

The canvas should be tainted, or the export blocked, whenever a cross-origin image is used as a text fill pattern.

How it was found

  1. Open the proof-of-concept page in the browser.
  2. Observe that the cross-origin logo is drawn as a text fill pattern.
  3. Read the canvas back with toDataURL and see the stolen image printed as the textarea value.

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 can draw images onto a canvas, but browsers normally block reading back the pixels of a canvas that contains an image from another website, to stop data theft. Here the browser forgot that check when the image was used as a pattern to fill text, so the page could read the pixels anyway.

What is Info disclosure?

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

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.