-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COOP: test COOP popup from a CSP-sandboxed popup #21111
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9e1f466
COOP: test COOP popup from a CSP-sandboxed popup
zcorpan 3b3194a
Apply suggestions from code review
zcorpan a05e192
Remove get-host-info.sub.js from csp-sandbox.py
zcorpan 94da6ee
Use byte strings in python
zcorpan 32b2eef
Add a test per annevk's suggestion to navigate from CSP sandbox to CO…
zcorpan abbc0bd
Change fullyLoaded to a function
zcorpan 5d9eed6
Add more assertions in the navigate test (unsure about correctness)
zcorpan b2db19d
Avoid spaces in window.open second argument
zcorpan 36fc58a
Correct the same-origin check and add explanatory comments
zcorpan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
html/cross-origin-opener-policy/coop-csp-sandbox-navigate.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!doctype html> | ||
<title>CSP sandbox popup navigate to Cross-Origin-Opener-Policy document should work</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src="/common/utils.js"></script> <!-- Use token() to allow running tests in parallel --> | ||
<div id=log> | ||
<script> | ||
[ | ||
"allow-popups allow-scripts allow-same-origin", | ||
"allow-popups allow-scripts", | ||
].forEach(sandboxValue => { | ||
async_test(t => { | ||
const channel = new BroadcastChannel(token()); | ||
let popup; | ||
channel.onmessage = t.step_func_done(e => { | ||
assert_equals(e.data.name, '', 'e.data.name'); | ||
assert_false(e.data.opener, 'e.data.opener'); | ||
// `popup` is still the WindowProxy that holds the CSP sandbox document, not the | ||
// after-navigation COOP document. The CSP sandbox only applies to the before navigation | ||
// document/window. | ||
assert_true(popup.closed, 'popup.closed'); | ||
// Same-origin check (with the CSP sandbox document) should not throw when 'allow-same-origin' | ||
if (sandboxValue.includes('allow-same-origin')) { | ||
assert_true(!!popup.document, 'same-origin check'); | ||
} else { | ||
assert_throws_dom("SecurityError", () => { popup.document; }, 'same-origin check'); | ||
} | ||
}); | ||
const navigateTo = `/html/cross-origin-opener-policy/resources/coop-coep.py?coop=same-origin&coep=&channel=${channel.name}`; | ||
popup = window.open(`resources/csp-sandbox.py?coop=&coep=&sandbox=${sandboxValue}&channel=&navigate=${encodeURIComponent(navigateTo)}`, sandboxValue.replace(/ /g, '_')); | ||
t.add_cleanup(() => { popup.close(); }); | ||
addEventListener('load', t.step_func(() => { | ||
t.step_timeout(() => { | ||
assert_unreached('Navigation from CSP sandbox to COOP document failed') | ||
}, 1500); | ||
})); | ||
}, `CSP: sandbox ${sandboxValue}; ${document.title}`); | ||
}); | ||
</script> |
24 changes: 24 additions & 0 deletions
24
html/cross-origin-opener-policy/coop-csp-sandbox.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!doctype html> | ||
<title>CSP sandboxed Cross-Origin-Opener-Policy popup should result in a network error</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src="/common/utils.js"></script> <!-- Use token() to allow running tests in parallel --> | ||
<div id=log> | ||
<script> | ||
[ | ||
"allow-popups allow-scripts allow-same-origin", | ||
"allow-popups allow-scripts", | ||
].forEach(sandboxValue => { | ||
async_test(t => { | ||
const channel = new BroadcastChannel(token()); | ||
channel.onmessage = t.unreached_func("A COOP popup was created from a CSP-sandboxed popup"); | ||
const popup = window.open(`resources/csp-sandbox.py?coop=same-origin&coep=&sandbox=${sandboxValue}&channel=${channel.name}`); | ||
t.add_cleanup(() => { popup.close(); }); | ||
addEventListener('load', t.step_func(() => { | ||
t.step_timeout(() => { | ||
t.done() | ||
}, 1500); | ||
})); | ||
}, `CSP: sandbox ${sandboxValue}; ${document.title}`); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
def main(request, response): | ||
coop = request.GET.first(b"coop") | ||
coep = request.GET.first(b"coep") | ||
sandbox = request.GET.first(b"sandbox") | ||
if coop != "": | ||
response.headers.set(b"Cross-Origin-Opener-Policy", coop) | ||
if coep != "": | ||
response.headers.set(b"Cross-Origin-Embedder-Policy", coep) | ||
response.headers.set(b"Content-Security-Policy", b"sandbox " + sandbox + b";") | ||
|
||
# Open a popup to coop-coep.py with the same parameters (except sandbox) | ||
response.content = b""" | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<script src="/common/get-host-info.sub.js"></script> | ||
<script src="/html/cross-origin-opener-policy/resources/common.js"></script> | ||
<script> | ||
const params = new URL(location).searchParams; | ||
params.delete("sandbox"); | ||
const navigate = params.get("navigate"); | ||
if (navigate) { | ||
fullyLoaded().then(() => { | ||
self.location = navigate; | ||
}); | ||
} else { | ||
window.open(`/html/cross-origin-opener-policy/resources/coop-coep.py?${params}`); | ||
} | ||
</script> | ||
""" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you have a reference to the popup and it won't be replaced, can't you assert something about the popup? That it's not closed and that it's document is no longer same-origin? I guess that doesn't work for the case where allow-same-origin isn't set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But
closed
should be true after the navigation? The CSP sandbox doesn't have COOP, and then when navigating to the COOP document the browsing context is swapped.The "is no longer same origin" is interesting. Should it not be same-origin for any of these 2 cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I misread the test.