Bug 242889 - Canvas' security should not take into account Single Origin (for videos and images)
Summary: Canvas' security should not take into account Single Origin (for videos and i...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Canvas (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jean-Yves Avenard [:jya]
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-07-19 01:14 PDT by Jean-Yves Avenard [:jya]
Modified: 2022-11-30 17:23 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Yves Avenard [:jya] 2022-07-19 01:14:29 PDT
Per canvas' spec:
https://html.spec.whatwg.org/multipage/canvas.html#the-image-argument-is-not-origin-clean

an object image is not origin-clean if:
HTMLOrSVGImageElement
    image's current request's image data is CORS-cross-origin.
HTMLVideoElement
    image's media data is CORS-cross-origin.
HTMLCanvasElement
ImageBitmap
    image's bitmap's origin-clean flag is false.

And as per the security's policy:
https://html.spec.whatwg.org/multipage/canvas.html#security-with-canvas-elements

"To mitigate this, bitmaps used with canvas elements and ImageBitmap objects are defined to have a flag indicating whether they are origin-clean. All bitmaps start with their origin-clean set to true. The flag is set to false when cross-origin images are used."

And various methods will reject their promise according to this origin-clean flag.
Such as getImageData: https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getimagedata
2. If the CanvasRenderingContext2D's origin-clean flag is set to false, then throw a "SecurityError" DOMException.

`CanvasRenderingContext::wouldTaintOrigin` is the method used to determine if a particular object can be used with a canvas.
Image:
https://searchfox.org/wubkat/rev/3c7828ddd50109debe235dded88a94e66d33e879/Source/WebCore/html/canvas/CanvasRenderingContext.cpp#132-133
```
   if (!image->hasSingleSecurityOrigin())
        return true;
```

Videos:
https://searchfox.org/wubkat/rev/3c7828ddd50109debe235dded88a94e66d33e879/Source/WebCore/html/canvas/CanvasRenderingContext.cpp#154-155
```
    if (!video->hasSingleSecurityOrigin())
        return true;
```

This requirement that an object used with a canvas has a single origin isn't found in the canvas spec ; only that the data is CORS-cross-origin

The current implementation prevents drawing into a canvas a video that was served across multiple mirrors as is commonly found in the media world.

The check that hasSingleSecurityOrigin must be true should be removed.
Comment 1 Radar WebKit Bug Importer 2022-07-19 01:14:53 PDT
<rdar://problem/97245327>
Comment 2 Jean-Yves Avenard [:jya] 2022-11-27 16:50:37 PST
Pull request: https://github.com/WebKit/WebKit/pull/6844
Comment 3 EWS 2022-11-30 17:23:49 PST
Committed 257207@main (2c5193d0471c): <https://commits.webkit.org/257207@main>

Reviewed commits have been landed. Closing PR #6844 and removing active labels.