blob: a703a922e273447a19efd4fd72f606e35fcd62ff [file] [log] [blame]
Austin James Ahlstrom9543eaf2017-09-12 09:19:431<!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">
Philip Jägenstedt2cb86af2018-01-06 16:35:2711const path = "/xhr/resources/pass.txt?pipe=" +
Austin James Ahlstrom9543eaf2017-09-12 09:19:4312 "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
17async_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
28async_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>
Philip Jägenstedt2cb86af2018-01-06 16:35:2740 <iframe id="frame" sandbox="allow-scripts" src="/xhr/resources/access-control-sandboxed-iframe.html">
Austin James Ahlstrom9543eaf2017-09-12 09:19:4341 </iframe>
42 </body>
43</html>