Skip to content

Commit

Permalink
"navigate-to" remaining work
Browse files Browse the repository at this point in the history
This patch includes:
The security violation event and CSP report are now sent to the correct
document via an interface ptr sent though the common params
Added 'unsafe-allowed-redirects' keyword tests
Bundled all CSP info into one InitiatorCSPInfo struct
Modified existing tests to test the violation event as well

Bug: 837627, 805886
Change-Id: I03124f29d4205ad4a5c2ac899b15f42e8e23659b
Reviewed-on: https://chromium-review.googlesource.com/c/1124476
Commit-Queue: Andy Paicu <andypaicu@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Reviewed-by: Mike West <mkwst@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#598336}
  • Loading branch information
andypaicu authored and chromium-wpt-export-bot committed Oct 10, 2018
1 parent 881c8c1 commit 50812d2
Show file tree
Hide file tree
Showing 35 changed files with 314 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<!DOCTYPE html>

<head>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>

<body>
<script>
var t = async_test("Test that the child can navigate the parent because the relevant policy belongs to the navigation initiator (in this case the child)");
var t = async_test("Test that the child can navigate the parent because the relevant policy belongs to the navigation initiator (in this case the child, which has the policy `navigate-to 'self'`)");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'success');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
</head>

<body>
<script>
var t = async_test("Test that the child can't navigate the parent because the relevant policy belongs to the navigation initiator (in this case the child which has the policy `navigate-to 'none'`)");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});
</script>
<iframe srcdoc="<iframe src='support/navigate_parent.sub.html?csp=navigate-to%20%27none%27&report_id={{$id:uuid()}}'>"></iframe>

<script async defer src='../support/checkReport.sub.js?reportField=violated-directive&reportValue=navigate-to%20%27none%27&reportID={{$id}}'></script>
</body>
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
assert_equals(e.data.result, 'success');
});
</script>
<iframe src="../support/form_action_navigation.sub.html?csp=navigate-to%20%27self%27%3B%20form-action%20%27self%27%3B&action=post_message_to_frame_owner.html">
<iframe src="../support/form_action_navigation.sub.html?csp=navigate-to%20%27self%27%3B%20form-action%20%27self%27%3B&action=post_message_to_frame_owner.html&report_id=dummy">
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
assert_equals(e.data.result, 'success');
});
</script>
<iframe src="../support/form_action_navigation.sub.html?csp=navigate-to%20%27none%27%3B%20form-action%20%27self%27%3B&action=post_message_to_frame_owner.html">
<iframe src="../support/form_action_navigation.sub.html?csp=navigate-to%20%27none%27%3B%20form-action%20%27self%27%3B&action=post_message_to_frame_owner.html&report_id=dummy">
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
assert_equals(e.data.violatedDirective, 'form-action');
});
</script>
<iframe src="../support/form_action_navigation.sub.html?csp=navigate-to%20%27self%27%3B%20form-action%20%27none%27%3B&action=post_message_to_frame_owner.html">
<iframe src="../support/form_action_navigation.sub.html?csp=navigate-to%20%27self%27%3B%20form-action%20%27none%27%3B&action=post_message_to_frame_owner.html&report_id=dummy">
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
assert_equals(e.data.violatedDirective, 'form-action');
});
</script>
<iframe src="../support/form_action_navigation.sub.html?csp=navigate-to%20%27none%27%3B%20form-action%20%27none%27%3B&action=post_message_to_frame_owner.html">
<iframe src="../support/form_action_navigation.sub.html?csp=navigate-to%20%27none%27%3B%20form-action%20%27none%27%3B&action=post_message_to_frame_owner.html&report_id=dummy">
</body>
7 changes: 7 additions & 0 deletions content-security-policy/navigate-to/form-blocked.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
</head>

<body>
<script>
var t = async_test("Test that the child iframe navigation is not allowed");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});
</script>
<iframe src="support/form_action_navigation.sub.html?csp=navigate-to%20%27none%27&report_id={{$id:uuid()}}&action=post_message_to_frame_owner.html"></iframe>

<script async defer src='../support/checkReport.sub.js?reportField=violated-directive&reportValue=navigate-to%20%27none%27&reportID={{$id}}'></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
</head>

<body>
<script>
var t = async_test("Test that the child iframe navigation is not allowed");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});
</script>
<iframe src="support/form_action_navigation.sub.html?csp=navigate-to%20%27self%27&report_id={{$id:uuid()}}&action=http%3A%2F%2F{{domains[www1]}}:{{ports[http][0]}}%2Fcontent-security-policy%2Fnavigate-to%2Fsupport%2Fpost_message_to_frame_owner.html"></iframe>

<script async defer src='../support/checkReport.sub.js?reportField=violated-directive&reportValue=navigate-to%20%27self%27&reportID={{$id}}'></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
</head>

