Chromium Code Reviews| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/containers/hash_tables.h" | 6 #include "base/containers/hash_tables.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" | 8 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
| 9 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | 9 #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
| 10 #include "content/browser/frame_host/navigator.h" | 10 #include "content/browser/frame_host/navigator.h" |
| 11 #include "content/browser/renderer_host/render_view_host_factory.h" | 11 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 12 #include "content/browser/renderer_host/render_view_host_impl.h" | 12 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 13 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
| 14 #include "content/common/frame_messages.h" | 14 #include "content/common/frame_messages.h" |
| 15 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
| 16 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/interstitial_page.h" | 17 #include "content/public/browser/interstitial_page.h" |
| 18 #include "content/public/browser/interstitial_page_delegate.h" | 18 #include "content/public/browser/interstitial_page_delegate.h" |
| 19 #include "content/public/browser/storage_partition.h" | 19 #include "content/public/browser/storage_partition.h" |
| 20 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| 21 #include "content/public/common/file_chooser_params.h" | |
| 21 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
| 22 #include "content/public/test/content_browser_test.h" | 23 #include "content/public/test/content_browser_test.h" |
| 23 #include "content/public/test/content_browser_test_utils.h" | 24 #include "content/public/test/content_browser_test_utils.h" |
| 24 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
| 25 #include "content/shell/browser/shell.h" | 26 #include "content/shell/browser/shell.h" |
| 26 #include "ipc/ipc_security_test_util.h" | 27 #include "ipc/ipc_security_test_util.h" |
| 27 #include "net/dns/mock_host_resolver.h" | 28 #include "net/dns/mock_host_resolver.h" |
| 28 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 29 | 30 |
| 30 using IPC::IpcSecurityTestUtil; | 31 using IPC::IpcSecurityTestUtil; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 // Add a host resolver rule to map all outgoing requests to the test server. | 101 // Add a host resolver rule to map all outgoing requests to the test server. |
| 101 // This allows us to use "real" hostnames in URLs, which we can use to | 102 // This allows us to use "real" hostnames in URLs, which we can use to |
| 102 // create arbitrary SiteInstances. | 103 // create arbitrary SiteInstances. |
| 103 command_line->AppendSwitchASCII( | 104 command_line->AppendSwitchASCII( |
| 104 switches::kHostResolverRules, | 105 switches::kHostResolverRules, |
| 105 "MAP * " + | 106 "MAP * " + |
| 106 net::HostPortPair::FromURL(embedded_test_server()->base_url()) | 107 net::HostPortPair::FromURL(embedded_test_server()->base_url()) |
| 107 .ToString() + | 108 .ToString() + |
| 108 ",EXCLUDE localhost"); | 109 ",EXCLUDE localhost"); |
| 109 } | 110 } |
| 111 | |
| 112 protected: | |
| 113 // Tests that a given file path sent in a ViewHostMsg_RunFileChooser will | |
| 114 // cause renderer to be killed. | |
| 115 void TestFileChooserWithPath(const base::FilePath& path); | |
| 110 }; | 116 }; |
| 111 | 117 |
| 118 void SecurityExploitBrowserTest::TestFileChooserWithPath( | |
| 119 const base::FilePath& path) { | |
| 120 GURL foo("http://foo.com/simple_page.html"); | |
|
nasko
2015/02/25 15:14:45
This seems like simple enough test that it should
| |
| 121 NavigateToURL(shell(), foo); | |
| 122 EXPECT_EQ(base::ASCIIToUTF16("OK"), shell()->web_contents()->GetTitle()); | |
| 123 | |
| 124 content::RenderViewHost* compromised_renderer = | |
| 125 shell()->web_contents()->GetRenderViewHost(); | |
| 126 content::RenderProcessHostWatcher terminated( | |
| 127 shell()->web_contents(), | |
| 128 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | |
| 129 | |
| 130 FileChooserParams params; | |
| 131 params.default_file_name = path; | |
| 132 | |
| 133 ViewHostMsg_RunFileChooser evil(compromised_renderer->GetRoutingID(), params); | |
| 134 | |
| 135 IpcSecurityTestUtil::PwnMessageReceived( | |
| 136 compromised_renderer->GetProcess()->GetChannel(), evil); | |
| 137 terminated.Wait(); | |
| 138 } | |
| 139 | |
| 112 // Ensure that we kill the renderer process if we try to give it WebUI | 140 // Ensure that we kill the renderer process if we try to give it WebUI |
| 113 // properties and it doesn't have enabled WebUI bindings. | 141 // properties and it doesn't have enabled WebUI bindings. |
| 114 IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, SetWebUIProperty) { | 142 IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, SetWebUIProperty) { |
| 115 GURL foo("http://foo.com/simple_page.html"); | 143 GURL foo("http://foo.com/simple_page.html"); |
| 116 | 144 |
| 117 NavigateToURL(shell(), foo); | 145 NavigateToURL(shell(), foo); |
| 118 EXPECT_EQ(base::ASCIIToUTF16("OK"), shell()->web_contents()->GetTitle()); | 146 EXPECT_EQ(base::ASCIIToUTF16("OK"), shell()->web_contents()->GetTitle()); |
| 119 EXPECT_EQ(0, | 147 EXPECT_EQ(0, |
| 120 shell()->web_contents()->GetRenderViewHost()->GetEnabledBindings()); | 148 shell()->web_contents()->GetRenderViewHost()->GetEnabledBindings()); |
| 121 | 149 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 | 200 |
| 173 // Since this test executes on the UI thread and hopping threads might cause | 201 // Since this test executes on the UI thread and hopping threads might cause |
| 174 // different timing in the test, let's simulate a CreateNewWidget call coming | 202 // different timing in the test, let's simulate a CreateNewWidget call coming |
| 175 // from the IO thread. Use the existing window routing id to cause a | 203 // from the IO thread. Use the existing window routing id to cause a |
| 176 // deliberate collision. | 204 // deliberate collision. |
| 177 pending_rvh->CreateNewWidget(duplicate_routing_id, blink::WebPopupTypeSelect); | 205 pending_rvh->CreateNewWidget(duplicate_routing_id, blink::WebPopupTypeSelect); |
| 178 | 206 |
| 179 // If the above operation doesn't crash, the test has succeeded! | 207 // If the above operation doesn't crash, the test has succeeded! |
| 180 } | 208 } |
| 181 | 209 |
| 210 // This is a test for crbug.com/444198. It tries to send a | |
| 211 // ViewHostMsg_RunFileChooser containing an invalid path. The browser should | |
| 212 // correctly terminate the renderer in these cases. | |
| 213 IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, AttemptRunFileChoosers) { | |
| 214 TestFileChooserWithPath(base::FilePath(FILE_PATH_LITERAL("../../*.txt"))); | |
| 215 TestFileChooserWithPath(base::FilePath(FILE_PATH_LITERAL("/etc/*.conf"))); | |
| 216 #if defined(OS_WIN) | |
| 217 TestFileChooserWithPath( | |
| 218 base::FilePath(FILE_PATH_LITERAL("\\\\evilserver\\evilshare\\*.txt"))); | |
| 219 TestFileChooserWithPath(base::FilePath(FILE_PATH_LITERAL("c:\\*.txt"))); | |
| 220 TestFileChooserWithPath(base::FilePath(FILE_PATH_LITERAL("..\\..\\*.txt"))); | |
| 221 #endif | |
| 222 } | |
| 223 | |
| 182 class SecurityExploitTestInterstitialPage : public InterstitialPageDelegate { | 224 class SecurityExploitTestInterstitialPage : public InterstitialPageDelegate { |
| 183 public: | 225 public: |
| 184 explicit SecurityExploitTestInterstitialPage(WebContents* contents) { | 226 explicit SecurityExploitTestInterstitialPage(WebContents* contents) { |
| 185 InterstitialPage* interstitial = InterstitialPage::Create( | 227 InterstitialPage* interstitial = InterstitialPage::Create( |
| 186 contents, true, contents->GetLastCommittedURL(), this); | 228 contents, true, contents->GetLastCommittedURL(), this); |
| 187 interstitial->Show(); | 229 interstitial->Show(); |
| 188 } | 230 } |
| 189 | 231 |
| 190 // InterstitialPageDelegate implementation. | 232 // InterstitialPageDelegate implementation. |
| 191 void CommandReceived(const std::string& command) override { | 233 void CommandReceived(const std::string& command) override { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 // "evil" message doesn't arrive in the intervening period. | 308 // "evil" message doesn't arrive in the intervening period. |
| 267 ASSERT_TRUE(content::ExecuteScript( | 309 ASSERT_TRUE(content::ExecuteScript( |
| 268 interstitial_page->GetMainFrame(), | 310 interstitial_page->GetMainFrame(), |
| 269 "window.domAutomationController.send(\"okay2\");")); | 311 "window.domAutomationController.send(\"okay2\");")); |
| 270 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 312 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 271 ASSERT_EQ("\"okay2\"", message); | 313 ASSERT_EQ("\"okay2\"", message); |
| 272 ASSERT_EQ("\"okay2\"", interstitial->last_command()); | 314 ASSERT_EQ("\"okay2\"", interstitial->last_command()); |
| 273 } | 315 } |
| 274 | 316 |
| 275 } // namespace content | 317 } // namespace content |
| OLD | NEW |