Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/scoped_feature_list.h" | |
| 10 #include "content/browser/child_process_security_policy_impl.h" | 11 #include "content/browser/child_process_security_policy_impl.h" |
| 11 #include "content/browser/frame_host/navigation_handle_impl.h" | 12 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 12 #include "content/browser/frame_host/navigation_request.h" | 13 #include "content/browser/frame_host/navigation_request.h" |
| 13 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
| 14 #include "content/common/frame_messages.h" | 15 #include "content/common/frame_messages.h" |
| 15 #include "content/common/site_isolation_policy.h" | 16 #include "content/common/site_isolation_policy.h" |
| 17 #include "content/public/browser/navigation_controller.h" | |
| 16 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/content_features.h" | |
| 18 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
| 19 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
| 20 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
| 21 #include "content/public/test/content_browser_test.h" | 24 #include "content/public/test/content_browser_test.h" |
| 22 #include "content/public/test/content_browser_test_utils.h" | 25 #include "content/public/test/content_browser_test_utils.h" |
| 23 #include "content/public/test/navigation_handle_observer.h" | 26 #include "content/public/test/navigation_handle_observer.h" |
| 24 #include "content/public/test/test_navigation_observer.h" | 27 #include "content/public/test/test_navigation_observer.h" |
| 25 #include "content/shell/browser/shell.h" | 28 #include "content/shell/browser/shell.h" |
| 26 #include "content/shell/browser/shell_network_delegate.h" | 29 #include "content/shell/browser/shell_network_delegate.h" |
| 27 #include "content/test/content_browser_test_utils_internal.h" | 30 #include "content/test/content_browser_test_utils_internal.h" |
| 28 #include "ipc/ipc_security_test_util.h" | 31 #include "ipc/ipc_security_test_util.h" |
| 32 #include "net/base/filename_util.h" | |
| 29 #include "net/base/load_flags.h" | 33 #include "net/base/load_flags.h" |
| 30 #include "net/dns/mock_host_resolver.h" | 34 #include "net/dns/mock_host_resolver.h" |
| 31 #include "net/test/embedded_test_server/embedded_test_server.h" | 35 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 32 #include "net/test/url_request/url_request_failed_job.h" | 36 #include "net/test/url_request/url_request_failed_job.h" |
| 33 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 34 | 38 |
| 35 namespace content { | 39 namespace content { |
| 36 | 40 |
| 37 class BrowserSideNavigationBrowserTest : public ContentBrowserTest { | 41 class BrowserSideNavigationBrowserTest : public ContentBrowserTest { |
| 38 public: | 42 public: |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 // to the URL that was blocked. | 422 // to the URL that was blocked. |
| 419 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 423 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 420 EXPECT_FALSE( | 424 EXPECT_FALSE( |
| 421 controller.GetLastCommittedEntry()->GetURL().SchemeIs(url::kDataScheme)); | 425 controller.GetLastCommittedEntry()->GetURL().SchemeIs(url::kDataScheme)); |
| 422 EXPECT_TRUE(controller.GetLastCommittedEntry()->GetVirtualURL().SchemeIs( | 426 EXPECT_TRUE(controller.GetLastCommittedEntry()->GetVirtualURL().SchemeIs( |
| 423 url::kDataScheme)); | 427 url::kDataScheme)); |
| 424 EXPECT_EQ(url::kAboutBlankURL, | 428 EXPECT_EQ(url::kAboutBlankURL, |
| 425 controller.GetLastCommittedEntry()->GetURL().spec()); | 429 controller.GetLastCommittedEntry()->GetURL().spec()); |
| 426 } | 430 } |
| 427 | 431 |
| 432 class BrowserSideNavigationBrowserDisableWebSecurityTest | |
| 433 : public BrowserSideNavigationBrowserTest { | |
| 434 public: | |
| 435 BrowserSideNavigationBrowserDisableWebSecurityTest() {} | |
| 436 | |
| 437 protected: | |
| 438 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 439 // Simulate a compromised renderer, otherwise the cross-origin request to | |
| 440 // file: is blocked. | |
| 441 command_line->AppendSwitch(switches::kDisableWebSecurity); | |
| 442 BrowserSideNavigationBrowserTest::SetUpCommandLine(command_line); | |
| 443 } | |
| 444 }; | |
| 445 | |
| 428 // Test to verify that an exploited renderer process trying to specify a | 446 // Test to verify that an exploited renderer process trying to specify a |
| 429 // non-empty URL for base_url_for_data_url on navigation is correctly | 447 // non-empty URL for base_url_for_data_url on navigation is correctly |
| 430 // terminated. | 448 // terminated. |
| 431 // TODO(nasko): This test case belongs better in | 449 // TODO(nasko): This test case belongs better in |
| 432 // security_exploit_browsertest.cc, so move it there once PlzNavigate is on | 450 // security_exploit_browsertest.cc, so move it there once PlzNavigate is on |
| 433 // by default. | 451 // by default. |
| 434 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, | 452 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserDisableWebSecurityTest, |
| 435 ValidateBaseUrlForDataUrl) { | 453 ValidateBaseUrlForDataUrl) { |
| 436 GURL start_url(embedded_test_server()->GetURL("/title1.html")); | 454 GURL start_url(embedded_test_server()->GetURL("/title1.html")); |
| 437 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | 455 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| 438 | 456 |
| 439 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>( | 457 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>( |
| 440 shell()->web_contents()->GetMainFrame()); | 458 shell()->web_contents()->GetMainFrame()); |
| 441 | 459 |
| 460 GURL data_url("data:text/html,foo"); | |
| 461 base::FilePath file_path = GetTestFilePath("", "simple_page.html"); | |
| 462 GURL file_url = net::FilePathToFileURL(file_path); | |
| 463 | |
| 464 // To get around DataUrlNavigationThrottle. Other attempts at getting around | |
| 465 // it don't work, i.e.: | |
| 466 // -if the request is made in a child frame then the frame is torn down | |
| 467 // immediately on process killing so the navigation doesn't complete | |
| 468 // -if it's classified as same document, then a DCHECK in | |
| 469 // NavigationRequest::CreateRendererInitiated fires | |
| 470 base::test::ScopedFeatureList feature_list; | |
| 471 feature_list.InitAndEnableFeature( | |
| 472 features::kAllowContentInitiatedDataUrlNavigations); | |
| 442 // Setup a BeginNavigate IPC with non-empty base_url_for_data_url. | 473 // Setup a BeginNavigate IPC with non-empty base_url_for_data_url. |
| 443 GURL url(embedded_test_server()->GetURL("/title2.html")); | |
| 444 CommonNavigationParams common_params( | 474 CommonNavigationParams common_params( |
| 445 url, Referrer(), ui::PAGE_TRANSITION_LINK, | 475 data_url, Referrer(), ui::PAGE_TRANSITION_LINK, |
|
Charlie Reis
2017/06/01 00:33:43
Just curious, why did you need to use a data URL?
jam
2017/06/01 00:51:19
The call to ChildProcessSecurityPolicy that uses b
Charlie Reis
2017/06/01 01:00:09
Ah, thanks. So the original test wouldn't have go
| |
| 446 FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT, true, false, | 476 FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT, true, false, |
| 447 base::TimeTicks(), FrameMsg_UILoadMetricsReportType::NO_REPORT, | 477 base::TimeTicks(), FrameMsg_UILoadMetricsReportType::NO_REPORT, |
| 448 embedded_test_server()->GetURL("foo.com", | 478 file_url, // base_url_for_data_url |
| 449 "/title3.html"), // base_url_for_data_url | |
| 450 GURL(), PREVIEWS_UNSPECIFIED, base::TimeTicks::Now(), "GET", nullptr, | 479 GURL(), PREVIEWS_UNSPECIFIED, base::TimeTicks::Now(), "GET", nullptr, |
| 451 base::Optional<SourceLocation>(), CSPDisposition::CHECK); | 480 base::Optional<SourceLocation>(), CSPDisposition::CHECK); |
| 452 BeginNavigationParams begin_params( | 481 BeginNavigationParams begin_params( |
| 453 std::string(), net::LOAD_NORMAL, false, false, | 482 std::string(), net::LOAD_NORMAL, false, false, |
| 454 REQUEST_CONTEXT_TYPE_LOCATION, | 483 REQUEST_CONTEXT_TYPE_LOCATION, |
| 455 blink::WebMixedContentContextType::kBlockable, false, url::Origin(url)); | 484 blink::WebMixedContentContextType::kBlockable, false, |
| 485 url::Origin(data_url)); | |
| 456 FrameHostMsg_BeginNavigation msg(rfh->GetRoutingID(), common_params, | 486 FrameHostMsg_BeginNavigation msg(rfh->GetRoutingID(), common_params, |
| 457 begin_params); | 487 begin_params); |
| 458 | 488 |
| 459 // Receiving the invalid IPC message should lead to renderer process | 489 // Receiving the invalid IPC message should lead to renderer process |
| 460 // termination. | 490 // termination. |
| 461 RenderProcessHostWatcher process_exit_observer( | 491 RenderProcessHostWatcher process_exit_observer( |
| 462 rfh->GetProcess(), RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 492 rfh->GetProcess(), RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 463 IPC::IpcSecurityTestUtil::PwnMessageReceived(rfh->GetProcess()->GetChannel(), | 493 IPC::IpcSecurityTestUtil::PwnMessageReceived(rfh->GetProcess()->GetChannel(), |
| 464 msg); | 494 msg); |
| 465 process_exit_observer.Wait(); | 495 process_exit_observer.Wait(); |
|
Charlie Reis
2017/06/01 00:33:43
Does the CanReadFile check work? We should add it
jam
2017/06/01 00:51:19
Done.
| |
| 496 | |
| 497 // Reload the page to create another renderer process. | |
| 498 TestNavigationObserver tab_observer(shell()->web_contents(), 1); | |
| 499 shell()->web_contents()->GetController().Reload(ReloadType::NORMAL, false); | |
| 500 tab_observer.Wait(); | |
| 501 | |
| 502 // Make an XHR request to check if the page has access. | |
| 503 std::string script = base::StringPrintf( | |
| 504 "var xhr = new XMLHttpRequest()\n" | |
| 505 "xhr.open('GET', '%s', false);\n" | |
| 506 "xhr.send();\n" | |
| 507 "window.domAutomationController.send(xhr.responseText);", | |
| 508 file_url.spec().c_str()); | |
| 509 std::string result; | |
| 510 EXPECT_TRUE( | |
| 511 ExecuteScriptAndExtractString(shell()->web_contents(), script, &result)); | |
| 512 EXPECT_TRUE(result.empty()); | |
| 466 } | 513 } |
| 467 | 514 |
| 468 } // namespace content | 515 } // namespace content |
| OLD | NEW |