javascript-url-security-check-multi-globals.sub.html (2564B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Multi-globals: which one is the initiator for the javascript: URL security check?</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 7 <body> 8 <script> 9 "use strict"; 10 document.domain = "{{hosts[][]}}"; 11 12 // These tests would fail if a different pair of origins were compared (see, e.g., the discussion in 13 // https://github.com/whatwg/html/issues/6514). 14 15 promise_test(async t => { 16 const iframe = await insertIframe(t); 17 const innerIframe = iframe.contentDocument.querySelector("iframe"); 18 19 // - incumbentNavigationOrigin = this page's origin, http://{{hosts[][]}}:{{ports[http][0]}} 20 // - iframe's current origin is this origin, http://{{hosts[][]}}:{{ports[http][0]}}. 21 // javascript:'s security check uses incumbentNavigationOrigin vs. the iframe's current origin 22 // so the check will pass and the result will get written. 23 innerIframe.src = "javascript:'test'"; 24 25 await waitForLoad(innerIframe, "Failed to load the javascript: URL"); 26 27 assert_equals(innerIframe.contentDocument.body.textContent, "test"); 28 }, "Using iframeEl.src"); 29 30 promise_test(async t => { 31 const iframe = await insertIframe(t); 32 const innerIframe = iframe.contentDocument.querySelector("iframe"); 33 34 // Here, https://html.spec.whatwg.org/#location-object-navigate sets the source browsing context to the 35 // incumbent settings object's browsing context. So incumbentNavigationOrigin = this page's origin, 36 // http://{{hosts[][]}}:{{ports[http][0]}}. 37 // 38 // So again, the check will pass. 39 40 iframe.contentWindow.frames[0].location.href = "javascript:'test'"; 41 42 await waitForLoad(innerIframe, "Failed to load the javascript: URL"); 43 44 assert_equals(innerIframe.contentDocument.body.textContent, "test"); 45 }, "Using location.href"); 46 47 function insertIframe(t) { 48 return new Promise((resolve, reject) => { 49 const iframe = document.createElement("iframe"); 50 iframe.src = "http://{{hosts[][www]}}:{{ports[http][0]}}/html/browsers/browsing-the-web/navigating-across-documents/resources/multi-globals-subframe-1.sub.html"; 51 iframe.onload = () => resolve(iframe); 52 iframe.onerror = () => reject(new Error("Failed to load the outer iframe")); 53 54 t.add_cleanup(() => iframe.remove()); 55 56 document.body.append(iframe); 57 }); 58 } 59 60 function waitForLoad(iframe, errorMessage = "Failed to load iframe") { 61 return new Promise((resolve, reject) => { 62 iframe.onload = () => resolve(iframe); 63 iframe.onerror = () => reject(new Error(errorMessage)); 64 }); 65 } 66 </script>