<body>
<script>
var t = async_test("Test that the child iframe navigation is not allowed");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});
</script>

<iframe src="support/form_action_navigation.sub.html?csp=navigate-to%20%27self%27&report_id={{$id:uuid()}}&action=redirect_to_post_message_to_frame_owner.py%3Flocation%3Dhttp%3A%2F%2F{{domains[www1]}}%3A{{ports[http][0]}}%2Fcontent-security-policy%2Fnavigate-to%2Fsupport%2Fpost_message_to_frame_owner.html"></iframe>

<script async defer src='../support/checkReport.sub.js?reportField=violated-directive&reportValue=navigate-to%20%27self%27&reportID={{$id}}'></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

<body>
<script>
var t = async_test("Test that the child iframe navigation is not allowed");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});

window.open("support/href_location_navigation.sub.html?csp=navigate-to%20%27none%27&report_id={{$id:uuid()}}&target=post_message_to_frame_owner.html", "_blank");
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

<body>
<script>
var t = async_test("Test that the child iframe navigation is not allowed");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});

window.open("support/href_location_navigation.sub.html?csp=navigate-to%20%27self%27&report_id={{$id:uuid()}}&target=http%3A%2F%2F{{domains[www1]}}:{{ports[http][0]}}%2Fcontent-security-policy%2Fnavigate-to%2Fsupport%2Fpost_message_to_frame_owner.html", "_blank");
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

<body>
<script>
var t = async_test("Test that the child iframe navigation is not allowed");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});

window.open("support/href_location_navigation.sub.html?csp=navigate-to%20%27self%27&report_id={{$id:uuid()}}&target=redirect_to_post_message_to_frame_owner.py%3Flocation%3Dhttp%3A%2F%2F{{domains[www1]}}%3A{{ports[http][0]}}%2Fcontent-security-policy%2Fnavigate-to%2Fsupport%2Fpost_message_to_frame_owner.html", "_blank");
</script>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!DOCTYPE html>

<head>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
</head>

<body>
<script>
var t = async_test("Test that the child iframe navigation is not allowed");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});
</script>
<iframe src="support/link_click_navigation.sub.html?csp=navigate-to%20%27none%27&report_id={{$id:uuid()}}&target=post_message_to_frame_owner.html"></iframe>

<script async defer src='../support/checkReport.sub.js?reportField=violated-directive&reportValue=navigate-to%20%27none%27&reportID={{$id}}'></script>
<script async defer src='../support/checkReport.sub.js?reportField=violated-directive&reportValue=navigate-to%20%27self%27&reportID={{$id}}'></script>
</body>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!DOCTYPE html>

<head>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<!DOCTYPE html>

<head>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>

<body>
<script>
var t = async_test("Test that the child iframe navigation is not allowed");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});
</script>

<iframe src="support/link_click_navigation.sub.html?csp=navigate-to%20%27self%27&report_id={{$id:uuid()}}&target=http%3A%2F%2F{{domains[www1]}}:{{ports[http][0]}}%2Fcontent-security-policy%2Fnavigate-to%2Fsupport%2Fpost_message_to_frame_owner.html"></iframe>

<script async defer src='../support/checkReport.sub.js?reportField=violated-directive&reportValue=navigate-to%20%27self%27&reportID={{$id}}'></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!DOCTYPE html>

<head>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<!DOCTYPE html>

<head>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>

<body>
<script>
var t = async_test("Test that the child iframe navigation is not allowed");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});
</script>
<iframe src="support/link_click_navigation.sub.html?csp=navigate-to%20%27self%27&report_id={{$id:uuid()}}&target=redirect_to_post_message_to_frame_owner.py%3Flocation%3Dhttp%3A%2F%2F{{domains[www1]}}%3A{{ports[http][0]}}%2Fcontent-security-policy%2Fnavigate-to%2Fsupport%2Fpost_message_to_frame_owner.html"></iframe>

<script async defer src='../support/checkReport.sub.js?reportField=violated-directive&reportValue=navigate-to%20%27self%27&reportID={{$id}}'></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
</head>

<body>
<script>
var t = async_test("Test that the child iframe navigation is not allowed");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});
</script>

<iframe src="support/meta_refresh_navigation.sub.html?csp=navigate-to%20%27none%27&report_id={{$id:uuid()}}&target=post_message_to_frame_owner.html"></iframe>

<script async defer src='../support/checkReport.sub.js?reportField=violated-directive&reportValue=navigate-to%20%27none%27&reportID={{$id}}'></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
</head>

<body>
<script>
var t = async_test("Test that the child iframe navigation is not allowed");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});
</script>

<iframe src="support/meta_refresh_navigation.sub.html?csp=navigate-to%20%27self%27&report_id={{$id:uuid()}}&target=http%3A%2F%2F{{domains[www1]}}:{{ports[http][0]}}%2Fcontent-security-policy%2Fnavigate-to%2Fsupport%2Fpost_message_to_frame_owner.html"></iframe>

