Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(694)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_browsertest.cc

Issue 1868823002: Fix cross-site popups to inherit their opener's sandbox flags even when popup opener is not set (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/renderer/render_view_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 2530 matching lines...) Expand 10 before | Expand all | Expand 10 after
2541 EXPECT_FALSE( 2541 EXPECT_FALSE(
2542 web_contents->GetRenderManagerForTesting()->speculative_frame_host()); 2542 web_contents->GetRenderManagerForTesting()->speculative_frame_host());
2543 } else { 2543 } else {
2544 EXPECT_FALSE( 2544 EXPECT_FALSE(
2545 web_contents->GetRenderManagerForTesting()->pending_frame_host()); 2545 web_contents->GetRenderManagerForTesting()->pending_frame_host());
2546 } 2546 }
2547 2547
2548 ResourceDispatcherHost::Get()->SetDelegate(nullptr); 2548 ResourceDispatcherHost::Get()->SetDelegate(nullptr);
2549 } 2549 }
2550 2550
2551 // Check that if a sandboxed subframe opens a cross-process popup such that the
2552 // popup's opener won't be set, the popup still inherits the subframe's sandbox
2553 // flags. This matters for rel=noopener and rel=noreferrer links, as well as
2554 // for some situations in non-site-per-process mode where the popup would
2555 // normally maintain the opener, but loses it due to being placed in a new
2556 // process and not creating subframe proxies. The latter might happen when
2557 // opening the default search provider site. See https://crbug.com/576204.
2558 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
2559 CrossProcessPopupInheritsSandboxFlagsWithNoOpener) {
2560 StartEmbeddedServer();
2561 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
2562 ->GetFrameTree()
2563 ->root();
2564
2565 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html"));
2566 EXPECT_TRUE(NavigateToURL(shell(), main_url));
2567
2568 // Add a sandboxed about:blank iframe.
2569 {
2570 std::string script =
2571 "var frame = document.createElement('iframe');\n"
2572 "frame.sandbox = 'allow-scripts allow-popups';\n"
2573 "document.body.appendChild(frame);\n";
2574 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script));
2575 }
2576
2577 // Navigate iframe to a page with target=_blank links, and rewrite the links
2578 // to point to valid cross-site URLs.
2579 GURL frame_url(
2580 embedded_test_server()->GetURL("a.com", "/click-noreferrer-links.html"));
2581 NavigateFrameToURL(root->child_at(0), frame_url);
2582 std::string script = "setOriginForLinks('http://b.com:" +
2583 embedded_test_server()->base_url().port() + "/');";
2584 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script));
2585
2586 // Helper to click on the 'rel=noreferrer target=_blank' and 'rel=noopener
2587 // target=_blank' links. Checks that these links open a popup that ends up
2588 // in a new SiteInstance even without site-per-process and then verifies that
2589 // the popup is still sandboxed.
2590 auto click_link_and_verify_popup = [this,
2591 root](std::string link_opening_script) {
2592 ShellAddedObserver new_shell_observer;
2593 bool success = false;
2594 EXPECT_TRUE(ExecuteScriptAndExtractBool(
2595 root->child_at(0)->current_frame_host(),
2596 "window.domAutomationController.send(" + link_opening_script + ")",
2597 &success));
2598 EXPECT_TRUE(success);
2599
2600 Shell* new_shell = new_shell_observer.GetShell();
2601 EXPECT_TRUE(WaitForLoadStop(new_shell->web_contents()));
2602 EXPECT_NE(new_shell->web_contents()->GetSiteInstance(),
2603 shell()->web_contents()->GetSiteInstance());
2604
2605 // Check that the popup is sandboxed by checking its document.origin, which
2606 // should be unique.
2607 std::string origin;
2608 EXPECT_TRUE(ExecuteScriptAndExtractString(
2609 new_shell->web_contents(),
2610 "domAutomationController.send(document.origin)", &origin));
2611 EXPECT_EQ("null", origin);
2612 };
2613
2614 click_link_and_verify_popup("clickNoOpenerTargetBlankLink()");
2615 click_link_and_verify_popup("clickNoRefTargetBlankLink()");
2616 }
2617
2551 } // namespace content 2618 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/render_view_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698