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

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>17099</bug_id>
          
          <creation_ts>2008-01-30 12:00:59 -0800</creation_ts>
          <short_desc>Add Mozilla tests for postMessage, fix bugs they reveal</short_desc>
          <delta_ts>2010-01-03 10:34:37 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Tools / Tests</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>OS X 10.5</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc>http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-May/014665.html</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Adam Barth">abarth</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>annevk</cc>
    
    <cc>ap</cc>
    
    <cc>collinj</cc>
    
    <cc>jwalden+bwo</cc>
    
    <cc>sam</cc>
    
    <cc>sylvain.pasche</cc>
    
    <cc>webkit</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>68828</commentid>
    <comment_count>0</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2008-01-30 12:00:59 -0800</bug_when>
    <thetext>Jeff Walden has posted the Mozilla regression tests for postMessage to the WHATWG mailing list:

http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-January/013795.html

He says that WebKit fails a number of these tests.  We should convert them to LayoutTests, add them to our test suite, and fix the bugs they reveal.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69006</commentid>
    <comment_count>1</comment_count>
    <who name="Robert Blaut">webkit</who>
    <bug_when>2008-01-31 22:27:28 -0800</bug_when>
    <thetext>This test http://virtuelvis.com/download/2005/12/crossdocument/sender.html also doesn&apos;t work.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69008</commentid>
    <comment_count>2</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2008-01-31 22:47:25 -0800</bug_when>
    <thetext>(In reply to comment #1)
&gt; This test http://virtuelvis.com/download/2005/12/crossdocument/sender.html also
&gt; doesn&apos;t work.

I believe this doesn&apos;t work because it is using the following
  var receiver = document.getElementsByTagName(&quot;iframe&quot;)[0].contentDocument;
  receiver.postMessage(val);

The issue is that it is using contentDocument instead of contentWindow.  postMessage is a function of the window, not the document.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69025</commentid>
    <comment_count>3</comment_count>
    <who name="Jeff Walden (remove +bwo to email)">jwalden+bwo</who>
    <bug_when>2008-02-01 01:31:19 -0800</bug_when>
    <thetext>Opera pioneered postMessage on document; HTML5 puts it on window.  Given that IE7 no longer allows cross-origin access to documents and Firefox 3 is following in its footsteps, and given that narrowing the cross-origin attack surface to just window is better security-wise, I don&apos;t think the location of postMessage will change, for what it&apos;s worth.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69338</commentid>
    <comment_count>4</comment_count>
    <who name="Anne van Kesteren">annevk</who>
    <bug_when>2008-02-04 04:57:45 -0800</bug_when>
    <thetext>We have changed our (Opera) implementation though it might take some time (two weeks max I&apos;m hoping) before it propagates to a public release. At that point hopefully we can do some joint testing together to ensure people can actually use this. :-)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74176</commentid>
    <comment_count>5</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2008-03-17 15:21:40 -0700</bug_when>
    <thetext>&lt;rdar://problem/5803701&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80028</commentid>
    <comment_count>6</comment_count>
    <who name="Jeff Walden (remove +bwo to email)">jwalden+bwo</who>
    <bug_when>2008-05-09 15:58:13 -0700</bug_when>
    <thetext>Tests updated to latest spec, a second time since original posts.

Current failures I see, latest source:
- not throwing security exception accessing variable in other window (returning
  undefined, presumably); not inherently postMessage-related
- event.target is document (but target of dispatch is correctly window)
- some funkiness related to a closed-window test, not sure what&apos;s up with it
- you choke with a SYNTAX_ERR if targetOrigin is IDN
- you&apos;re using the value of document.domain for determining origin -- you
  should use the actual location
- data: URI origins not following HTML5 spec mean a test where a data: URI
  reaches into its parent ends up failing

The fifth is probably most important -- it&apos;s a spoofing concern for hosts which give out subdomains (although at least it isn&apos;t a two-way channel unless &quot;*&quot; is used with the response, rather only subdomain-&gt;other).  Fourth is next because it&apos;s not immediately obvious the failure would always be an exception thrown, and if it&apos;s a fail any way it&apos;ll be completely silent.  Second depends how smart code is at recognizing that, excepting listeners set across pages, .target === window -- I&apos;d bet it&apos;d be fairly rare.  The others are worth fixing but are either edge-case behavior or behavior that was one way but the spec now says do something else, so they&apos;re not super-duper important right now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80030</commentid>
    <comment_count>7</comment_count>
    <who name="Jeff Walden (remove +bwo to email)">jwalden+bwo</who>
    <bug_when>2008-05-09 16:02:04 -0700</bug_when>
    <thetext>Oh, forgot:
