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

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 1710283003: OOPIF: Handle cross-site frames being blocked by X-Frame-Options or CSP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/site_per_process_browsertest.h" 5 #include "content/browser/site_per_process_browsertest.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 5283 matching lines...) Expand 10 before | Expand all | Expand 10 after
5294 observer->Wait(); 5294 observer->Wait();
5295 5295
5296 // Force the renderer to generate a new frame. 5296 // Force the renderer to generate a new frame.
5297 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), 5297 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
5298 "document.body.style.background = 'black'")); 5298 "document.body.style.background = 'black'"));
5299 5299
5300 // Waits for the next frame. 5300 // Waits for the next frame.
5301 observer->Wait(); 5301 observer->Wait();
5302 } 5302 }
5303 5303
5304 // Test that a cross-origin iframe can be blocked by X-Frame-Options and CSP
5305 // frame-ancestors.
5306 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
5307 CrossSiteIframeBlockedByXFrameOptionsOrCSP) {
5308 GURL main_url(embedded_test_server()->GetURL(
5309 "a.com", "/cross_site_iframe_factory.html?a(a)"));
5310 NavigateToURL(shell(), main_url);
5311
5312 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
5313 ->GetFrameTree()
5314 ->root();
5315 GURL frame_url(root->child_at(0)->current_url());
5316
5317 // Add a load event handler for the iframe element.
5318 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
5319 "document.querySelector('iframe').onload = "
5320 " function() { document.title = 'loaded'; };"));
5321
5322 GURL blocked_urls[] = {
5323 embedded_test_server()->GetURL("b.com", "/frame-ancestors-none.html"),
5324 embedded_test_server()->GetURL("b.com", "/x-frame-options-deny.html")
5325 };
5326
5327 for (size_t i = 0; i < arraysize(blocked_urls); ++i) {
5328 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
5329 "document.title = 'not loaded';"));
5330 base::string16 expected_title(base::UTF8ToUTF16("loaded"));
5331 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
5332
5333 // Navigate the subframe to a blocked URL, and wait for navigation to fail.
5334 TestNavigationObserver load_observer(shell()->web_contents());
5335 EXPECT_TRUE(ExecuteScript(
5336 shell()->web_contents(),
5337 "frames[0].location.href = '" + blocked_urls[i].spec() + "';"));
5338 load_observer.Wait();
5339
5340 // Blocking the frame will result in a DidFailProvisionalLoad; i.e., the
5341 // last navigation should have failed.
5342 EXPECT_FALSE(load_observer.last_navigation_succeeded());
5343
5344 // The blocked frame's origin should become unique.
5345 EXPECT_EQ("null", root->child_at(0)->current_origin().Serialize());
5346
5347 // The blocked frame should still fire a load event in its parent's process.
5348 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
5349
5350 // Double-check that the current RenderFrameHost has stopped loading.
5351 EXPECT_FALSE(root->child_at(0)->current_frame_host()->is_loading());
5352
5353 // Navigate the subframe to another cross-origin page and ensure that this
5354 // navigation succeeds.
5355 GURL c_url(embedded_test_server()->GetURL("c.com", "/title1.html"));
5356 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "child-0", c_url));
5357 EXPECT_EQ(c_url, root->child_at(0)->current_url());
5358
5359 // When a page gets blocked due to XFO or CSP, it is sandboxed with the
5360 // SandboxOrigin flag (i.e., its origin is set to be unique) in the
5361 // renderer to ensure that the blocked page is seen as cross-origin.
5362 // However, those flags shouldn't affect future navigations for a frame.
5363 // Verify this for the above navigation.
5364 EXPECT_EQ(c_url.GetOrigin().spec(),
5365 root->child_at(0)->current_origin().Serialize() + "/");
5366 EXPECT_EQ(blink::WebSandboxFlags::None,
5367 root->child_at(0)->effective_sandbox_flags());
5368 }
5369 }
5370
5304 } // namespace content 5371 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698