<?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>155710</bug_id>
          <alias>CVE-2016-4758</alias>
          <creation_ts>2016-03-20 21:27:10 -0700</creation_ts>
          <short_desc>showModalDialog code runs with “first window” set to wrong window</short_desc>
          <delta_ts>2017-10-11 10:26:32 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>Safari 8</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Critical</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Darin Adler">darin</reporter>
          <assigned_to name="Darin Adler">darin</assigned_to>
          <cc>andersca</cc>
    
    <cc>beidson</cc>
    
    <cc>bfulgham</cc>
    
    <cc>ddkilzer</cc>
    
    <cc>ggaren</cc>
    
    <cc>sam</cc>
    
    <cc>wilander</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1176665</commentid>
    <comment_count>0</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2016-03-20 21:27:10 -0700</bug_when>
    <thetext>Code inside showModalDialog runs with an incorrect &quot;first window&quot;, which can lead to security vulnerability. I have a patch for this, but a regression test is trickier to create.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1176666</commentid>
    <comment_count>1</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2016-03-20 21:29:31 -0700</bug_when>
    <thetext>&lt;rdar://problem/21449949&gt;

Could use advice both on creating a regression test and on possible more-elegant ways to fix this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1176668</commentid>
    <comment_count>2</comment_count>
      <attachid>274574</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2016-03-20 21:32:47 -0700</bug_when>
    <thetext>Created attachment 274574
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1176669</commentid>
    <comment_count>3</comment_count>
      <attachid>274575</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2016-03-20 21:33:58 -0700</bug_when>
    <thetext>Created attachment 274575
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1176754</commentid>
    <comment_count>4</comment_count>
      <attachid>274575</attachid>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2016-03-21 09:38:49 -0700</bug_when>
    <thetext>Comment on attachment 274575
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=274575&amp;action=review

No insight into writing a test yet.

&gt; Source/WebCore/ChangeLog:3
&gt; +        showModalDialog code runs with âfirst windowâ set to wrong window

Fancy quotes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1176793</commentid>
    <comment_count>5</comment_count>
      <attachid>274575</attachid>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2016-03-21 11:26:17 -0700</bug_when>
    <thetext>Comment on attachment 274575
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=274575&amp;action=review

I think this change looks good, though the comment about the JSC context makes me wonder if we need to tighten the lifetime of the nullptr JSC scope. Otherwise, I think this change is good. I&apos;ve asked John W. to help us create a test. Perhaps we could land that test in a separate commit?

&gt; Source/WebCore/page/Chrome.cpp:227
&gt; +

Your comment here makes it seem like we want the JSC context for &apos;fireTimersInNestedEventLoop&apos; to be different than the script code for this modal dialog. However, as written we get a new scope for the timers, and this same scope is used for &apos;runModal&apos;. It&apos;s quite likely that you did mean for it to work this way, but if so I think the comment might be misleading.

If not, we should control the scope of the new JSC context so that we &quot;pop&quot; back to the original JSC when invoking runModal.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1176797</commentid>
    <comment_count>6</comment_count>
      <attachid>274575</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2016-03-21 11:39:46 -0700</bug_when>
    <thetext>Comment on attachment 274575
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=274575&amp;action=review

&gt;&gt; Source/WebCore/ChangeLog:3
&gt;&gt; +        showModalDialog code runs with âfirst windowâ set to wrong window
&gt; 
&gt; Fancy quotes.

Fancy quotes are bad in our review tool, but are they bad in ChangeLog?

&gt;&gt; Source/WebCore/page/Chrome.cpp:227
&gt;&gt; +
&gt; 
&gt; Your comment here makes it seem like we want the JSC context for &apos;fireTimersInNestedEventLoop&apos; to be different than the script code for this modal dialog. However, as written we get a new scope for the timers, and this same scope is used for &apos;runModal&apos;. It&apos;s quite likely that you did mean for it to work this way, but if so I think the comment might be misleading.
&gt; 
&gt; If not, we should control the scope of the new JSC context so that we &quot;pop&quot; back to the original JSC when invoking runModal.

JavaScript context has no effect on fireTimersInNestedEventLoop and it doesn’t matter if we do this work before or after calling fireTimersInNestedEventLoop. The name fireTimersInNestedEventLoop might sound like is a function that could execute some JavaScript, but it could not. Calling that function makes sure that run loop timers fire, inside the run loop, instead of waiting for an exit of the outer run loop.

All three of the setup steps—PageGroupLoadDeferrer, entryScope, fireTimersInNestedEventLoop—could be done in any order. There are no dependencies between them.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1177268</commentid>
    <comment_count>7</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2016-03-22 21:16:45 -0700</bug_when>
    <thetext>Committed r198575: &lt;http://trac.webkit.org/changeset/198575&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1177274</commentid>
    <comment_count>8</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2016-03-22 21:25:40 -0700</bug_when>
    <thetext>Thank you for fixing this, Darin!</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>274574</attachid>
            <date>2016-03-20 21:32:47 -0700</date>
            <delta_ts>2016-03-20 21:33:55 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-155710-20160320213247.patch</filename>
            <type>text/plain</type>
            <size>1933</size>
            <attacher name="Darin Adler">darin</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTk4NDgwCmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggMjU3ZjJjOTZlMTc0YmU2
