Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(602)

Side by Side Diff: chrome/browser/chrome_security_exploit_browsertest.cc

Issue 2399853003: [M54 merge] Lock down creation of blob:chrome-extension URLs from non-extension processes. (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h" 10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/singleton_tabs.h" 11 #include "chrome/browser/ui/singleton_tabs.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/extensions/extension_process_policy.h"
13 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
16 #include "content/common/fileapi/webblob_messages.h"
15 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_types.h" 19 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/resource_request_details.h" 22 #include "content/public/browser/resource_request_details.h"
19 #include "content/public/browser/web_contents_observer.h" 23 #include "content/public/browser/web_contents_observer.h"
20 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
21 #include "content/public/test/browser_test_utils.h" 25 #include "content/public/test/browser_test_utils.h"
26 #include "ipc/ipc_security_test_util.h"
27 #include "net/dns/mock_host_resolver.h"
22 #include "net/test/embedded_test_server/embedded_test_server.h" 28 #include "net/test/embedded_test_server/embedded_test_server.h"
23 29
24 // The goal of these tests is to "simulate" exploited renderer processes, which 30 // The goal of these tests is to "simulate" exploited renderer processes, which
25 // can send arbitrary IPC messages and confuse browser process internal state, 31 // can send arbitrary IPC messages and confuse browser process internal state,
26 // leading to security bugs. We are trying to verify that the browser doesn't 32 // leading to security bugs. We are trying to verify that the browser doesn't
27 // perform any dangerous operations in such cases. 33 // perform any dangerous operations in such cases.
28 // This is similar to the security_exploit_browsertest.cc tests, but also 34 // This is similar to the security_exploit_browsertest.cc tests, but also
29 // includes chrome/ layer concepts such as extensions. 35 // includes chrome/ layer concepts such as extensions.
30 class ChromeSecurityExploitBrowserTest : public InProcessBrowserTest { 36 class ChromeSecurityExploitBrowserTest : public InProcessBrowserTest {
31 public: 37 public:
32 ChromeSecurityExploitBrowserTest() {} 38 ChromeSecurityExploitBrowserTest() {}
33 ~ChromeSecurityExploitBrowserTest() override {} 39 ~ChromeSecurityExploitBrowserTest() override {}
34 40
41 void SetUpOnMainThread() override {
42 ASSERT_TRUE(embedded_test_server()->Start());
43 host_resolver()->AddRule("*", "127.0.0.1");
44 }
45
35 void SetUpCommandLine(base::CommandLine* command_line) override { 46 void SetUpCommandLine(base::CommandLine* command_line) override {
36 ASSERT_TRUE(embedded_test_server()->Start());
37
38 // Add a host resolver rule to map all outgoing requests to the test server.
39 // This allows us to use "real" hostnames in URLs, which we can use to
40 // create arbitrary SiteInstances.
41 command_line->AppendSwitchASCII(
42 switches::kHostResolverRules,
43 "MAP * " + embedded_test_server()->host_port_pair().ToString() +
44 ",EXCLUDE localhost");
45
46 // Since we assume exploited renderer process, it can bypass the same origin 47 // Since we assume exploited renderer process, it can bypass the same origin
47 // policy at will. Simulate that by passing the disable-web-security flag. 48 // policy at will. Simulate that by passing the disable-web-security flag.
48 command_line->AppendSwitch(switches::kDisableWebSecurity); 49 command_line->AppendSwitch(switches::kDisableWebSecurity);
49 } 50 }
50 51
51 private: 52 private:
52 DISALLOW_COPY_AND_ASSIGN(ChromeSecurityExploitBrowserTest); 53 DISALLOW_COPY_AND_ASSIGN(ChromeSecurityExploitBrowserTest);
53 }; 54 };
54 55
55 IN_PROC_BROWSER_TEST_F(ChromeSecurityExploitBrowserTest, 56 IN_PROC_BROWSER_TEST_F(ChromeSecurityExploitBrowserTest,
56 ChromeExtensionResources) { 57 ChromeExtensionResources) {
57 // Load a page that requests a chrome-extension:// image through XHR. We 58 // Load a page that requests a chrome-extension:// image through XHR. We
58 // expect this load to fail, as it is an illegal request. 59 // expect this load to fail, as it is an illegal request.
59 GURL foo("http://foo.com/chrome_extension_resource.html"); 60 GURL foo = embedded_test_server()->GetURL("foo.com",
61 "/chrome_extension_resource.html");
60 62
61 content::DOMMessageQueue msg_queue; 63 content::DOMMessageQueue msg_queue;
62 64
63 ui_test_utils::NavigateToURL(browser(), foo); 65 ui_test_utils::NavigateToURL(browser(), foo);
64 66
65 std::string status; 67 std::string status;
66 std::string expected_status("0"); 68 std::string expected_status("0");
67 EXPECT_TRUE(msg_queue.WaitForMessage(&status)); 69 EXPECT_TRUE(msg_queue.WaitForMessage(&status));
68 EXPECT_STREQ(status.c_str(), expected_status.c_str()); 70 EXPECT_STREQ(status.c_str(), expected_status.c_str());
69 } 71 }
72
73 IN_PROC_BROWSER_TEST_F(ChromeSecurityExploitBrowserTest,
74 CreateBlobInExtensionOrigin) {
75 if (!extensions::IsIsolateExtensionsEnabled())
76 return;
77
78 ui_test_utils::NavigateToURL(
79 browser(),
80 embedded_test_server()->GetURL("a.root-servers.net", "/title1.html"));
81
82 content::RenderFrameHost* rfh =
83 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame();
84
85 // All these are attacker controlled values. The UUID is arbitrary.
86 std::string blob_id = "2ce53a26-0409-45a3-86e5-f8fb9f5566d8";
87 std::string blob_type = "text/html";
88 std::string blob_contents = "<script>chrome.extensions</script>";
89 std::string blob_path = "5881f76e-10d2-410d-8c61-ef210502acfd";
90
91 // Target the bookmark manager extension.
92 std::string target_origin =
93 "chrome-extension://eemcgdkfndhakfknompkggombfjjjeno";
94
95 std::vector<storage::DataElement> data_elements(1);
96 data_elements[0].SetToBytes(blob_contents.c_str(), blob_contents.size());
97
98 // Set up a blob ID and populate it with attacker-controlled value. These two
99 // messages are allowed, because this data is not in any origin.
100 IPC::IpcSecurityTestUtil::PwnMessageReceived(
101 rfh->GetProcess()->GetChannel(),
102 BlobStorageMsg_RegisterBlobUUID(blob_id, blob_type, "",
103 std::set<std::string>()));
104
105 IPC::IpcSecurityTestUtil::PwnMessageReceived(
106 rfh->GetProcess()->GetChannel(),
107 BlobStorageMsg_StartBuildingBlob(blob_id, data_elements));
108
109 // This IPC should result in a kill because |target_origin| is not commitable
110 // in |rfh->GetProcess()|.
111 content::RenderProcessHostWatcher crash_observer(
112 rfh->GetProcess(),
113 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
114 IPC::IpcSecurityTestUtil::PwnMessageReceived(
115 rfh->GetProcess()->GetChannel(),
116 BlobHostMsg_RegisterPublicURL(
117 GURL("blob:" + target_origin + "/" + blob_path), blob_id));
118 crash_observer.Wait(); // If the process is killed, this test passes.
119 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.h ('k') | chrome/browser/devtools/devtools_sanity_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698