Skip to content

Clarify origin check in document.open() - #2288

Merged
annevk merged 1 commit into
whatwg:masterfrom
jeisinger:clarify-origin-check-in-document-open
Feb 15, 2017
Merged

annevk merged 1 commit into
whatwg:masterfrom
jeisinger:clarify-origin-check-in-document-open

Conversation

@jeisinger

Copy link
Copy Markdown
Member

Fixes #2282

@annevk

annevk commented Jan 24, 2017

Copy link
Copy Markdown
Member

This looks good. Would be good if the tests discussed on IRC can land first.

@jeisinger

Copy link
Copy Markdown
Member Author

working on it

@annevk

annevk commented Feb 2, 2017

Copy link
Copy Markdown
Member

If we make this same origin-domain I think we should just remove the check altogether. It would be redundant with https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl.

@jeisinger

Copy link
Copy Markdown
Member Author

If we make this same origin-domain I think we should just remove the check altogether. It would be
redundant with https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl.

It's not redundant in blink, as you don't lose access to objects you once got. So getting the document and the open function, and then setting the document.domain still allows you to call open on the now no longer same origin-domain document. In that case, the check in step 4 triggers.

In Firefox on the other hand, the membrane will revoke access so step 4 might be indeed redundant.

@zcorpan I don't think your tests are correct due to the difference in how security checks are implemented in the two browsers.

@annevk

annevk commented Feb 2, 2017

Copy link
Copy Markdown
Member

@jeisinger it's not redundant in Blink because Blink doesn't implement the "perform a security check" that the HTML standard requires. If we start defining Blink's model, we'd have to remove that check, from HTML and IDL, and define a couple things in a different way. But putting both in would make it logically inconsistent.

@jeisinger

Copy link
Copy Markdown
Member Author

@annevk maybe I'm misunderstanding. Can you point me at where "perform a security check" is invoked?

@annevk

annevk commented Feb 2, 2017

Copy link
Copy Markdown
Member

@jeisinger

Copy link
Copy Markdown
Member Author

the way I read this is that we have to perform the security check when reading the attribute which we do. The result of reading the attribute is converted to a ECMAScript object that doesn't require further access checks.

So something like this is still spec compliant

const doc = window.frames[0].document; // performs access check to get the doc
const docOpen = doc.open.bind(doc); // performs access check to get open from that doc
document.domain = document.domain; // from now on, access checks won't pass anymore
docOpen(); // should be fine.

@annevk

annevk commented Feb 2, 2017

Copy link
Copy Markdown
Member

Thank you, it does indeed seem to only be invoked on creation, not on invocation. So currently HTML describes Chrome's SOP model and not Firefox's model. And this change would add defense-in-depth for document.open() matching both.

@bzbarsky does that also match your understanding of things as far as HTML and SOP go?

@bzbarsky

bzbarsky commented Feb 2, 2017

Copy link
Copy Markdown
Contributor

@bzbarsky does that also match your understanding of things as far as HTML and SOP go?

Per the current specs as written, in @jeisinger's testcase, when you call docOpen you land in the steps defined in step 2 of https://heycam.github.io/webidl/#dfn-create-operation-function. Step 2.1.2.3 says:

If O is a platform object, then perform a security check, passing O, id, and "method"

which applies to us, since O is doc in this case. That drops us in https://heycam.github.io/webidl/#dfn-perform-a-security-check which then calls into https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl. Step 1 does not apply, but step 2 does, so we land in https://html.spec.whatwg.org/multipage/browsers.html#isplatformobjectsameorigin-(-o-). But the security check passes, because by this point the "current settings object" is that of the doc.open function, which is the same as the relevant settings object of doc.

So per current spec as written, this should in fact succeed in calling into the steps of open.

On the other hand, doing document.open.call(doc) after that document.domain = document.domain line should throw per spec, because at that point the current settings object will be that of document.open and O will be doc in https://html.spec.whatwg.org/multipage/browsers.html#isplatformobjectsameorigin-(-o-) and the two settings objects are not same origin-domain with each other.

In Gecko the step that would throw in that testcase is crossing the now-revoked membrane to reach the [[Call]] of the doc.open function, so none of these steps would be reached at all. So you're right that the spec does not define Gecko's security model.

On the other hand, Chrome does not seem to perform any security check from inside the IDL operation at all, so the spec also does not define Chrome's security model. ;)

Moving right along....

const docOpen = doc.open.bind(doc); // performs access check to get open from that doc

This step does not perform any security checks I'm aware of per the HTML and IDL specs (but does on Gecko, for getting the "open" property, so if you set document.domain before this line, the get of "open" would fail in Gecko).

The only security checks in the specs I'm aware of are the "perform a security check" bits in IDL and the internal methods of WindowProxy and Location objects.

@bzbarsky

bzbarsky commented Feb 2, 2017

Copy link
Copy Markdown
Contributor

