| 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 "content/browser/child_process_security_policy_impl.h" |
| 10 #include "content/browser/frame_host/navigation_handle_impl.h" | 11 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 11 #include "content/browser/frame_host/navigation_request.h" | 12 #include "content/browser/frame_host/navigation_request.h" |
| 12 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
| 13 #include "content/common/site_isolation_policy.h" | 14 #include "content/common/site_isolation_policy.h" |
| 14 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
| 15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 17 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
| 18 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 19 #include "content/public/test/content_browser_test.h" | 20 #include "content/public/test/content_browser_test.h" |
| 20 #include "content/public/test/content_browser_test_utils.h" | 21 #include "content/public/test/content_browser_test_utils.h" |
| 21 #include "content/public/test/navigation_handle_observer.h" | 22 #include "content/public/test/navigation_handle_observer.h" |
| 22 #include "content/public/test/test_navigation_observer.h" | 23 #include "content/public/test/test_navigation_observer.h" |
| 23 #include "content/shell/browser/shell.h" | 24 #include "content/shell/browser/shell.h" |
| 24 #include "content/shell/browser/shell_network_delegate.h" | 25 #include "content/shell/browser/shell_network_delegate.h" |
| 26 #include "content/test/content_browser_test_utils_internal.h" |
| 25 #include "net/dns/mock_host_resolver.h" | 27 #include "net/dns/mock_host_resolver.h" |
| 26 #include "net/test/embedded_test_server/embedded_test_server.h" | 28 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 27 #include "net/test/url_request/url_request_failed_job.h" | 29 #include "net/test/url_request/url_request_failed_job.h" |
| 28 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 29 | 31 |
| 30 namespace content { | 32 namespace content { |
| 31 | 33 |
| 32 class BrowserSideNavigationBrowserTest : public ContentBrowserTest { | 34 class BrowserSideNavigationBrowserTest : public ContentBrowserTest { |
| 33 public: | 35 public: |
| 34 BrowserSideNavigationBrowserTest() {} | 36 BrowserSideNavigationBrowserTest() {} |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 ASSERT_TRUE(root->navigation_request()); | 317 ASSERT_TRUE(root->navigation_request()); |
| 316 EXPECT_EQ(GURL(), | 318 EXPECT_EQ(GURL(), |
| 317 root->navigation_request()->navigation_handle()->GetReferrer().url); | 319 root->navigation_request()->navigation_handle()->GetReferrer().url); |
| 318 | 320 |
| 319 // The navigation should commit without being blocked. | 321 // The navigation should commit without being blocked. |
| 320 EXPECT_TRUE(manager.WaitForResponse()); | 322 EXPECT_TRUE(manager.WaitForResponse()); |
| 321 manager.WaitForNavigationFinished(); | 323 manager.WaitForNavigationFinished(); |
| 322 EXPECT_EQ(kInsecureUrl, shell()->web_contents()->GetLastCommittedURL()); | 324 EXPECT_EQ(kInsecureUrl, shell()->web_contents()->GetLastCommittedURL()); |
| 323 } | 325 } |
| 324 | 326 |
| 327 // Test to verify that an exploited renderer process trying to upload a file |
| 328 // it hasn't been explicitly granted permissions to is correctly terminated. |
| 329 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, |
| 330 PostUploadIllegalFilePath) { |
| 331 GURL form_url( |
| 332 embedded_test_server()->GetURL("/form_that_posts_to_echoall.html")); |
| 333 EXPECT_TRUE(NavigateToURL(shell(), form_url)); |
| 334 |
| 335 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>( |
| 336 shell()->web_contents()->GetMainFrame()); |
| 337 |
| 338 // Prepare a file for the upload form. |
| 339 base::ThreadRestrictions::ScopedAllowIO allow_io_for_temp_dir; |
| 340 base::ScopedTempDir temp_dir; |
| 341 base::FilePath file_path; |
| 342 std::string file_content("test-file-content"); |
| 343 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 344 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.GetPath(), &file_path)); |
| 345 ASSERT_LT( |
| 346 0, base::WriteFile(file_path, file_content.data(), file_content.size())); |
| 347 |
| 348 // Fill out the form to refer to the test file. |
| 349 std::unique_ptr<FileChooserDelegate> delegate( |
| 350 new FileChooserDelegate(file_path)); |
| 351 shell()->web_contents()->SetDelegate(delegate.get()); |
| 352 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
| 353 "document.getElementById('file').click();")); |
| 354 EXPECT_TRUE(delegate->file_chosen()); |
| 355 |
| 356 // Ensure that the process is allowed to access to the chosen file and |
| 357 // does not have access to the other file name. |
| 358 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 359 rfh->GetProcess()->GetID(), file_path)); |
| 360 |
| 361 // Revoke the access to the file and submit the form. The renderer process |
| 362 // should be terminated. |
| 363 RenderProcessHostWatcher process_exit_observer( |
| 364 rfh->GetProcess(), RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 365 ChildProcessSecurityPolicyImpl* security_policy = |
| 366 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 367 security_policy->RevokeAllPermissionsForFile(rfh->GetProcess()->GetID(), |
| 368 file_path); |
| 369 |
| 370 // Use ExecuteScriptAndExtractBool and respond back to the browser process |
| 371 // before doing the actual submission. This will ensure that the process |
| 372 // termination is guaranteed to arrive after the response from the executed |
| 373 // JavaScript. |
| 374 bool result = false; |
| 375 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 376 shell(), |
| 377 "window.domAutomationController.send(true);" |
| 378 "document.getElementById('file-form').submit();", |
| 379 &result)); |
| 380 EXPECT_TRUE(result); |
| 381 process_exit_observer.Wait(); |
| 382 } |
| 383 |
| 325 } // namespace content | 384 } // namespace content |
| OLD | NEW |