Canvas drawImage() has a security hole when the image isn't yet fully loaded.
authorsaid@apple.com <said@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Apr 2015 19:53:14 +0000 (19:53 +0000)
committersaid@apple.com <said@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Apr 2015 19:53:14 +0000 (19:53 +0000)
commit415701b2648b8b0f7c6309c76c6ac09028ffcc23
tree59e748e22522bf3d8b9884ec0d65b844a5b7abc1
parent8700bcadb377b951778daf1b85a4b904192f2479
Canvas drawImage() has a security hole when the image isn't yet fully loaded.
https://bugs.webkit.org/show_bug.cgi?id=58681.

Reviewed by Darin Adler.

Source/WebCore:

There is a race condition which may happen if an image from a different
origin is drawn on a canvas before it finishes loading. The check to taint
the canvas comes before drawing it. This check returns false if the image
is not completely loaded because we check the URL of the resource response.
If after this check and before the drawing, the image finishes loading, the
canvas will not be tainted but the image will be drawn.

The fix is to move the check to taint the canvas after drawing the image.
The only problem with this solution is basically the opposite of this bug:
we will become stricter than before with images which are from a different
origin and before they finish loading. The image has not finished loading,
so we do not draw it. Before we check for tainting, the image finishes
loading. So we decide to taint the canvas even the image is not drawn.

But this should not be a security issue anymore. I personally do not know
if it is even a correctness issue or not.

Test: http/tests/canvas/canvas-tainted-after-draw-image.html

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawImage):

LayoutTests:

This test confirms when we load an image from a different origin and try
drawing it on a canvas, the canvas is tainted if the image is completely
loaded and drawn. Otherwise the image is not drawn.

* http/tests/canvas/canvas-tainted-after-draw-image-expected.txt: Added.
* http/tests/canvas/canvas-tainted-after-draw-image.html: Added.
* http/tests/canvas/resources: Added.
* http/tests/canvas/resources/100x100-lime-rect.svg: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182750 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/http/tests/canvas/canvas-tainted-after-draw-image-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/canvas/canvas-tainted-after-draw-image.html [new file with mode: 0644]
LayoutTests/http/tests/canvas/resources/100x100-lime-rect.svg [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp