Skip to content

Commit fb9ece2

Browse files
arichivchromium-wpt-export-bot
authored andcommitted
[CSP] WPTs for matching edge cases
We don't allow url encoded hosts but do permit ports with leading 0s. w3c/webappsec-csp#597 w3c/webappsec-csp#596 Bug: 1418009 Change-Id: Ie8ddc509b63e1aa9d35d4e2b989df63483bfca6a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4454670 Reviewed-by: Dustin Mitchell <[email protected]> Commit-Queue: Ari Chivukula <[email protected]> Cr-Commit-Position: refs/heads/main@{#1134816}
1 parent 30fd4be commit fb9ece2

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Security-Policy" content="base-uri {{location[scheme]}}://{{domains[www1]}}:0{{ports[http][0]}}/">
5+
<script src='/resources/testharness.js'></script>
6+
<script src='/resources/testharnessreport.js'></script>
7+
8+
<script>
9+
var t = async_test("Check that base URIs can be set if they do not violate the page's policy because leading 0s are stripped from the port.");
10+
window.addEventListener('securitypolicyviolation', t.step_func(function(t) {
11+
assert_unreached('No CSP violation report should have been fired.');
12+
}));
13+
</script>
14+
15+
<base href="{{location[scheme]}}://{{domains[www1]}}:{{ports[http][0]}}/">
16+
<script>
17+
t.step(function() {
18+
assert_equals(document.baseURI, "{{location[scheme]}}://{{domains[www1]}}:{{ports[http][0]}}/");
19+
t.done();
20+
});
21+
</script>
22+
</head>
23+
<body>
24+
</html>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Security-Policy" content="base-uri {{location[scheme]}}://www1%2E{{domains[]}}:{{ports[http][0]}}/">
5+
<script src='/resources/testharness.js'></script>
6+
<script src='/resources/testharnessreport.js'></script>
7+
8+
<script>
9+
var t = async_test("Check that baseURI fires a securitypolicyviolation event when it does not match the csp directive due to a url encoded host character.");
10+
window.addEventListener('securitypolicyviolation', t.step_func_done(function(e) {
11+
assert_equals(e.blockedURI, "{{location[scheme]}}://{{domains[www2]}}:{{ports[http][0]}}/")
12+
assert_equals(e.violatedDirective, "base-uri");
13+
}));
14+
</script>
15+
16+
<base href="{{location[scheme]}}://{{domains[www2]}}:{{ports[http][0]}}/">
17+
<script>
18+
test(function() {
19+
assert_equals(document.baseURI, window.location.href);
20+
t.done();
21+
}, "Check that the baseURI is not set when it does not match the csp directive");
22+
</script>
23+
</head>
24+
<body>
25+
</html>

0 commit comments

Comments
 (0)