access-control-sandboxed-iframe-denied-without-wildcard.htm (1697B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Tests that sandboxed iframe does not have CORS XHR access to server with "Access-Control-Allow-Origin" set to the original origin</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/common/get-host-info.sub.js"></script> 8 </head> 9 <body> 10 <script type="text/javascript"> 11 const path = "/xhr/resources/pass.txt?pipe=" + 12 "header(Cache-Control,no-store)|" + 13 "header(Content-Type,text/plain)" + 14 "header(Access-Control-Allow-Credentials,true)|" + 15 "header(Access-Control-Allow-Origin," + get_host_info().HTTP_ORIGIN + ")"; 16 17 async_test((test) => { 18 const xhr = new XMLHttpRequest; 19 xhr.open("GET", get_host_info().HTTP_REMOTE_ORIGIN + path); 20 xhr.send(); 21 xhr.onerror = test.unreached_func("Unexpected error"); 22 xhr.onload = test.step_func_done(() => { 23 assert_equals(xhr.status, 200); 24 assert_equals(xhr.responseText.trim(), "PASS"); 25 }); 26 }, "Check that path exists and is accessible via CORS XHR request"); 27 28 async_test((test) => { 29 window.addEventListener("message", test.step_func((evt) => { 30 if (evt.data === "ready") { 31 document.getElementById("frame").contentWindow.postMessage( 32 get_host_info().HTTP_REMOTE_ORIGIN + path, "*"); 33 } else { 34 assert_equals(evt.data, "Exception thrown. Sandboxed iframe XHR access was denied in 'send'."); 35 test.done(); 36 } 37 }), false); 38 }, "Sandboxed iframe is denied CORS access to server that allows parent origin"); 39 </script> 40 <iframe id="frame" sandbox="allow-scripts" src="/xhr/resources/access-control-sandboxed-iframe.html"> 41 </iframe> 42 </body> 43 </html>