MWE1MTQzMGRiNWQ4NTQzYTc3OGM1ZjI1Ni4uYTVkYWIwNDZkMTBiYzUyNjgwY2YzOWZmZDExOGEw
NTFiZjEzM2ZkZCAxMDA2NDQKLS0tIGEvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCisrKyBiL1Nv
dXJjZS9XZWJDb3JlL0NoYW5nZUxvZwpAQCAtMSwzICsxLDE1IEBACisyMDE2LTAzLTIwICBEYXJp
biBBZGxlciAgPGRhcmluQGFwcGxlLmNvbT4KKworICAgICAgICBzaG93TW9kYWxEaWFsb2cgY29k
ZSBydW5zIHdpdGgg4oCcZmlyc3Qgd2luZG934oCdIHNldCB0byB3cm9uZyB3aW5kb3cKKyAgICAg
ICAgaHR0cHM6Ly9idWdzLndlYmtpdC5vcmcvc2hvd19idWcuY2dpP2lkPTE1NTcxMAorCisgICAg
ICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAgICogcGFnZS9DaHJvbWUu
Y3BwOgorICAgICAgICAoV2ViQ29yZTo6Q2hyb21lOjpydW5Nb2RhbCk6IE51bGwgb3V0IGVudHJ5
U2NvcGUgc28gdGhhdCB0aGUgImZpcnN0IHdpbmRvdyIKKyAgICAgICAgY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AKQEAgLTIxOSw2ICsyMjEsMTAgQEAgdm9pZCBDaHJvbWU6
OnJ1bk1vZGFsKCkgY29uc3QKICAgICAvLyBpbiBhIHdheSB0aGF0IGNvdWxkIGludGVyYWN0IHdp
dGggdGhpcyB2aWV3LgogICAgIFBhZ2VHcm91cExvYWREZWZlcnJlciBkZWZlcnJlcihtX3BhZ2Us
IGZhbHNlKTsKIAorICAgIC8vIEphdmFTY3JpcHQgdGhhdCBydW5zIHdpdGhpbiB0aGUgbmVzdGVk
IGV2ZW50IGxvb3Agc2hvdWxkIGJlIHJ1biBpbiB0aGUgY29udGV4dCBvZiB0aGUKKyAgICAvLyBz
Y3JpcHQgdGhhdCBjYWxsZWQgc2hvd01vZGFsRGlhbG9nLiBOdWxsIG91dCBlbnRyeVNjb3BlIHRv
IGJyZWFrIHRoZSBjb25uZWN0aW9uLgorICAgIFRlbXBvcmFyeUNoYW5nZTxKU0M6OlZNRW50cnlT
Y29wZSo+IGVudHJ5U2NvcGVOdWxsaWZpZXIgeyBtX3BhZ2UubWFpbkZyYW1lKCkuZG9jdW1lbnQo
KS0+dm0oKS5lbnRyeVNjb3BlLCBudWxscHRyIH07CisKICAgICBUaW1lckJhc2U6OmZpcmVUaW1l
cnNJbk5lc3RlZEV2ZW50TG9vcCgpOwogICAgIG1fY2xpZW50LnJ1bk1vZGFsKCk7CiB9Cg==
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>274575</attachid>
            <date>2016-03-20 21:33:58 -0700</date>
            <delta_ts>2016-03-21 11:26:17 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-155710-20160320213358.patch</filename>
            <type>text/plain</type>
            <size>1935</size>
            <attacher name="Darin Adler">darin</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTk4NDgwCmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29y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dCB0aGF0IGNhbGxlZCBzaG93TW9kYWxEaWFsb2cuIE51bGwgb3V0IGVudHJ5U2NvcGUg
dG8gYnJlYWsgdGhlIGNvbm5lY3Rpb24uCisgICAgVGVtcG9yYXJ5Q2hhbmdlPEpTQzo6Vk1FbnRy
eVNjb3BlKj4gZW50cnlTY29wZU51bGxpZmllciB7IG1fcGFnZS5tYWluRnJhbWUoKS5kb2N1bWVu
dCgpLT52bSgpLmVudHJ5U2NvcGUsIG51bGxwdHIgfTsKKwogICAgIFRpbWVyQmFzZTo6ZmlyZVRp
bWVyc0luTmVzdGVkRXZlbnRMb29wKCk7CiAgICAgbV9jbGllbnQucnVuTW9kYWwoKTsKIH0K
</data>
<flag name="review"
          id="298995"
          type_id="1"
          status="+"
          setter="bfulgham"
    />
          </attachment>
      

    </bug>

</bugzilla>