<?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>209653</bug_id>
          
          <creation_ts>2020-03-27 09:01:20 -0700</creation_ts>
          <short_desc>events from sandboxed iframe (allow-same-origin) not firing</short_desc>
          <delta_ts>2026-01-12 09:09:15 -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>DOM</component>
          <version>Safari 13</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=215589</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>frisou76</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>ap</cc>
    
    <cc>bfulgham</cc>
    
    <cc>cdumez</cc>
    
    <cc>graouts</cc>
    
    <cc>handtrix</cc>
    
    <cc>matb</cc>
    
    <cc>me</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1634815</commentid>
    <comment_count>0</comment_count>
    <who name="">frisou76</who>
    <bug_when>2020-03-27 09:01:20 -0700</bug_when>
    <thetext>Hi.

Version:
- tested on gnome web (13.0 / ubuntu 18.04 x86_64)
- tested on virtual safari 13.0.2 (via browser stack)

Description:
Sandboxed iframe with parameter sandbox=&quot;allow-same-origin&quot; does not fire events (any kind: onload, onclick,...), and message &quot;Blocked script execution in &apos;...&apos; because the document&apos;s frame is sandboxed and the &apos;allow-scripts&apos; permission is not set.&quot; is displayed in console.

Awaited:
Scripts inside the iframe must not be executed, but parent script functions attached to iframe content events should be executed, since they are trusted.

Other browsers:
Works in Firefox, Chromium, IE, Edge


Steps to reproduce:
1) Create an iframe by script with parameter sandbox=&quot;allow-same-origin&quot;
2) Populate iframe by script with untrusted content
3) Attach iframe event like onload / onreadystatechange / onclick to a function

Code sample:

&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;script&gt;
  var iframe = document.createElement(&apos;iframe&apos;);
  iframe.setAttribute(&apos;sandbox&apos;, &apos;allow-same-origin allow-modals&apos;); //allow-modals is set because we use alert in button.onclick function that, however, shall not be launched
  iframe.style.width = iframe.style.height = &quot;100%&quot;;
  document.body.appendChild(iframe);
  var idocument = iframe.contentWindow.document;
  
  var onready = idocument.onreadystatechange = function(){
    if (idocument.readyState == &apos;complete&apos;) {
      idocument.querySelector(&apos;button&apos;).addEventListener(&apos;click&apos;, function(ev){
        alert(&apos;This script is trusted :-)&apos;);
      }, false)
    }
  }

  idocument.write(&apos;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;button onclick=&quot;alert(\&apos;This script is UNTRUSTED :-(\&apos;)&quot;&gt;click Me&lt;/button&gt;&lt;/body&gt;&apos;);
  try{
    idocument.close()
  }catch(er){
  }
  
  // as a first workaround for webkit, let&apos;s set up a loop to check readyState
  function checkComplete(){
    if (idocument.readyState != &apos;complete&apos;)
      return setTimeout(checkComplete, 100);
    onready();
  }
  checkComplete();
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;


Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1635053</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-03-27 16:50:33 -0700</bug_when>
    <thetext>&lt;rdar://problem/60990768&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1894524</commentid>
    <comment_count>2</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2022-08-29 07:26:07 -0700</bug_when>
    <thetext>I am able to reproduce this bug in Safari Technology Preview 152 on macOS 12.5.1 using test case from Comment 01 turned into JSFiddle:

Link - https://jsfiddle.net/yp7fxow8/

When I click &quot;Click Me&quot;, it does not show anything while in case of other browsers (Chrome Canary 107 and Firefox Nightly 106), it shows &quot;This script is trusted :-)&quot;.

Just wanted to share updated testing results. Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1918519</commentid>
    <comment_count>3</comment_count>
    <who name="Henrik Wenz">handtrix</who>
    <bug_when>2022-12-12 09:58:13 -0800</bug_when>
    <thetext>The issue is still present in Safari Release 159 (Safari 16.4, WebKit 18615.1.12.130.1) 😢</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>