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

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

Issue 2398463004: browser_test that creates filesystem resources in extension origin (Closed)
Patch Set: Rebase & apply alex's fixes. Created 4 years 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
« no previous file with comments | « chrome/browser/DEPS ('k') | content/browser/fileapi/mock_file_update_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/test/histogram_tester.h"
8 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_commands.h" 10 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/singleton_tabs.h" 11 #include "chrome/browser/ui/singleton_tabs.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/extensions/extension_process_policy.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"
15 #include "content/common/fileapi/webblob_messages.h"
16 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/notification_types.h" 18 #include "content/public/browser/notification_types.h"
19 #include "content/public/browser/render_frame_host.h" 19 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/render_process_host.h" 20 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/resource_request_details.h" 21 #include "content/public/browser/resource_request_details.h"
22 #include "content/public/browser/web_contents_observer.h" 22 #include "content/public/browser/web_contents_observer.h"
23 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
24 #include "content/public/test/browser_test_utils.h" 24 #include "content/public/test/browser_test_utils.h"
25 #include "ipc/ipc_security_test_util.h"
26 #include "net/dns/mock_host_resolver.h" 25 #include "net/dns/mock_host_resolver.h"
27 #include "net/test/embedded_test_server/embedded_test_server.h" 26 #include "net/test/embedded_test_server/embedded_test_server.h"
28 27
29 // The goal of these tests is to "simulate" exploited renderer processes, which 28 // The goal of these tests is to "simulate" exploited renderer processes, which
30 // can send arbitrary IPC messages and confuse browser process internal state, 29 // can send arbitrary IPC messages and confuse browser process internal state,
31 // leading to security bugs. We are trying to verify that the browser doesn't 30 // leading to security bugs. We are trying to verify that the browser doesn't
32 // perform any dangerous operations in such cases. 31 // perform any dangerous operations in such cases.
33 // This is similar to the security_exploit_browsertest.cc tests, but also 32 // This is similar to the security_exploit_browsertest.cc tests, but also
34 // includes chrome/ layer concepts such as extensions. 33 // includes chrome/ layer concepts such as extensions.
35 class ChromeSecurityExploitBrowserTest : public InProcessBrowserTest { 34 class ChromeSecurityExploitBrowserTest : public InProcessBrowserTest {
(...skipping 26 matching lines...) Expand all
62 content::DOMMessageQueue msg_queue; 61 content::DOMMessageQueue msg_queue;
63 62
64 ui_test_utils::NavigateToURL(browser(), foo); 63 ui_test_utils::NavigateToURL(browser(), foo);
65 64
66 std::string status; 65 std::string status;
67 std::string expected_status("0"); 66 std::string expected_status("0");
68 EXPECT_TRUE(msg_queue.WaitForMessage(&status)); 67 EXPECT_TRUE(msg_queue.WaitForMessage(&status));
69 EXPECT_STREQ(status.c_str(), expected_status.c_str()); 68 EXPECT_STREQ(status.c_str(), expected_status.c_str());
70 } 69 }
71 70
71 // Extension isolation prevents a normal renderer process from being able to
72 // create a "blob:chrome-extension://" resource.
72 IN_PROC_BROWSER_TEST_F(ChromeSecurityExploitBrowserTest, 73 IN_PROC_BROWSER_TEST_F(ChromeSecurityExploitBrowserTest,
73 CreateBlobInExtensionOrigin) { 74 CreateBlobInExtensionOrigin) {
74 // This test relies on extensions documents running in extension processes, 75 // This test relies on extensions documents running in extension processes,
75 // which is guaranteed with --isolate-extensions. Without it, the checks are 76 // which is guaranteed with --isolate-extensions. Without it, the checks are
76 // not enforced and this test will time out waiting for the process to be 77 // not enforced and this test will time out waiting for the process to be
77 // killed. 78 // killed.
78 if (!extensions::IsIsolateExtensionsEnabled()) 79 if (!extensions::IsIsolateExtensionsEnabled())
79 return; 80 return;
80 81
81 ui_test_utils::NavigateToURL( 82 ui_test_utils::NavigateToURL(
82 browser(), 83 browser(),
83 embedded_test_server()->GetURL("a.root-servers.net", "/title1.html")); 84 embedded_test_server()->GetURL("a.root-servers.net", "/title1.html"));
84 85
85 content::RenderFrameHost* rfh = 86 content::RenderFrameHost* rfh =
86 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(); 87 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame();
87 88
88 // All these are attacker controlled values. The UUID is arbitrary. 89 // All these are attacker controlled values. The UUID is arbitrary.
89 std::string blob_id = "2ce53a26-0409-45a3-86e5-f8fb9f5566d8"; 90 std::string blob_id = "2ce53a26-0409-45a3-86e5-f8fb9f5566d8";
90 std::string blob_type = "text/html"; 91 std::string blob_type = "text/html";
91 std::string blob_contents = "<script>chrome.extensions</script>"; 92 std::string blob_contents = "<script>chrome.extensions</script>";
92 std::string blob_path = "5881f76e-10d2-410d-8c61-ef210502acfd"; 93 std::string blob_path = "5881f76e-10d2-410d-8c61-ef210502acfd";
93 94
94 // Target the bookmark manager extension. 95 // Target the bookmark manager extension.
95 std::string target_origin = 96 std::string target_origin =
96 "chrome-extension://eemcgdkfndhakfknompkggombfjjjeno"; 97 "chrome-extension://eemcgdkfndhakfknompkggombfjjjeno";
97 98
98 std::vector<storage::DataElement> data_elements(1);
99 data_elements[0].SetToBytes(blob_contents.c_str(), blob_contents.size());
100
101 // Set up a blob ID and populate it with attacker-controlled value. This 99 // Set up a blob ID and populate it with attacker-controlled value. This
102 // message is allowed, because this data is not in any origin. 100 // message is allowed, because this data is not in any origin.
103 IPC::IpcSecurityTestUtil::PwnMessageReceived( 101 content::PwnMessageHelper::CreateBlobWithPayload(
104 rfh->GetProcess()->GetChannel(), 102 rfh->GetProcess(), blob_id, blob_type, "", blob_contents);
105 BlobStorageMsg_RegisterBlob(blob_id, blob_type, "", data_elements));
106 103
107 // This IPC should result in a kill because |target_origin| is not commitable 104 // This IPC should result in a kill because |target_origin| is not commitable
108 // in |rfh->GetProcess()|. 105 // in |rfh->GetProcess()|.
106 base::HistogramTester histograms;
109 content::RenderProcessHostWatcher crash_observer( 107 content::RenderProcessHostWatcher crash_observer(
110 rfh->GetProcess(), 108 rfh->GetProcess(),
111 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); 109 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
112 IPC::IpcSecurityTestUtil::PwnMessageReceived( 110
113 rfh->GetProcess()->GetChannel(), 111 content::PwnMessageHelper::RegisterBlobURL(
114 BlobHostMsg_RegisterPublicURL( 112 rfh->GetProcess(), GURL("blob:" + target_origin + "/" + blob_path),
115 GURL("blob:" + target_origin + "/" + blob_path), blob_id)); 113 blob_id);
116 crash_observer.Wait(); // If the process is killed, this test passes. 114
115 // If the process is killed, this test passes.
116 crash_observer.Wait();
117 histograms.ExpectUniqueSample("Stability.BadMessageTerminated.Content", 139,
118 1);
117 } 119 }
120
121 // Extension isolation prevents a normal renderer process from being able to
122 // create a "filesystem:chrome-extension://sdgkjaghsdg/temporary/" resource.
123 IN_PROC_BROWSER_TEST_F(ChromeSecurityExploitBrowserTest,
124 CreateFilesystemURLInExtensionOrigin) {
125 GURL page_url =
126 embedded_test_server()->GetURL("a.root-servers.net", "/title1.html");
127 ui_test_utils::NavigateToURL(browser(), page_url);
128
129 content::RenderFrameHost* rfh =
130 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame();
131
132 // Block the renderer on operation that never completes, to shield it from
133 // receiving unexpected browser->renderer IPCs that might CHECK.
134 rfh->ExecuteJavaScriptWithUserGestureForTests(
135 base::ASCIIToUTF16("var r = new XMLHttpRequest();"
136 "r.open('GET', '/slow?99999', false);"
137 "r.send(null);"
138 "while (1);"));
139
140 // JS code that the attacker would like to run in an extension process.
141 std::string payload = "<html><body>pwned.</body></html>";
142 std::string payload_type = "text/html";
143
144 // Target the bookmark manager extension.
145 std::string target_origin =
146 "chrome-extension://eemcgdkfndhakfknompkggombfjjjeno/";
147
148 // Set up a blob ID and populate it with the attacker-controlled payload.
149 // This is allowed, because this data is not in any origin;
150 // the UUID is arbitrary.
151 std::string blob_id = "2ce53a26-0409-45a3-86e5-f8fb9f5566d8";
152 content::PwnMessageHelper::CreateBlobWithPayload(rfh->GetProcess(), blob_id,
153 payload_type, "", payload);
154
155 // Note: a well-behaved renderer would always send the following message here,
156 // but it's actually not necessary for the original attack to succeed, so we
157 // omit it. As a result there are some log warnings from the quota observer.
158 //
159 // IPC::IpcSecurityTestUtil::PwnMessageReceived(
160 // rfh->GetProcess()->GetChannel(),
161 // FileSystemHostMsg_OpenFileSystem(22, GURL(target_origin),
162 // storage::kFileSystemTypeTemporary));
163
164 GURL target_url =
165 GURL("filesystem:" + target_origin + "temporary/exploit.html");
166
167 content::PwnMessageHelper::FileSystemCreate(rfh->GetProcess(), 23, target_url,
168 false, false, false);
169
170 // Write the blob into the file. If successful, this places an
171 // attacker-controlled value in a resource on the extension origin.
172 content::PwnMessageHelper::FileSystemWrite(rfh->GetProcess(), 24, target_url,
173 blob_id, 0);
174
175 // Now navigate to |target_url| in a new tab. It should not contain |payload|.
176 AddTabAtIndex(0, target_url, ui::PAGE_TRANSITION_TYPED);
177 content::WaitForLoadStop(browser()->tab_strip_model()->GetWebContentsAt(0));
178 rfh = browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame();
179 EXPECT_EQ(GURL(target_origin), rfh->GetSiteInstance()->GetSiteURL());
180 std::string body;
181 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
182 rfh, "window.domAutomationController.send(document.body.innerText);",
183 &body));
184 if (extensions::IsIsolateExtensionsEnabled()) {
185 EXPECT_EQ(
186 "\nYour file was not found\n\n"
187 "It may have been moved or deleted.\n"
188 "ERR_FILE_NOT_FOUND\n",
189 body);
190 } else {
191 // Without --isolate-extensions, the above steps must succeed, since
192 // unblessed extension frames are allowed in ordinary renderer processes.
193 EXPECT_EQ("pwned.", body);
194 }
195 }
OLDNEW
« no previous file with comments | « chrome/browser/DEPS ('k') | content/browser/fileapi/mock_file_update_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698