Hi
TL;DR: Help me understand the spec about how scripts should behave on detached frames :)
Background: Script execution on detached frames has caused a bunch of security issues. I'm now investigating if it's feasible to forbid script execution on detached frames.
Consider the following code:
<script>
onload = function() {
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
var win = iframe.contentWindow;
var doc = iframe.contentWindow.document;
win.foo = "aaa";
doc.foo = "bbb";
document.body.removeChild(iframe);
var iterator = doc.createNodeIterator(doc, NodeFilter.SHOW_ELEMENT, null, false);
console.log(win.foo);
console.log(doc.foo);
console.log(iterator);
}
</script>
Chrome, Firefox, Safari and IE behave as follows:
Chrome:
aaa
bbb
[object NodeIterator]
Firefox:
aaa
undefined
[object NodeIterator]
Safari:
undefined
bbb
[object NodeIterator]
IE:
undefined
bbb
[object NodeIterator]
As far as I read
the spec, it is saying that "User agents must not allow the user to interact with child browsing contexts of elements that are in Documents that are not themselves fully active". I interpret this meaning that user agents must not allow the user to interact with detached iframes. Thus I think the code should behave as follows:
undefined or throw an exception
undefined or throw an exception
undefined or throw an exception
Here are a couple of questions:
1) What does "user agents must not allow..." mean? Does it mean that window.foo should return undefined? Or does it mean that it should throw an exception?
2) If the user calls doc.createNodeIterator(), should we interpret that the user is interacting with the detached frame, or not? doc.createNodeIterator() is not explicitly touching the iframe's window object but is implicitly interacting with the iframe's window object by creating a DOM wrapper on the window object. In other words, should doc.createNodeIterator() return a valid DOM wrapper? Or should it return undefined or throw an exception? (As described above, all the browsers are returning a valid DOM wrapper currently.)
3) When is an unload handler dispatched? I think the unload handler should have an ability to do something on the detached frame. Is the unload handler dispatched before Frame::detach is called? Or is the unload handler dispatched after Frame::detach is called but before LocalDOMWindow::reset is called? (If the latter is the case, we need to somehow support executing the unload handler on the detached frame.)
--
Kentaro Hara, Tokyo, Japan