Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ImageBitmap content security policy to use 'origin-clean' #385

Closed
wants to merge 1 commit into from
Closed

Conversation

junov
Copy link
Member

@junov junov commented Dec 4, 2015

Currently, image bitmap creation fails when the source is from another origin
or is tainted with cross-origin content. This is unnecessarily restrictive and
hinders use cases envisaged in the OffscreenCanvas feature proposal.

@junov junov changed the title Changing ImageBitmap content security policy to use 'origin-clean' Change ImageBitmap content security policy to use 'origin-clean' Dec 4, 2015
@kenrussell
Copy link
Member

This will be extremely useful. One question: for createImageBitmap taking Blob, the Blob couldn't have been fetched if it wasn't effectively same-origin with the document, correct? So ImageBitmaps created from Blobs will always be origin-clean?

@domenic
Copy link
Member

domenic commented Dec 4, 2015

Hmm I think this needs @mikewest and @bzbarsky as reviewers at least.

Haven't done a review but one nit is the commit message: https://github.com/erlang/otp/wiki/Writing-good-commit-messages

@xidachen
Copy link
Contributor

xidachen commented Dec 5, 2015

I think this would be applied to HTMLImageElement and HTMLVideoElement only.

@bzbarsky
Copy link
Contributor

bzbarsky commented Dec 5, 2015

I haven't thought through the ImageBitmap bits very much so far. You may want to check with Robert O'Callahan on the mailing list; I'm not sure he has a github account.

@domenic
Copy link
Member

domenic commented Dec 5, 2015

@rocallahan, thoughts?

@rocallahan
Copy link

This is probably the right thing to do. It enables usage of cross-origin images for some use-cases at the expense of making all ImageBitmap APIs more complicated...

@junov
Copy link
Member Author

junov commented Dec 10, 2015

Commit message was updated.

objects are defined to have a flag indicating whether they are <span
data-x="concept-canvas-origin-clean">origin-clean</span>. All bitmaps start with their <span
data-x="concept-canvas-origin-clean">origin-clean</span> set to true. The flag is set to false
when cross-origin images or fonts are used.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a <dfn> for its own variable. The one for <canvas> doesn't really apply here.

@annevk annevk assigned annevk and unassigned mikewest Dec 15, 2015
@junov
Copy link
Member Author

junov commented Dec 16, 2015

Updated commit. Applied @annevk feedback


<p>The <code data-x="dom-canvas-toDataURL">toDataURL()</code>, <code
data-x="dom-canvas-toBlob">toBlob()</code>, and <code
data-x="dom-context-2d-getImageData">getImageData()</code> methods check the flag and will
throw a <code>SecurityError</code> exception rather than leak cross-origin data.</p>

<p>The value of the <span data-x="concept-ImageBitmap-origin-clean">origin-clean</span> flag is
propagated from a source <code>canvas</code> element's bitmap to a new <code>ImageBitmap</code>
object by createImageBitmap. Conversely, a destination <code>canvas</code> element's bitmap will
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/createImageBitmap/<code data-x="dom-createImageBitmap">createImageBitmap()</code>/

@junov
Copy link
Member Author

junov commented Dec 17, 2015

Made the corrections

propagated from a source <code>canvas</code> element's bitmap to a new <code>ImageBitmap</code>
object by <code data-x="dom-createImageBitmap">createImageBitmap()</code>. Conversely, a
destination <code>canvas</code> element's bitmap will have its <span
data-x="concept-ImageBitmap-origin-clean">origin-clean</span> flags set to false by drawImage if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong origin-clean flag. Also, drawImage should be marked up similarly to createImageBitMap. Sorry for not catching this the last time around.

@annevk
Copy link
Member

annevk commented Dec 17, 2015

Also, once that is sorted @domenic can probably land this. I'll be away until January 1 and it doesn't seem necessary to wait until then.

@annevk annevk assigned domenic and unassigned annevk Dec 17, 2015
@domenic
Copy link
Member

domenic commented Dec 17, 2015

I still think this needs security review from @mikewest... am I wrong?

@annevk
Copy link
Member

annevk commented Dec 17, 2015

I feel fairly confident that the security aspect is fine. But happy to let @mikewest take a look first.

@domenic
Copy link
Member

domenic commented Dec 17, 2015

Hmm, I can trust you on that, so will merge after the above corrections are made.

@junov
Copy link
Member Author

junov commented Dec 17, 2015

Okay. I made the changes. Switched back to "concept-canvas-origin-clean" everywhere. Edited the definition of "concept-canvas-origin-clean" to make it inclusive of ImageBitmap. Fixed line wrapping mistake.

contexts, such as those described in the section on the <code>CanvasRenderingContext2D</code>
object below, have an <dfn data-x="concept-canvas-origin-clean">origin-clean</dfn> flag, which can
be set to true or false. Initially, when the <code>canvas</code> element is created, its bitmap's
<p>The bitmaps of <code>canvas</code> elements, the bitmaps of ImageBitmap objects, as well as
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs <code> around ImageBitmap. Also below.

Before this change, the content security policy of ImageBitmap did not
allow any cross-origin content in ImageBitmap objects. Attempts to do
so would cause SecurityError exceptions to be thrown. With this
change, a tainting mechanism is added to ImageBitmap, which allows
cross-origin content to be transported by ImageBitmaps while still
protecting the bitmap image data from being accessed by script. The
tainting mechanism uses an 'origin clean' flag that works much like
the 'origin clean' flag of canvas element bitmaps.
@junov
Copy link
Member Author

junov commented Dec 17, 2015

Done.

domenic pushed a commit that referenced this pull request Dec 20, 2015
Before this change, the content security policy of ImageBitmap did not
allow any cross-origin content in ImageBitmap objects. Attempts to do
so would cause SecurityError exceptions to be thrown. With this
change, a tainting mechanism is added to ImageBitmap, which allows
cross-origin content to be transported by ImageBitmaps while still
protecting the bitmap image data from being accessed by script. The
tainting mechanism uses an 'origin clean' flag that works much like
the 'origin clean' flag of canvas element bitmaps.

PR #385
@domenic
Copy link
Member

domenic commented Dec 20, 2015

Merged as 083c57c, woo!

@domenic domenic closed this Dec 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants