Changeset 182750 in webkit


Ignore:
Timestamp:
Apr 13, 2015 12:53:14 PM (9 years ago)
Author:
Said Abou-Hallawa
Message:

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.
Location:
trunk
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r182748 r182750  
     12015-04-13  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        Canvas drawImage() has a security hole when the image isn't yet fully loaded.
     4        https://bugs.webkit.org/show_bug.cgi?id=58681.
     5
     6        Reviewed by Darin Adler.
     7
     8        This test confirms when we load an image from a different origin and try
     9        drawing it on a canvas, the canvas is tainted if the image is completely
     10        loaded and drawn. Otherwise the image is not drawn.
     11
     12        * http/tests/canvas/canvas-tainted-after-draw-image-expected.txt: Added.
     13        * http/tests/canvas/canvas-tainted-after-draw-image.html: Added.
     14        * http/tests/canvas/resources: Added.
     15        * http/tests/canvas/resources/100x100-lime-rect.svg: Added.
     16
    1172015-04-13  Beth Dakin  <bdakin@apple.com>
    218
  • trunk/Source/WebCore/ChangeLog

    r182748 r182750  
     12015-04-13  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        Canvas drawImage() has a security hole when the image isn't yet fully loaded.
     4        https://bugs.webkit.org/show_bug.cgi?id=58681.
     5
     6        Reviewed by Darin Adler.
     7
     8        There is a race condition which may happen if an image from a different
     9        origin is drawn on a canvas before it finishes loading. The check to taint
     10        the canvas comes before drawing it. This check returns false if the image
     11        is not completely loaded because we check the URL of the resource response.
     12        If after this check and before the drawing, the image finishes loading, the
     13        canvas will not be tainted but the image will be drawn.
     14       
     15        The fix is to move the check to taint the canvas after drawing the image.
     16        The only problem with this solution is basically the opposite of this bug:
     17        we will become stricter than before with images which are from a different
     18        origin and before they finish loading. The image has not finished loading,
     19        so we do not draw it. Before we check for tainting, the image finishes
     20        loading. So we decide to taint the canvas even the image is not drawn.
     21       
     22        But this should not be a security issue anymore. I personally do not know
     23        if it is even a correctness issue or not.
     24
     25        Test: http/tests/canvas/canvas-tainted-after-draw-image.html
     26
     27        * html/canvas/CanvasRenderingContext2D.cpp:
     28        (WebCore::CanvasRenderingContext2D::drawImage):
     29
    1302015-04-13  Beth Dakin  <bdakin@apple.com>
    231
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r182207 r182750  
    13781378        return;
    13791379
    1380     checkOrigin(image);
    1381 
    13821380    if (rectContainsCanvas(normalizedDstRect)) {
    13831381        c->drawImage(cachedImage->imageForRenderer(image->renderer()), ColorSpaceDeviceRGB, normalizedDstRect, normalizedSrcRect, ImagePaintingOptions(op, blendMode));
     
    13941392        didDraw(normalizedDstRect);
    13951393    }
     1394
     1395    checkOrigin(image);
    13961396}
    13971397
Note: See TracChangeset for help on using the changeset viewer.