This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 27204 - Provide guidance on entry vs incumbent settings objects
Summary: Provide guidance on entry vs incumbent settings objects
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: Unwelcome (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: Unsorted
Assignee: Michael[tm] Smith
QA Contact: sideshowbarker+unwelcome
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 27203
  Show dependency treegraph
 
Reported: 2014-10-31 08:11 UTC by Anne
Modified: 2016-06-15 19:28 UTC (History)
8 users (show)

See Also:


Attachments

Description Anne 2014-10-31 08:11:22 UTC
According to bz for anything new we should use incumbent for origin checks and entry for base URL and Referrer. It might be good to stipulate that clearly.
Comment 1 Boris Zbarsky 2014-10-31 08:16:56 UTC
It's not clear that we want to use incumbent for origin checks, except when operating on cross-origin Window and Location, which are their own special kettle of fish.  I think we should seriously think about using the current Realm for origin checks in normal cases.
Comment 2 Anne 2014-10-31 08:20:05 UTC
So there's three set of objects in play? Entry, incumbent, and current Realm? Current Realm seems fine, but that would require some kind of IDL hook, right? And again, people will need guidance as this is hard.
Comment 3 Bob Owen 2014-10-31 08:51:40 UTC
(In reply to Anne from comment #0)
> According to bz for anything new we should use incumbent for origin checks
> and entry for base URL and Referrer. It might be good to stipulate that
> clearly.

For navigation, I think the referrer is generally supposed to come from the Source Browsing Context, see [1].
This can be a variety of things, including coming from the incumbent settings object.
I'm not sure it is ever specified as coming from the entry settings object, although it could of course end up being the same thing.

[1] https://html.spec.whatwg.org/multipage/infrastructure.html#processing-model
Comment 4 Bobby Holley (:bholley) 2014-10-31 10:15:37 UTC
(In reply to Boris Zbarsky from comment #1)
> It's not clear that we want to use incumbent for origin checks

Agreed. See bug 26603.

> except when
> operating on cross-origin Window and Location, which are their own special
> kettle of fish.

Yeah. And even for that it's not really using the origin for a security check per se, but rather for determining the "Caller-Appropriate Cross-Origin Representation" of the various methods and accessors. See the current draft of the spec for this stuff: https://etherpad.mozilla.org/html5-cross-origin-objects

> I think we should seriously think about using the current
> Realm for origin checks in normal cases.

Definitely.
Comment 5 Boris Zbarsky 2014-10-31 14:51:23 UTC
> So there's three set of objects in play? Entry, incumbent, and current Realm? 

Yes.

> but that would require some kind of IDL hook, right?

That's a good question.

Per ES, every function object (and this includes the getters/setters/methods IDL generates) has an associated Realm and that Realm becomes the current Realm when the function is called.

We may need a mechanism to go from a Realm to a settings object or an origin, but that doesn't seem like an IDL thing.  Rather, that seems like something that's part of the prose defining a global object, right?

> And again, people will need guidance as this is hard.

Yes, I agree.
Comment 6 Anne 2014-10-31 14:57:02 UTC
The IDL hook is needed for the prose written in specifications as that typically does not deal with the JavaScript environment (nor theoretically has access to it I suppose). Currently it can use "entry settings object" or "incumbent settings object". And XMLHttpRequest uses something different again: https://xhr.spec.whatwg.org/#dom-xmlhttprequest
Comment 7 Boris Zbarsky 2014-10-31 15:13:26 UTC
> nor theoretically has access to it I suppose

That's flat-out impossible, because it needs to be able to create JS objects like typed arrays and promises.  IDL describes how to do the type conversions, but all it does is "return the same object".  _Creating_ the thing requires access to a JS global environment.

Right now specs sweep this under the hood, which is actually pretty confusing, because it doesn't make it clear which JS global environment is getting used.  I'm 99% sure this leads to observable behavior differences between browsers in edge cases (some of which may be somewhat covered up by IDL instanceof operating on cross-global objects).  Just like the failure of most specs to specify which global environment their 

If we want to have the polite fiction that IDL is language-agnostic, we need to seriously rework how these objects work in IDL.

One other note.  IDL defines a "perform a security check" operation, or rather a hook for performing such a check that gets passed the things to check against each other.  This explicitly uses the current Realm to get the global and then passes that to "perform a security check".  See <http://heycam.github.io/webidl/#es-security>.  Sadly, HTML doesn't actually define what it means to "perform a security check".  :(
Comment 8 Boris Zbarsky 2014-10-31 15:24:48 UTC
> I'm 99% sure this leads to observable behavior differences

For example, try https://web.mit.edu/bzbarsky/www/testcases/global-object-association/webcrypto-parent.html in Firefox and Chrome.

> we need to seriously rework how these objects work in IDL.

Or at least provide IDL hooks for creating Promise and typed array objects... and decide whether these hooks use some implicit global (which one?) or have to be handed an explicit global, together with a hook for getting the current realm global or something.
Comment 9 Anne 2014-10-31 17:48:04 UTC
Filed bug 27212 on HTML to define that security check.

I would be happy for IDL to remove the language agnostic stuff and just be JavaScript.
Comment 10 Anne 2014-10-31 18:20:24 UTC
Bug 24652 is the IDL bug on defining the associated Realm.
Comment 11 Ian 'Hixie' Hickson 2014-11-04 00:44:16 UTC
If this is asking for spec writing guidance, shouldn't that be in the wiki?
Comment 12 Anne 2014-11-04 08:23:05 UTC
I don't know. In my experience people write specs the same way they write code. By copy and pasting others and then changing the bits they don't like until it looks "reasonable". This argues for some short clarifying notes if concepts are particularly tricky.
Comment 13 Arun 2014-11-18 21:00:00 UTC
Something like this: http://www.w3.org/2001/tag/doc/promises-guide

would be good, but applied to Realm as well, as mentioned in Bug 26603.

Currently, Blob URLs use this to define origin.
Comment 14 Ian 'Hixie' Hickson 2015-01-15 23:42:23 UTC
I'm all for people writing spec writing advice, guides, wiki pages, and so on. I don't have the bandwidth to do it.
Comment 15 Domenic Denicola 2016-06-15 19:28:43 UTC
I believe this is taken care of by https://html.spec.whatwg.org/multipage/webappapis.html#realms-settings-objects-global-object