- something appears to truncate origins at the first null character, so
  &quot;http://lo\0k.com&quot; appears to be interpreted as &quot;http://lo&quot; (at the least, it
  doesn&apos;t throw)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80035</commentid>
    <comment_count>8</comment_count>
    <who name="Jeff Walden (remove +bwo to email)">jwalden+bwo</who>
    <bug_when>2008-05-09 16:06:16 -0700</bug_when>
    <thetext>(In reply to comment #6)
&gt; - you&apos;re using the value of document.domain for determining origin -- you
&gt;   should use the actual location
&gt; 
&gt; The fifth is probably most important -- it&apos;s a spoofing concern for hosts
&gt; which give out subdomains (although at least it isn&apos;t a two-way channel
&gt; unless &quot;*&quot; is used with the response, rather only subdomain-&gt;other).

On second thought, I have no reason to believe it&apos;s not two-way; I don&apos;t think I tested that in the tests, and my reason for believing it was pure mental rationalization.

(Last time I bugspam in this bug today, I promise!  :-) )</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80047</commentid>
    <comment_count>9</comment_count>
    <who name="Collin Jackson">collinj</who>
    <bug_when>2008-05-09 18:52:42 -0700</bug_when>
    <thetext>(In reply to comment #6)
&gt; - you&apos;re using the value of document.domain for determining origin -- you
&gt;   should use the actual location

I was not able to reproduce this issue on the latest nightly. I typed this sequence of commands into the JavaScript console:

&gt; document.domain = &quot;webkit.org&quot;;
&gt; addEventListener(&quot;message&quot;, function(e) { alert(e.origin); }, true);
&gt; postMessage(&quot;hi&quot;, &quot;*&quot;);

An alert pops up that says &quot;https://bugs.webkit.org/&quot; (not &quot;https://webkit.org&quot;, which would be wrong)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80049</commentid>
    <comment_count>10</comment_count>
    <who name="Jeff Walden (remove +bwo to email)">jwalden+bwo</who>
    <bug_when>2008-05-09 19:42:43 -0700</bug_when>
    <thetext>(In reply to comment #9)
&gt; I was not able to reproduce this issue on the latest nightly.

I think I was mistaken.  The first test that demonstrated this was succumbing to a previous error that snowballed and claimed to have received the wrong origin, but it was switching on a flawed .data property to determine it had received the wrong origin.  The second test is this one:

http://localhost:8888/tests/dom/tests/mochitest/whatwg/test_postMessage_onOther.html

The failure I get is:

not ok - unexpected origin got &quot;http://example.com&quot;, expected &quot;http://test1.example.com&quot;

Either what&apos;s happening here is that document.domain is being used or (more likely given your example) the method used to determine the origin of the caller doesn&apos;t know that when A.bar() calls B.baz(), where baz was defined inside a script included by B&apos;s document, and B.baz() then calls postMessage, the origin to use is B&apos;s origin (more precisely, the origin of baz()) and not the origin of A (more precisely, A.bar()).  I think I recall seeing the latter at one other time when I was comparing tests against another implementation, so I&apos;m betting the latter is the real problem.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80159</commentid>
    <comment_count>11</comment_count>
      <attachid>21077</attachid>
    <who name="Adam Barth">abarth</who>
    <bug_when>2008-05-12 00:32:12 -0700</bug_when>
    <thetext>Created attachment 21077
Use lexical scope

This is because we&apos;re in the middle of switching from using the dynamic scope for authorization to using the lexical scope.  I&apos;ve attached an (untested) patch that switches postMessage over to lexical scope.  I&apos;m not sure if this is correct vis-a-vis WindowShell.  I don&apos;t understand that code yet.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>176429</commentid>
    <comment_count>12</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2010-01-03 10:34:37 -0800</bug_when>
    <thetext>I don&apos;t think there is anything to do with this bug anymore.  The tests noted in the mailing list will not pass in WebKit due to spec changes and WebKit updating to match.  If there is an updated suite, please re-open the bug.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>21077</attachid>
            <date>2008-05-12 00:32:12 -0700</date>
            <delta_ts>2008-05-12 00:32:12 -0700</delta_ts>
            <desc>Use lexical scope</desc>
            <filename>lexical-post-message.patch</filename>
            <type>text/plain</type>
            <size>574</size>
            <attacher name="Adam Barth">abarth</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkNvcmUvYmluZGluZ3MvanMvSlNET01XaW5kb3dDdXN0b20uY3BwCj09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT0KLS0tIFdlYkNvcmUvYmluZGluZ3MvanMvSlNET01XaW5kb3dDdXN0b20uY3BwCShyZXZpc2lv
biAzMzAzOCkKKysrIFdlYkNvcmUvYmluZGluZ3MvanMvSlNET01XaW5kb3dDdXN0b20uY3BwCSh3
b3JraW5nIGNvcHkpCkBAIC0yMDQsNyArMjA0LDcgQEAgSlNWYWx1ZSogSlNET01XaW5kb3c6OnBv
c3RNZXNzYWdlKEV4ZWNTdAogewogICAgIERPTVdpbmRvdyogd2luZG93ID0gaW1wbCgpOwogCi0g
ICAgRE9NV2luZG93KiBzb3VyY2UgPSBhc0pTRE9NV2luZG93KGV4ZWMtPmR5bmFtaWNHbG9iYWxP
YmplY3QoKSktPmltcGwoKTsKKyAgICBET01XaW5kb3cqIHNvdXJjZSA9IGFzSlNET01XaW5kb3co
ZXhlYy0+bGV4aWNhbEdsb2JhbE9iamVjdCgpKS0+aW1wbCgpOwogICAgIFN0cmluZyBtZXNzYWdl
ID0gYXJnc1swXS0+dG9TdHJpbmcoZXhlYyk7CiAKICAgICBpZiAoZXhlYy0+aGFkRXhjZXB0aW9u
KCkpCg==
</data>

          </attachment>
      

    </bug>

</bugzilla>