<script async defer src='../support/checkReport.sub.js?reportField=violated-directive&reportValue=navigate-to%20%27self%27&reportID={{$id}}'></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
</head>

<body>
<script>
var t = async_test("Test that the child iframe navigation is not allowed");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'fail');
assert_equals(e.data.violatedDirective, 'navigate-to');
});
</script>

<iframe src="support/meta_refresh_navigation.sub.html?csp=navigate-to%20%27self%27&report_id={{$id:uuid()}}&target=redirect_to_post_message_to_frame_owner.py%3Flocation%3Dhttp%3A%2F%2F{{domains[www1]}}%3A{{ports[http][0]}}%2Fcontent-security-policy%2Fnavigate-to%2Fsupport%2Fpost_message_to_frame_owner.html"></iframe>

<script async defer src='../support/checkReport.sub.js?reportField=violated-directive&reportValue=navigate-to%20%27self%27&reportID={{$id}}'></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<body>
<script>
var t = async_test("Test that the parent can navigate the child because the relevant policy belongs to the navigation initiator (in this case the parent)");
var t = async_test("Test that the parent can navigate the child because the relevant policy belongs to the navigation initiator (in this case the parent, which has the policy `navigate-to 'self'`)");
window.onmessage = t.step_func_done(function(e) {
assert_equals(e.data.result, 'success');
});
Expand All @@ -23,4 +23,4 @@
i.src = "support/wait_for_navigation.html?csp=navigate-to%20%none%27";
document.body.appendChild(i);
</script>
</body>
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

<body>
<script>
var t = async_test("Test that the parent can't navigate the child because the relevant policy belongs to the navigation initiator (in this case the parent, which has the policy `navigate-to support/wait_for_navigation.html;`)");
window.onmessage = t.unreached_func("Should not have received a message as the navigation should not have been successful");
window.addEventListener('securitypolicyviolation', t.step_func_done(function(e) {
assert_equals(e.violatedDirective, 'navigate-to');
}));

var i = document.createElement('iframe');
var src_changed = false;
i.onload = function() {
Expand All @@ -17,5 +23,6 @@
i.src = "support/wait_for_navigation.html?csp=navigate-to%20%27self%27";
document.body.appendChild(i);
</script>

<script async defer src='../support/checkReport.sub.js?reportField=violated-directive&reportValue=navigate-to%20support%2Fwait_for_navigation.html'></script>
</body>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>

<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<!-- This tests that a navigation initiator that has been replaced by the time
the navigation it initiates is blocked, will not receive the SPV event.
An iframe will navigate another iframe and the navigate itself.
The second iframe's navigation response will be delayed by the server but will
eventually be blocked by the CSP of the first iframe.
By the time this happens the first iframe should be an entirely different
document and it should not receive a SPV event -->
<script>
var t = async_test("Test that no spv event is raised");
window.onmessage = t.step_func(function(e) {
if (e.data == "end_test") t.done();
else assert_unreached("Should not have raised a spv event");
});

var frames_loaded_count = 0;
var frame_loaded = function() {
if (++frames_loaded_count == 2) {
// both child frame have loaded we can start the
// test now, send a message to iframe1 so it knows to start
document.getElementById('iframe1').contentWindow.postMessage('start_test', '*');
}
}
var i1 = document.createElement('iframe');
i1.src = "support/spv-test-iframe1.sub.html?report_id={{$id:uuid()}}";
i1.id = "iframe1";
i1.name = "iframe1";
i1.onload = frame_loaded;
document.body.appendChild(i1);

var i2 = document.createElement('iframe');
i2.src = "support/spv-test-iframe2.sub.html";
i2.id = "iframe2";
i2.name = "iframe2";
i2.onload = frame_loaded;
document.body.appendChild(i2);
</script>

<script async defer src='../support/checkReport.sub.js?reportExists=false&reportID={{$id}}'></script>

</body>
12 changes: 12 additions & 0 deletions content-security-policy/navigate-to/support/delayed_frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import time
def main(request, response):
time.sleep(1)
headers = [("Content-Type", "text/html")]
return headers, '''
<!DOCTYPE html>
<head>
</head>
<body>
DELAYED FRAME
</body
'''
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

<body>
<script>
window.addEventListener('securitypolicyviolation', function(e) {
opener.postMessage({result: 'fail', violatedDirective: e.violatedDirective}, '*');
});

try {
location.href = "{{GET[target]}}";
} catch(ex) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<body>
<a href="{{GET[target]}}" id="link">dummy link</a>
<script>
window.addEventListener('securitypolicyviolation', function(e) {
top.postMessage({result: 'fail', violatedDirective: e.violatedDirective}, '*');
});

document.getElementById('link').click();
</script>
</body>
Loading

0 comments on commit 50812d2

Please sign in to comment.