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.
Originally disclosed on Mozilla
- Fixed in 24 days
- Paid in 24 days
- Disclosed after 24 days
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.
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
- Open the proof-of-concept page in the browser.
- Observe that the cross-origin logo is drawn as a text fill pattern.
- 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.