OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "content/browser/bad_message.h" |
12 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" | 13 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
13 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 14 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
14 #include "content/browser/frame_host/navigator.h" | 15 #include "content/browser/frame_host/navigator.h" |
15 #include "content/browser/frame_host/render_frame_host_impl.h" | 16 #include "content/browser/frame_host/render_frame_host_impl.h" |
16 #include "content/browser/renderer_host/render_view_host_factory.h" | 17 #include "content/browser/renderer_host/render_view_host_factory.h" |
17 #include "content/browser/renderer_host/render_view_host_impl.h" | 18 #include "content/browser/renderer_host/render_view_host_impl.h" |
18 #include "content/browser/web_contents/web_contents_impl.h" | 19 #include "content/browser/web_contents/web_contents_impl.h" |
19 #include "content/common/frame_messages.h" | 20 #include "content/common/frame_messages.h" |
20 #include "content/common/resource_messages.h" | 21 #include "content/common/resource_messages.h" |
21 #include "content/common/resource_request.h" | 22 #include "content/common/resource_request.h" |
22 #include "content/common/view_messages.h" | 23 #include "content/common/view_messages.h" |
23 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/content_browser_client.h" | 25 #include "content/public/browser/content_browser_client.h" |
25 #include "content/public/browser/interstitial_page.h" | 26 #include "content/public/browser/interstitial_page.h" |
26 #include "content/public/browser/interstitial_page_delegate.h" | 27 #include "content/public/browser/interstitial_page_delegate.h" |
| 28 #include "content/public/browser/resource_context.h" |
27 #include "content/public/browser/resource_dispatcher_host.h" | 29 #include "content/public/browser/resource_dispatcher_host.h" |
28 #include "content/public/browser/storage_partition.h" | 30 #include "content/public/browser/storage_partition.h" |
29 #include "content/public/common/appcache_info.h" | 31 #include "content/public/common/appcache_info.h" |
30 #include "content/public/common/browser_side_navigation_policy.h" | 32 #include "content/public/common/browser_side_navigation_policy.h" |
31 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
32 #include "content/public/common/file_chooser_params.h" | 34 #include "content/public/common/file_chooser_params.h" |
33 #include "content/public/test/browser_test_utils.h" | 35 #include "content/public/test/browser_test_utils.h" |
34 #include "content/public/test/content_browser_test.h" | 36 #include "content/public/test/content_browser_test.h" |
35 #include "content/public/test/content_browser_test_utils.h" | 37 #include "content/public/test/content_browser_test_utils.h" |
36 #include "content/public/test/test_utils.h" | 38 #include "content/public/test/test_utils.h" |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 396 |
395 // Send a second message from the interstitial page, and make sure that the | 397 // Send a second message from the interstitial page, and make sure that the |
396 // "evil" message doesn't arrive in the intervening period. | 398 // "evil" message doesn't arrive in the intervening period. |
397 ASSERT_TRUE(ExecuteScript(interstitial_page->GetMainFrame(), | 399 ASSERT_TRUE(ExecuteScript(interstitial_page->GetMainFrame(), |
398 "window.domAutomationController.send(\"okay2\");")); | 400 "window.domAutomationController.send(\"okay2\");")); |
399 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 401 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
400 ASSERT_EQ("\"okay2\"", message); | 402 ASSERT_EQ("\"okay2\"", message); |
401 ASSERT_EQ("\"okay2\"", interstitial->last_command()); | 403 ASSERT_EQ("\"okay2\"", interstitial->last_command()); |
402 } | 404 } |
403 | 405 |
404 class IsolatedAppContentBrowserClient : public TestContentBrowserClient { | 406 // Intercepts the HTTP origin header and on being invoked once it is found |
405 public: | 407 // aborts the requeest. |
406 bool IsIllegalOrigin(content::ResourceContext* resource_context, | 408 void OnHttpHeaderReceived(const std::string& header, |
407 int child_process_id, | 409 const std::string& value, |
408 const GURL& origin) override { | 410 int child_process_id, |
409 // Simulate a case where an app origin is not in an app process. | 411 content::ResourceContext* resource_context, |
410 return true; | 412 OnHeaderProcessedCallback callback) { |
411 } | 413 callback.Run(false, content::bad_message::RDH_ILLEGAL_ORIGIN); |
412 }; | 414 } |
413 | 415 |
414 // Renderer processes should not be able to spoof Origin HTTP headers. | 416 // Renderer processes should not be able to spoof Origin HTTP headers. |
415 IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, InvalidOriginHeaders) { | 417 IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, InvalidOriginHeaders) { |
416 // Create a set of IPC messages with various Origin headers. | 418 // Create a set of IPC messages with various Origin headers. |
417 ResourceRequest chrome_origin_msg( | 419 ResourceRequest chrome_origin_msg( |
418 CreateXHRRequestWithOrigin("chrome://settings")); | 420 CreateXHRRequestWithOrigin("chrome://settings")); |
419 ResourceRequest embedder_isolated_origin_msg( | 421 ResourceRequest embedder_isolated_origin_msg( |
420 CreateXHRRequestWithOrigin("https://isolated.bar.com")); | 422 CreateXHRRequestWithOrigin("https://isolated.bar.com")); |
421 ResourceRequest invalid_origin_msg(CreateXHRRequestWithOrigin("invalidurl")); | 423 ResourceRequest invalid_origin_msg(CreateXHRRequestWithOrigin("invalidurl")); |
422 ResourceRequest invalid_scheme_origin_msg( | 424 ResourceRequest invalid_scheme_origin_msg( |
(...skipping 15 matching lines...) Expand all Loading... |
438 chrome_origin_msg)); | 440 chrome_origin_msg)); |
439 web_process_killed.Wait(); | 441 web_process_killed.Wait(); |
440 } | 442 } |
441 | 443 |
442 // Web processes cannot make XHRs with URLs that the content embedder expects | 444 // Web processes cannot make XHRs with URLs that the content embedder expects |
443 // to have process isolation. Ideally this would test chrome-extension:// | 445 // to have process isolation. Ideally this would test chrome-extension:// |
444 // URLs for Chrome Apps, but those can't be tested inside content/ and the | 446 // URLs for Chrome Apps, but those can't be tested inside content/ and the |
445 // ResourceRequest IPC can't be created in a test outside content/. | 447 // ResourceRequest IPC can't be created in a test outside content/. |
446 NavigateToURL(shell(), web_url); | 448 NavigateToURL(shell(), web_url); |
447 { | 449 { |
448 // Set up a ContentBrowserClient that simulates an app URL in a non-app | 450 content::ResourceDispatcherHost::Get()->RegisterInterceptor( |
449 // process. | 451 "Origin", "", base::Bind(&OnHttpHeaderReceived)); |
450 IsolatedAppContentBrowserClient app_client; | 452 |
451 ContentBrowserClient* old_client = SetBrowserClientForTesting(&app_client); | |
452 RenderProcessHostWatcher web_process_killed( | 453 RenderProcessHostWatcher web_process_killed( |
453 web_rfh->GetProcess(), | 454 web_rfh->GetProcess(), |
454 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 455 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
455 IPC::IpcSecurityTestUtil::PwnMessageReceived( | 456 IPC::IpcSecurityTestUtil::PwnMessageReceived( |
456 web_rfh->GetProcess()->GetChannel(), | 457 web_rfh->GetProcess()->GetChannel(), |
457 ResourceHostMsg_RequestResource(web_rfh->GetRoutingID(), | 458 ResourceHostMsg_RequestResource(web_rfh->GetRoutingID(), |
458 kRequestIdNotPreviouslyUsed, | 459 kRequestIdNotPreviouslyUsed, |
459 embedder_isolated_origin_msg)); | 460 embedder_isolated_origin_msg)); |
460 web_process_killed.Wait(); | 461 web_process_killed.Wait(); |
461 SetBrowserClientForTesting(old_client); | |
462 } | 462 } |
463 | 463 |
464 // Web processes cannot make XHRs with invalid Origin headers. | 464 // Web processes cannot make XHRs with invalid Origin headers. |
465 NavigateToURL(shell(), web_url); | 465 NavigateToURL(shell(), web_url); |
466 { | 466 { |
467 RenderProcessHostWatcher web_process_killed( | 467 RenderProcessHostWatcher web_process_killed( |
468 web_rfh->GetProcess(), | 468 web_rfh->GetProcess(), |
469 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 469 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
470 IPC::IpcSecurityTestUtil::PwnMessageReceived( | 470 IPC::IpcSecurityTestUtil::PwnMessageReceived( |
471 web_rfh->GetProcess()->GetChannel(), | 471 web_rfh->GetProcess()->GetChannel(), |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 // separate task of the message loop, so ensure that the process is still | 550 // separate task of the message loop, so ensure that the process is still |
551 // considered alive. | 551 // considered alive. |
552 EXPECT_TRUE(root->current_frame_host()->GetProcess()->HasConnection()); | 552 EXPECT_TRUE(root->current_frame_host()->GetProcess()->HasConnection()); |
553 | 553 |
554 exit_observer.Wait(); | 554 exit_observer.Wait(); |
555 EXPECT_FALSE(exit_observer.did_exit_normally()); | 555 EXPECT_FALSE(exit_observer.did_exit_normally()); |
556 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 556 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
557 } | 557 } |
558 | 558 |
559 } // namespace content | 559 } // namespace content |
OLD | NEW |