Oh, and as for the main topic of this issue: what is the point of the check in doc.open? The point is that doc.open will change the URL of doc to that of "the responsible document of the entry settings object", in https://html.spec.whatwg.org/#dom-document-open step 23. To prevent confusion about URLs that do not match origins, we want to ensure that the origin continues to match the URL. But we don't want to mutate origins either, so we check up front that the origin of doc matches that of "the responsible document of the entry settings object". That's what step 4 is about.

Note that "the responsible document of the entry settings object" may well not be same origin-domain with the actual caller of open() or the document open() is being called on, in all browsers including Gecko. A simple example: script is entered in window A, calls a function in window B, the function in window B sets document.domain and then calls open. At this point the "entry settings" thing is A, the caller of open is B, A need no longer be same origin-domain with B (even in Gecko). B does have to be same origin-domain in Gecko with the document that open() is being called on, of course.

@bzbarsky

bzbarsky commented Feb 2, 2017

Copy link
Copy Markdown
Contributor

One other note: I would have no objection to tightening the security check here to require that the document being opened is both same-origin and same origin-domain with "the responsible document of the entry settings object" if people want that.

I should also note that Chrome and WebKit do some sort of security checks here. I'm just not sure which ones. For example, http://web.mit.edu/bzbarsky/www/testcases/document/document-open-domains.html throws from every single test. But maybe they're checking same origin-domain or something?

@bzbarsky

bzbarsky commented Feb 2, 2017

Copy link
Copy Markdown
Contributor

I should note that http://software.hixie.ch/utilities/js/live-dom-viewer/saved/4851 (cited above) doesn't make sense to me: in that testcase both windows are same-origin and same origin-domain at all times, so there's just no security check issue, right? Hence no exceptions in any browsers.

@zcorpan

zcorpan commented Feb 2, 2017

Copy link
Copy Markdown
Member

@bzbarsky

bzbarsky commented Feb 2, 2017

Copy link
Copy Markdown
Contributor

Right, that sure makes it look like Blink is doing some sort of "same origin-domain" check inside document.open.

@jeisinger

Copy link
Copy Markdown
Member Author

@bzbarsky can you clarify what case should throw when you said "On the other hand, Chrome does not seem to perform any security check from inside the IDL operation at all, so the spec also does not define Chrome's security model. ;)"

@bzbarsky

bzbarsky commented Feb 3, 2017

Copy link
Copy Markdown
Contributor

Well, for example this:

const doc = frames[0].document;
document.domain = document.domain;
document.getElementById.call(doc, "x");

does not throw in Chrome, whereas per spec it should.

@jeisinger

Copy link
Copy Markdown
Member Author

Per the current specs as written, in @jeisinger's testcase, when you call docOpen you land in the steps
defined in step 2 of https://heycam.github.io/webidl/#dfn-create-operation-function. Step 2.1.2.3 says:

I read the spec that creating docOpen runs the "create an operation function" steps, but later calling it doesn't run those steps again.

@bzbarsky

bzbarsky commented Feb 3, 2017

Copy link
Copy Markdown
Contributor

The "create an operation" steps are run at global creation time. They create the JS Function object.

Step 2 of "create an operation" defines the variable steps to be a list of steps, but doesn't run them or anything. Then step 3 passes this variable to CreateBuiltinFunction. That lands you at https://tc39.github.io/ecma262/#sec-createbuiltinfunction. Per step 3 of that algorithm the result is a function that "when called performs the action described by steps".

@jeisinger

Copy link
Copy Markdown
Member Author

ok, I think this boils down to https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl step 2 (IsPlatformObjectSameOrigin) not being implemented in blink (nor is that easily implementable)

@jeisinger

Copy link
Copy Markdown
Member Author

soo... the conclusion is that "same origin-domain" is the right behavior but tests are hard?

@bzbarsky

Copy link
Copy Markdown
Contributor

Conclusion for which?

document.open needs to do an actual "same origin" check. See #2288 (comment)

@jeisinger
jeisinger force-pushed the clarify-origin-check-in-document-open branch from 09582bf to b3bec4d Compare February 15, 2017 10:47
@jeisinger

Copy link
Copy Markdown
Member Author

right. Update this PR, the WPT PR, and https://codereview.chromium.org/2691083006 updates blink to check for same-origin

@annevk

annevk commented Feb 15, 2017

Copy link
Copy Markdown
Member

Okay, so this PR as-is is correct, but there should be a follow-up issue where we discuss "perform a security check" and what we actually want as a security model, is that correct? (And yes, I realize we have tried in the past, but we should keep trying and at least acknowledge the current standard matches nobody there...)

@jeisinger

Copy link
Copy Markdown
Member Author

yeah, there's some discussion going on on the (private) issue that @bzbarsky filed on crbug.com

I'll file an issue once we come to a conclusion what to do

@annevk
annevk merged commit 87e60ab into whatwg:master Feb 15, 2017
@bzbarsky

Copy link
Copy Markdown
Contributor

I doubt "we" (broadly speaking) are going to come to a "conclusion what to do" in a hidden Blink issue, fwiw. ;)

@annevk

annevk commented Feb 15, 2017

Copy link
Copy Markdown
Member

FWIW, after stating that #2360 was filed as well, so there's now a public issue where we can try to make progress on this question as well.

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.

4 participants