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 "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 // TODO(nasko): This test case belongs better in | |
| 330 // security_exploit_browsertest.cc, so move it there once PlzNavigate is on | |
|
ncarter (slow)
2017/05/24 21:24:38
If we're no longer using pwnmessagerecieved, do we
nasko
2017/05/24 21:43:58
Yeah, no need to move. Removed.
| |
| 331 // by default. | |
| 332 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, | |
| 333 PostUploadIllegalFilePath) { | |
| 334 GURL form_url( | |
| 335 embedded_test_server()->GetURL("/form_that_posts_to_echoall.html")); | |
| 336 EXPECT_TRUE(NavigateToURL(shell(), form_url)); | |
| 337 | |
| 338 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>( | |
| 339 shell()->web_contents()->GetMainFrame()); | |
| 340 | |
| 341 // Prepare a file for the upload form. | |
| 342 base::ThreadRestrictions::ScopedAllowIO allow_io_for_temp_dir; | |
| 343 base::ScopedTempDir temp_dir; | |
| 344 base::FilePath file_path; | |
| 345 std::string file_content("test-file-content"); | |
| 346 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 347 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.GetPath(), &file_path)); | |
| 348 ASSERT_LT( | |
| 349 0, base::WriteFile(file_path, file_content.data(), file_content.size())); | |
| 350 | |
| 351 // Fill out the form to refer to the test file. | |
| 352 std::unique_ptr<FileChooserDelegate> delegate( | |
| 353 new FileChooserDelegate(file_path)); | |
| 354 shell()->web_contents()->SetDelegate(delegate.get()); | |
| 355 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | |
| 356 "document.getElementById('file').click();")); | |
| 357 EXPECT_TRUE(delegate->file_chosen()); | |
| 358 | |
| 359 // Ensure that the process is allowed to access to the chosen file and | |
| 360 // does not have access to the other file name. | |
| 361 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | |
| 362 rfh->GetProcess()->GetID(), file_path)); | |
| 363 | |
| 364 // Revoke the access to the file and submit the form. The renderer process | |
| 365 // should be terminanted. | |
|
ncarter (slow)
2017/05/24 21:24:38
"terminanted" typo
nasko
2017/05/24 21:43:58
Done.
| |
| 366 RenderProcessHostWatcher process_exit_observer( | |
| 367 rfh->GetProcess(), RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | |
| 368 ChildProcessSecurityPolicyImpl* security_policy = | |
| 369 ChildProcessSecurityPolicyImpl::GetInstance(); | |
| 370 security_policy->RevokeAllPermissionsForFile(rfh->GetProcess()->GetID(), | |
| 371 file_path); | |
| 372 EXPECT_TRUE( | |
| 373 ExecuteScript(shell(), "document.getElementById('file-form').submit();")); | |
|
ncarter (slow)
2017/05/24 21:24:38
Possibly paranoid: could the wait and EXPECT_TRUE
nasko
2017/05/24 21:43:58
Rewritten to ensure response is sent back before t
| |
| 374 process_exit_observer.Wait(); | |
| 375 } | |
| 376 | |
| 325 } // namespace content | 377 } // namespace content |
| OLD | NEW |