Skip to content
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

Add tests regarding navigation inside sandboxed iframes. #6221

Merged
merged 5 commits into from
Jun 21, 2017

Conversation

fred-wang
Copy link
Contributor

@fred-wang fred-wang commented Jun 13, 2017

This commit adds basic tests for frame navigation to verify some cases handled by Chromium, that I'm trying to implement in WebKit [1] [2]. cc'ing @mikewest @RByers @japhet who have worked on this. Also cc'ing @cdumez and @bzbarsky for WebKit & Mozilla.

[1] https://cs.chromium.org/chromium/src/third_party/WebKit/Source/core/frame/LocalFrame.cpp?type=cs&q=LocalFrame::CanNavigateWithoutFramebusting
[2] https://bugs.webkit.org/show_bug.cgi?id=173162

@fred-wang fred-wang requested review from mikewest and removed request for jdm, zcorpan, jgraham, ayg and zqzhang June 13, 2017 09:31
@fred-wang
Copy link
Contributor Author

cc'ing @natechapin too.

@ghost
Copy link

ghost commented Jun 13, 2017

View the complete job log.

Firefox (nightly)

Testing web-platform-tests at revision 813c23d
Using browser at version BuildID 20170612100241; SourceStamp 27cad9749cddf68e11fdd4e5d73dad84a8f8cf23
Starting 10 test iterations
All results were stable

All results

6 tests ran
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-1.html
Subtest Results Messages
TIMEOUT
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-2.html
Subtest Results Messages
TIMEOUT
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-1.html
Subtest Results Messages
OK
Check that sandboxed iframe can not navigate their ancestors PASS
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-2.html
Subtest Results Messages
OK
Check that unsandboxed iframe can navigate their ancestors PASS
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_descendants.html
Subtest Results Messages
OK
Check that sandboxed iframe can navigate their descendants PASS
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_itself.html
Subtest Results Messages
OK
Check that sandboxed iframe can navigate itself PASS

@ghost
Copy link

ghost commented Jun 13, 2017

View the complete job log.

Sauce (safari)

Testing web-platform-tests at revision 813c23d
Using browser at version 10.0
Starting 10 test iterations
All results were stable

All results

6 tests ran
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-1.html
Subtest Results Messages
TIMEOUT
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-2.html
Subtest Results Messages
TIMEOUT
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-1.html
Subtest Results Messages
TIMEOUT
Check that sandboxed iframe can not navigate their ancestors NOTRUN
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-2.html
Subtest Results Messages
OK
Check that unsandboxed iframe can navigate their ancestors PASS
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_descendants.html
Subtest Results Messages
OK
Check that sandboxed iframe can navigate their descendants PASS
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_itself.html
Subtest Results Messages
OK
Check that sandboxed iframe can navigate itself PASS

@ghost
Copy link

ghost commented Jun 13, 2017

View the complete job log.

Chrome (unstable)

Testing web-platform-tests at revision 813c23d
Using browser at version 61.0.3135.4 dev
Starting 10 test iterations

@ghost
Copy link

ghost commented Jun 13, 2017

View the complete job log.

Sauce (MicrosoftEdge)

Testing web-platform-tests at revision 813c23d
Using browser at version 14.14393
Starting 10 test iterations
All results were stable

All results

6 tests ran
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-1.html
Subtest Results Messages
TIMEOUT
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-2.html
Subtest Results Messages
TIMEOUT
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-1.html
Subtest Results Messages
TIMEOUT
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-2.html
Subtest Results Messages
OK
Check that unsandboxed iframe can navigate their ancestors PASS
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_descendants.html
Subtest Results Messages
OK
Check that sandboxed iframe can navigate their descendants PASS
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_itself.html
Subtest Results Messages
OK
Check that sandboxed iframe can navigate itself PASS

@fred-wang
Copy link
Contributor Author

Note: I modified the test for allow-top-navigation to make it more reliable. If needed, we can add a similar test to check that top navigation is blocked when allow-top-navigation is unset, however this is already done by iframe_sandbox_allow_top_navigation_by_user_activation_without_user_gesture.html

opener.postMessage({data: e.data, origin: e.origin}, "*")
window.close();
}
document.querySelector("iframe").src = "support/iframe-that-performs-top-navigation-without-user-gesture-passed.html";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the timing here's not going to work. The frame loads iframe-that-performs-top-navigation-without-user-gesture-passed.html, which navigates the page containing the frame. Depending on when that navigation fires, there might or might not actually be a message handler to postMessage() up to the opener.

// trying to modifying the top frame and transmit the result to our
// opener.
onmessage = function(e) {
opener.postMessage({data: e.data, origin: e.origin}, "*")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why pass the origin if you're not using it in the check on line 27?

assert_equals(e.data.data, "PASS", "Should have the right message");
});
var popupWin = window.open();
popupWin.location.href = location.href;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny style nit: I'd write this as:

async_test(t => {
  window.addEventListener('message', t.step_func_done(e => {
    assert_equals(e.data.data, "PASS");
    e.source.close();
  }));
  window.open(location.href);
}, "Frames with `allow-top-navigation` should be able to navigate the top frame.");

Closing the window helps clean things up when you're running the test manually, and I don't think you need the extra t or popupWin variables.

…check that navigation is not allowed when the flag is absent.
@fred-wang
Copy link
Contributor Author

@mikewest Thanks. I pushed another commit that hopefully fixes your concern. I finally also added a similar test when allow-top-navigation is unset.

@fred-wang
Copy link
Contributor Author

@mikewest ¿review ping?

Copy link
Member

@mikewest mikewest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % two small style nits.

<body>
<script>
window.onload = function()
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: The brace is on the same line with the function definition in all the other files. Let's move it up here as well.

<script>
window.onload = function()
{
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: Indentation.

@fred-wang fred-wang merged commit 2fbf393 into master Jun 21, 2017
@fred-wang fred-wang deleted the iframe-navigation branch June 21, 2017 14:45
@fred-wang
Copy link
Contributor Author

@mikewest thanks!

hubot pushed a commit to WebKit/WebKit-http that referenced this pull request Jun 21, 2017
https://bugs.webkit.org/show_bug.cgi?id=173649

Patch by Frederic Wang <[email protected]> on 2017-06-21
Reviewed by Youenn Fablet.

This import new tests added in web-platform-tests/wpt#6221 to verify
sandboxing of iframes and will help to test the changes in bug 173162.

* resources/import-expectations.json:
* resources/resource-files.json:
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/content_document_changes_only_after_load_matures-expected.txt: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/content_document_changes_only_after_load_matures.html: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-1-expected.txt: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-1.html: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-2-expected.txt: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_allow_top_navigation-2.html: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-1-expected.txt: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-1.html: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-2-expected.txt: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-2.html: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_descendants-expected.txt: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_descendants.html: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_itself-expected.txt: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_itself.html: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/support/iframe-that-performs-top-navigation-on-popup.html: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/support/iframe-that-tries-to-navigate-parent-and-sends-result-to-grandparent.html: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/support/iframe-tried-to-be-navigated-by-its-child.html: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/support/iframe-trying-to-navigate-its-child.html: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/support/iframe-trying-to-navigate-itself.html: Added.
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/support/w3c-import.log:
* web-platform-tests/html/semantics/embedded-content/the-iframe-element/w3c-import.log:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@218639 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants