<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>20390</bug_id>
          
          <creation_ts>2012-12-14 16:02:45 +0000</creation_ts>
          <short_desc>The origin of documents not in a browsing context is wrong in the spec</short_desc>
          <delta_ts>2012-12-20 17:36:42 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>DOM</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#sandboxOrigin</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>annevk</cc>
    
    <cc>bobbyholley</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>Ms2ger</cc>
    
    <cc>www-dom</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>80184</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-12-14 16:02:45 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html
Multipage: http://www.whatwg.org/C#sandboxOrigin
Complete: http://www.whatwg.org/c#sandboxOrigin

Comment:
The origin of documents not in a browsing context is wrong in the spec

Posted from: 173.48.81.109 by bzbarsky@mit.edu
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:20.0) Gecko/20121213 Firefox/20.0</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80185</commentid>
    <comment_count>1</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-14 16:06:25 +0000</bug_when>
    <thetext>At the very least this part:

     If a Document was obtained in some other manner (e.g. a data: URL typed in
     by the user, a Document created using the createDocument() API, etc)

    The origin is a globally unique identifier assigned when the Document is
    created.

and this part:

  User agents must throw a SecurityError exception whenever any properties of a
  Document object are accessed by scripts whose effective script origin is not
  the same as the Document&apos;s effective script origin.

means that if you createDocument() you then can&apos;t touch its properties.  Which on the face of it is bogus. Similar issues with new Document() and DOMParser...

XHR responseXML is OK, but only because XHR explicitly stamps the source origin on the responseXML document.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80223</commentid>
    <comment_count>2</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-12-14 23:24:58 +0000</bug_when>
    <thetext>Uh yeah, that&apos;s weird. I should call out createDocument()-created docs separately.

Anne, is the origin of a createDocument()-created Document something that DOM Core can define somehow so I can just point to that?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80234</commentid>
    <comment_count>3</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-12-15 10:18:47 +0000</bug_when>
    <thetext>I could define that Document objects next to having a URL, content type, and encoding, they also have an origin which is a globally unique identifier when the document is created.

Then for createDocument(), createHTMLDocument(), and the Document constructor I will say that the origin must be set to the global object&apos;s associated Document object&apos;s origin.

It seems that will start blurring the lines between HTML and DOM, but I do not really see a better way (other than maybe adding hooks to all the places where a Document is constructed).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80371</commentid>
    <comment_count>4</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-12-18 19:19:10 +0000</bug_when>
    <thetext>IMHO there are no lines between HTML and DOM. :-P</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80373</commentid>
    <comment_count>5</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-12-18 19:52:47 +0000</bug_when>
    <thetext>Okay, the tentative plan is to implement comment 3 and file a bug on HTML to align with DOM afterwards.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80402</commentid>
    <comment_count>6</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-12-19 12:44:30 +0000</bug_when>
    <thetext>Defined concept-document-origin and used it. Used the entry script&apos;s origin to define the origin of document objects created through script.

https://github.com/whatwg/dom/commit/922830c931d8b04d52e3482dfd9985cdcead43fe

I&apos;ll update XHR to use this new concept and file a bug on HTML, but maybe bz can confirm that using the entry script&apos;s origin is correct?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80416</commentid>
    <comment_count>7</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-19 17:45:41 +0000</bug_when>
    <thetext>Actually, using the entry script for origin stuff is almost never correct, I think.  See thread starting with http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-November/038017.html and in particular http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-November/038023.html and http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-November/038030.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80417</commentid>
    <comment_count>8</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-19 17:46:39 +0000</bug_when>
    <thetext>And in particular, I think that each API that creates documents should explicitly define the origin that will be used for that document.  For a DOMParser, say, it should be the origin of the Window the DOMParser is associated with or something like that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80421</commentid>
    <comment_count>9</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-12-19 18:20:21 +0000</bug_when>
    <thetext>So Window objects don&apos;t seem to have an origin per HTML. The global object&apos;s associated Document of course does. We could use that for new Document(), createDocument(), and createHTMLDocument(). Is that what Gecko does?

Note that DOM just defines a default being a globally unique identifier, but also defines that for new Document(), createDocument(), and createHTMLDocument(), that is overridden (currently by the entry script&apos;s origin, but I guess we should change that to something else).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80422</commentid>
    <comment_count>10</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-19 19:38:58 +0000</bug_when>
    <thetext>What Gecko does is use an alias to the origin and effective script origin of the Window (which is NOT the same as using the origin and effective script origin, note; I believe the alias thing is what we want).

In gecko, the origin and effective script origin of a Window alias the origin and effective script origin of its associated document while it has a document.  When it loses the document (unloaded, frame removed from DOM, document.open(), whatever) it continues to alias that no-longer-associated document&apos;s origin and effective script origin.  If in the spec Windows never end up in a state where they have no associated document, then the spec can just talk about aliasing the associated document.

&gt; Note that DOM just defines a default being a globally unique identifier, but
&gt; also defines that for new Document(), createDocument(), and
&gt; createHTMLDocument(), that is overridden

That makes sense to me.

In all three of those cases we should, imo, alias the origin and effective script origin of the document involved (the associated document of the Window for the constructor, and the document the DOMImplementation came from for the other two).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80445</commentid>
    <comment_count>11</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-12-20 16:11:53 +0000</bug_when>
    <thetext>I have done exactly that now.

Search for &quot;effective script origin&quot; in http://dom.spec.whatwg.org/ to find all the instances. The catch all sets them to a globally unique identifer. new Document(), createDocument(), and createHTMLDocument(), use the alias concept as you described.

I also filed bug 20463 to update HTML.

https://github.com/whatwg/dom/commit/2f2cdf4a29b7ed299c38f60eb35ed98918a7f439
https://github.com/whatwg/dom/commit/0d20aee2ccccb9b9e2baacdca9b0ba82d398b948</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80449</commentid>
    <comment_count>12</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-20 17:36:42 +0000</bug_when>
    <thetext>Looks good, thanks!</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>