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/bind_helpers.h" |
7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
8 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/process/process_handle.h" |
10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
11 #include "build/build_config.h" | 13 #include "build/build_config.h" |
12 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" | 14 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
13 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 15 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
14 #include "content/browser/frame_host/navigator.h" | 16 #include "content/browser/frame_host/navigator.h" |
15 #include "content/browser/frame_host/render_frame_host_impl.h" | 17 #include "content/browser/frame_host/render_frame_host_impl.h" |
16 #include "content/browser/renderer_host/render_view_host_factory.h" | 18 #include "content/browser/renderer_host/render_view_host_factory.h" |
17 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
18 #include "content/browser/web_contents/web_contents_impl.h" | 20 #include "content/browser/web_contents/web_contents_impl.h" |
19 #include "content/common/frame_messages.h" | 21 #include "content/common/frame_messages.h" |
(...skipping 374 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 { | |
405 public: | |
406 bool IsIllegalOrigin(content::ResourceContext* resource_context, | |
407 int child_process_id, | |
408 const GURL& origin) override { | |
409 // Simulate a case where an app origin is not in an app process. | |
410 return true; | |
411 } | |
412 }; | |
413 | |
414 // Renderer processes should not be able to spoof Origin HTTP headers. | 406 // Renderer processes should not be able to spoof Origin HTTP headers. |
415 IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, InvalidOriginHeaders) { | 407 IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, InvalidOriginHeaders) { |
416 // Create a set of IPC messages with various Origin headers. | 408 // Create a set of IPC messages with various Origin headers. |
417 ResourceRequest chrome_origin_msg( | 409 ResourceRequest chrome_origin_msg( |
418 CreateXHRRequestWithOrigin("chrome://settings")); | 410 CreateXHRRequestWithOrigin("chrome://settings")); |
419 ResourceRequest embedder_isolated_origin_msg( | 411 ResourceRequest embedder_isolated_origin_msg( |
420 CreateXHRRequestWithOrigin("https://isolated.bar.com")); | 412 CreateXHRRequestWithOrigin("https://isolated.bar.com")); |
421 ResourceRequest invalid_origin_msg(CreateXHRRequestWithOrigin("invalidurl")); | 413 ResourceRequest invalid_origin_msg(CreateXHRRequestWithOrigin("invalidurl")); |
422 ResourceRequest invalid_scheme_origin_msg( | 414 ResourceRequest invalid_scheme_origin_msg( |
423 CreateXHRRequestWithOrigin("fake-scheme://foo")); | 415 CreateXHRRequestWithOrigin("fake-scheme://foo")); |
424 | 416 |
425 GURL web_url("http://foo.com/simple_page.html"); | 417 GURL web_url("http://foo.com/simple_page.html"); |
426 NavigateToURL(shell(), web_url); | 418 NavigateToURL(shell(), web_url); |
427 RenderFrameHost* web_rfh = shell()->web_contents()->GetMainFrame(); | 419 RenderFrameHost* web_rfh = shell()->web_contents()->GetMainFrame(); |
428 | 420 |
| 421 // Registering the https scheme and the URL with RDH leads to the |
| 422 // embedder_isolated_origin_msg being denied |
| 423 ResourceDispatcherHost::Get()->AddSchemeForAccessCheck("https"); |
| 424 BrowserThread::PostTask( |
| 425 BrowserThread::IO, FROM_HERE, |
| 426 base::Bind( |
| 427 &ResourceDispatcherHost::RegisterOriginForAccessChecks, |
| 428 base::Unretained(ResourceDispatcherHost::Get()), |
| 429 shell()->web_contents()->GetBrowserContext()->GetResourceContext(), |
| 430 "https://isolated.bar.com", |
| 431 ResourceDispatcherHost::DENY_FOR_NON_OWNERS)); |
| 432 |
429 // Web processes cannot make XHRs with chrome:// Origin headers. | 433 // Web processes cannot make XHRs with chrome:// Origin headers. |
430 { | 434 { |
431 RenderProcessHostWatcher web_process_killed( | 435 RenderProcessHostWatcher web_process_killed( |
432 web_rfh->GetProcess(), | 436 web_rfh->GetProcess(), |
433 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 437 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
434 IPC::IpcSecurityTestUtil::PwnMessageReceived( | 438 IPC::IpcSecurityTestUtil::PwnMessageReceived( |
435 web_rfh->GetProcess()->GetChannel(), | 439 web_rfh->GetProcess()->GetChannel(), |
436 ResourceHostMsg_RequestResource(web_rfh->GetRoutingID(), | 440 ResourceHostMsg_RequestResource(web_rfh->GetRoutingID(), |
437 kRequestIdNotPreviouslyUsed, | 441 kRequestIdNotPreviouslyUsed, |
438 chrome_origin_msg)); | 442 chrome_origin_msg)); |
439 web_process_killed.Wait(); | 443 web_process_killed.Wait(); |
440 } | 444 } |
441 | 445 |
442 // Web processes cannot make XHRs with URLs that the content embedder expects | 446 // Web processes cannot make XHRs with URLs that the content embedder expects |
443 // to have process isolation. Ideally this would test chrome-extension:// | 447 // 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 | 448 // 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/. | 449 // ResourceRequest IPC can't be created in a test outside content/. |
446 NavigateToURL(shell(), web_url); | 450 NavigateToURL(shell(), web_url); |
447 { | 451 { |
448 // Set up a ContentBrowserClient that simulates an app URL in a non-app | 452 // Set up a ContentBrowserClient that simulates an app URL in a non-app |
449 // process. | 453 // process. |
450 IsolatedAppContentBrowserClient app_client; | |
451 ContentBrowserClient* old_client = SetBrowserClientForTesting(&app_client); | |
452 RenderProcessHostWatcher web_process_killed( | 454 RenderProcessHostWatcher web_process_killed( |
453 web_rfh->GetProcess(), | 455 web_rfh->GetProcess(), |
454 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 456 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
455 IPC::IpcSecurityTestUtil::PwnMessageReceived( | 457 IPC::IpcSecurityTestUtil::PwnMessageReceived( |
456 web_rfh->GetProcess()->GetChannel(), | 458 web_rfh->GetProcess()->GetChannel(), |
457 ResourceHostMsg_RequestResource(web_rfh->GetRoutingID(), | 459 ResourceHostMsg_RequestResource(web_rfh->GetRoutingID(), |
458 kRequestIdNotPreviouslyUsed, | 460 kRequestIdNotPreviouslyUsed, |
459 embedder_isolated_origin_msg)); | 461 embedder_isolated_origin_msg)); |
460 web_process_killed.Wait(); | 462 web_process_killed.Wait(); |
461 SetBrowserClientForTesting(old_client); | |
462 } | 463 } |
463 | 464 |
464 // Web processes cannot make XHRs with invalid Origin headers. | 465 // Web processes cannot make XHRs with invalid Origin headers. |
465 NavigateToURL(shell(), web_url); | 466 NavigateToURL(shell(), web_url); |
466 { | 467 { |
467 RenderProcessHostWatcher web_process_killed( | 468 RenderProcessHostWatcher web_process_killed( |
468 web_rfh->GetProcess(), | 469 web_rfh->GetProcess(), |
469 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 470 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
470 IPC::IpcSecurityTestUtil::PwnMessageReceived( | 471 IPC::IpcSecurityTestUtil::PwnMessageReceived( |
471 web_rfh->GetProcess()->GetChannel(), | 472 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 | 551 // separate task of the message loop, so ensure that the process is still |
551 // considered alive. | 552 // considered alive. |
552 EXPECT_TRUE(root->current_frame_host()->GetProcess()->HasConnection()); | 553 EXPECT_TRUE(root->current_frame_host()->GetProcess()->HasConnection()); |
553 | 554 |
554 exit_observer.Wait(); | 555 exit_observer.Wait(); |
555 EXPECT_FALSE(exit_observer.did_exit_normally()); | 556 EXPECT_FALSE(exit_observer.did_exit_normally()); |
556 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 557 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
557 } | 558 } |
558 | 559 |
559 } // namespace content | 560 } // namespace content |
OLD | NEW |