[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame^] | 5 | #include <stdint.h> |
| 6 | |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 8 | #include "base/containers/hash_tables.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame^] | 9 | #include "base/macros.h" |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 10 | #include "base/strings/utf_string_conversions.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame^] | 11 | #include "build/build_config.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 12 | #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
| 13 | #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 14 | #include "content/browser/frame_host/navigator.h" |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 15 | #include "content/browser/frame_host/render_frame_host_impl.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 16 | #include "content/browser/renderer_host/render_view_host_factory.h" |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 17 | #include "content/browser/renderer_host/render_view_host_impl.h" |
| 18 | #include "content/browser/web_contents/web_contents_impl.h" |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 19 | #include "content/common/frame_messages.h" |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 20 | #include "content/common/resource_messages.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 21 | #include "content/common/view_messages.h" |
| 22 | #include "content/public/browser/browser_context.h" |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 23 | #include "content/public/browser/content_browser_client.h" |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 24 | #include "content/public/browser/interstitial_page.h" |
| 25 | #include "content/public/browser/interstitial_page_delegate.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 26 | #include "content/public/browser/storage_partition.h" |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 27 | #include "content/public/common/appcache_info.h" |
carlosk | d80262f5 | 2015-12-16 14:40:35 | [diff] [blame] | 28 | #include "content/public/common/browser_side_navigation_policy.h" |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 29 | #include "content/public/common/content_switches.h" |
wfh | 815c487 | 2015-02-25 21:01:31 | [diff] [blame] | 30 | #include "content/public/common/file_chooser_params.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 31 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 6e9def1 | 2014-03-27 20:23:28 | [diff] [blame] | 32 | #include "content/public/test/content_browser_test.h" |
| 33 | #include "content/public/test/content_browser_test_utils.h" |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 34 | #include "content/public/test/test_utils.h" |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 35 | #include "content/shell/browser/shell.h" |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 36 | #include "content/test/test_content_browser_client.h" |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 37 | #include "ipc/ipc_security_test_util.h" |
| 38 | #include "net/dns/mock_host_resolver.h" |
| 39 | #include "net/test/embedded_test_server/embedded_test_server.h" |
| 40 | |
| 41 | using IPC::IpcSecurityTestUtil; |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 42 | |
| 43 | namespace content { |
| 44 | |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 45 | namespace { |
| 46 | |
| 47 | // This is a helper function for the tests which attempt to create a |
| 48 | // duplicate RenderViewHost or RenderWidgetHost. It tries to create two objects |
| 49 | // with the same process and routing ids, which causes a collision. |
| 50 | // It creates a couple of windows in process 1, which causes a few routing ids |
| 51 | // to be allocated. Then a cross-process navigation is initiated, which causes a |
| 52 | // new process 2 to be created and have a pending RenderViewHost for it. The |
| 53 | // routing id of the RenderViewHost which is target for a duplicate is set |
| 54 | // into |target_routing_id| and the pending RenderViewHost which is used for |
| 55 | // the attempt is the return value. |
| 56 | RenderViewHostImpl* PrepareToDuplicateHosts(Shell* shell, |
| 57 | int* target_routing_id) { |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 58 | GURL foo("http://foo.com/simple_page.html"); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 59 | |
| 60 | // Start off with initial navigation, so we get the first process allocated. |
| 61 | NavigateToURL(shell, foo); |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 62 | EXPECT_EQ(base::ASCIIToUTF16("OK"), shell->web_contents()->GetTitle()); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 63 | |
| 64 | // Open another window, so we generate some more routing ids. |
| 65 | ShellAddedObserver shell2_observer; |
| 66 | EXPECT_TRUE(ExecuteScript( |
| 67 | shell->web_contents(), "window.open(document.URL + '#2');")); |
| 68 | Shell* shell2 = shell2_observer.GetShell(); |
| 69 | |
| 70 | // The new window must be in the same process, but have a new routing id. |
| 71 | EXPECT_EQ(shell->web_contents()->GetRenderViewHost()->GetProcess()->GetID(), |
| 72 | shell2->web_contents()->GetRenderViewHost()->GetProcess()->GetID()); |
| 73 | *target_routing_id = |
| 74 | shell2->web_contents()->GetRenderViewHost()->GetRoutingID(); |
| 75 | EXPECT_NE(*target_routing_id, |
| 76 | shell->web_contents()->GetRenderViewHost()->GetRoutingID()); |
| 77 | |
| 78 | // Now, simulate a link click coming from the renderer. |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 79 | GURL extension_url("https://bar.com/simple_page.html"); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 80 | WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell->web_contents()); |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 81 | wc->GetFrameTree()->root()->navigator()->RequestOpenURL( |
lfg | 9ef7d2d | 2014-12-15 22:32:30 | [diff] [blame] | 82 | wc->GetFrameTree()->root()->current_frame_host(), extension_url, nullptr, |
nick | 94144d4 | 2015-04-27 19:21:40 | [diff] [blame] | 83 | Referrer(), CURRENT_TAB, false, true); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 84 | |
| 85 | // Since the navigation above requires a cross-process swap, there will be a |
carlosk | c49005eb | 2015-06-16 11:25:07 | [diff] [blame] | 86 | // speculative/pending RenderFrameHost. Ensure it exists and is in a different |
| 87 | // process than the initial page. |
| 88 | RenderFrameHostImpl* next_rfh; |
carlosk | d80262f5 | 2015-12-16 14:40:35 | [diff] [blame] | 89 | if (IsBrowserSideNavigationEnabled()) |
| 90 | next_rfh = wc->GetRenderManagerForTesting()->speculative_frame_host(); |
| 91 | else |
carlosk | c49005eb | 2015-06-16 11:25:07 | [diff] [blame] | 92 | next_rfh = wc->GetRenderManagerForTesting()->pending_frame_host(); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 93 | |
carlosk | c49005eb | 2015-06-16 11:25:07 | [diff] [blame] | 94 | EXPECT_TRUE(next_rfh); |
| 95 | EXPECT_NE(shell->web_contents()->GetRenderProcessHost()->GetID(), |
| 96 | next_rfh->GetProcess()->GetID()); |
| 97 | |
| 98 | return next_rfh->render_view_host(); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 99 | } |
| 100 | |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 101 | ResourceHostMsg_Request CreateXHRRequestWithOrigin(const char* origin) { |
| 102 | ResourceHostMsg_Request request; |
| 103 | request.method = "GET"; |
| 104 | request.url = GURL("http://bar.com/simple_page.html"); |
| 105 | request.first_party_for_cookies = GURL(origin); |
| 106 | request.referrer_policy = blink::WebReferrerPolicyDefault; |
| 107 | request.headers = base::StringPrintf("Origin: %s\r\n", origin); |
| 108 | request.load_flags = 0; |
| 109 | request.origin_pid = 0; |
| 110 | request.resource_type = RESOURCE_TYPE_XHR; |
| 111 | request.request_context = 0; |
| 112 | request.appcache_host_id = kAppCacheNoHostId; |
| 113 | request.download_to_file = false; |
| 114 | request.should_reset_appcache = false; |
| 115 | request.is_main_frame = true; |
| 116 | request.parent_is_main_frame = false; |
| 117 | request.parent_render_frame_id = -1; |
| 118 | request.transition_type = ui::PAGE_TRANSITION_LINK; |
| 119 | request.allow_download = true; |
| 120 | return request; |
| 121 | } |
| 122 | |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 123 | } // namespace |
| 124 | |
| 125 | |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 126 | // The goal of these tests will be to "simulate" exploited renderer processes, |
| 127 | // which can send arbitrary IPC messages and confuse browser process internal |
| 128 | // state, leading to security bugs. We are trying to verify that the browser |
| 129 | // doesn't perform any dangerous operations in such cases. |
| 130 | class SecurityExploitBrowserTest : public ContentBrowserTest { |
| 131 | public: |
| 132 | SecurityExploitBrowserTest() {} |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 133 | |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 134 | void SetUpCommandLine(base::CommandLine* command_line) override { |
svaldez | c3a9a17 | 2015-11-03 22:01:33 | [diff] [blame] | 135 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 136 | |
| 137 | // Add a host resolver rule to map all outgoing requests to the test server. |
| 138 | // This allows us to use "real" hostnames in URLs, which we can use to |
| 139 | // create arbitrary SiteInstances. |
| 140 | command_line->AppendSwitchASCII( |
| 141 | switches::kHostResolverRules, |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 142 | "MAP * " + |
| 143 | net::HostPortPair::FromURL(embedded_test_server()->base_url()) |
| 144 | .ToString() + |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 145 | ",EXCLUDE localhost"); |
| 146 | } |
wfh | 815c487 | 2015-02-25 21:01:31 | [diff] [blame] | 147 | |
| 148 | protected: |
| 149 | // Tests that a given file path sent in a ViewHostMsg_RunFileChooser will |
| 150 | // cause renderer to be killed. |
| 151 | void TestFileChooserWithPath(const base::FilePath& path); |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 152 | }; |
| 153 | |
wfh | 815c487 | 2015-02-25 21:01:31 | [diff] [blame] | 154 | void SecurityExploitBrowserTest::TestFileChooserWithPath( |
| 155 | const base::FilePath& path) { |
| 156 | GURL foo("http://foo.com/simple_page.html"); |
| 157 | NavigateToURL(shell(), foo); |
| 158 | EXPECT_EQ(base::ASCIIToUTF16("OK"), shell()->web_contents()->GetTitle()); |
| 159 | |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 160 | RenderViewHost* compromised_renderer = |
wfh | 815c487 | 2015-02-25 21:01:31 | [diff] [blame] | 161 | shell()->web_contents()->GetRenderViewHost(); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 162 | RenderProcessHostWatcher terminated( |
wfh | 815c487 | 2015-02-25 21:01:31 | [diff] [blame] | 163 | shell()->web_contents(), |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 164 | RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
wfh | 815c487 | 2015-02-25 21:01:31 | [diff] [blame] | 165 | |
| 166 | FileChooserParams params; |
| 167 | params.default_file_name = path; |
| 168 | |
| 169 | ViewHostMsg_RunFileChooser evil(compromised_renderer->GetRoutingID(), params); |
| 170 | |
| 171 | IpcSecurityTestUtil::PwnMessageReceived( |
| 172 | compromised_renderer->GetProcess()->GetChannel(), evil); |
| 173 | terminated.Wait(); |
| 174 | } |
| 175 | |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 176 | // Ensure that we kill the renderer process if we try to give it WebUI |
| 177 | // properties and it doesn't have enabled WebUI bindings. |
jaekyun | 37e572a3 | 2014-12-04 23:33:35 | [diff] [blame] | 178 | IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, SetWebUIProperty) { |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 179 | GURL foo("http://foo.com/simple_page.html"); |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 180 | |
| 181 | NavigateToURL(shell(), foo); |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 182 | EXPECT_EQ(base::ASCIIToUTF16("OK"), shell()->web_contents()->GetTitle()); |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 183 | EXPECT_EQ(0, |
| 184 | shell()->web_contents()->GetRenderViewHost()->GetEnabledBindings()); |
| 185 | |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 186 | RenderProcessHostWatcher terminated( |
[email protected] | 8ffad4e | 2014-01-02 23:18:26 | [diff] [blame] | 187 | shell()->web_contents(), |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 188 | RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 189 | shell()->web_contents()->GetRenderViewHost()->SetWebUIProperty( |
| 190 | "toolkit", "views"); |
| 191 | terminated.Wait(); |
| 192 | } |
| 193 | |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 194 | // This is a test for crbug.com/312016 attempting to create duplicate |
| 195 | // RenderViewHosts. SetupForDuplicateHosts sets up this test case and leaves |
| 196 | // it in a state with pending RenderViewHost. Before the commit of the new |
| 197 | // pending RenderViewHost, this test case creates a new window through the new |
| 198 | // process. |
| 199 | IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, |
| 200 | AttemptDuplicateRenderViewHost) { |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 201 | int32_t duplicate_routing_id = MSG_ROUTING_NONE; |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 202 | RenderViewHostImpl* pending_rvh = |
| 203 | PrepareToDuplicateHosts(shell(), &duplicate_routing_id); |
| 204 | EXPECT_NE(MSG_ROUTING_NONE, duplicate_routing_id); |
| 205 | |
| 206 | // Since this test executes on the UI thread and hopping threads might cause |
| 207 | // different timing in the test, let's simulate a CreateNewWindow call coming |
| 208 | // from the IO thread. |
| 209 | ViewHostMsg_CreateWindow_Params params; |
| 210 | DOMStorageContextWrapper* dom_storage_context = |
| 211 | static_cast<DOMStorageContextWrapper*>( |
| 212 | BrowserContext::GetStoragePartition( |
| 213 | shell()->web_contents()->GetBrowserContext(), |
| 214 | pending_rvh->GetSiteInstance())->GetDOMStorageContext()); |
[email protected] | 4af62451 | 2013-12-13 14:58:43 | [diff] [blame] | 215 | scoped_refptr<SessionStorageNamespaceImpl> session_storage( |
| 216 | new SessionStorageNamespaceImpl(dom_storage_context)); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 217 | // Cause a deliberate collision in routing ids. |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 218 | int32_t main_frame_routing_id = duplicate_routing_id + 1; |
| 219 | // TODO(avi): This should be made unique from the view routing ID once |
| 220 | // RenderViewHostImpl has-a RenderWidgetHostImpl. https://crbug.com/545684 |
| 221 | int32_t main_frame_widget_routing_id = duplicate_routing_id; |
| 222 | pending_rvh->CreateNewWindow(duplicate_routing_id, main_frame_routing_id, |
| 223 | main_frame_widget_routing_id, params, |
dcheng | 54c3719d | 2014-08-26 21:52:56 | [diff] [blame] | 224 | session_storage.get()); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 225 | |
| 226 | // If the above operation doesn't cause a crash, the test has succeeded! |
[email protected] | 81374f2 | 2013-02-07 02:03:45 | [diff] [blame] | 227 | } |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 228 | |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 229 | // This is a test for crbug.com/312016. It tries to create two RenderWidgetHosts |
| 230 | // with the same process and routing ids, which causes a collision. It is almost |
| 231 | // identical to the AttemptDuplicateRenderViewHost test case. |
| 232 | IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, |
| 233 | AttemptDuplicateRenderWidgetHost) { |
| 234 | int duplicate_routing_id = MSG_ROUTING_NONE; |
| 235 | RenderViewHostImpl* pending_rvh = |
| 236 | PrepareToDuplicateHosts(shell(), &duplicate_routing_id); |
| 237 | EXPECT_NE(MSG_ROUTING_NONE, duplicate_routing_id); |
| 238 | |
| 239 | // Since this test executes on the UI thread and hopping threads might cause |
| 240 | // different timing in the test, let's simulate a CreateNewWidget call coming |
| 241 | // from the IO thread. Use the existing window routing id to cause a |
| 242 | // deliberate collision. |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame] | 243 | pending_rvh->CreateNewWidget(duplicate_routing_id, blink::WebPopupTypePage); |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 244 | |
| 245 | // If the above operation doesn't crash, the test has succeeded! |
| 246 | } |
| 247 | |
wfh | 815c487 | 2015-02-25 21:01:31 | [diff] [blame] | 248 | // This is a test for crbug.com/444198. It tries to send a |
| 249 | // ViewHostMsg_RunFileChooser containing an invalid path. The browser should |
| 250 | // correctly terminate the renderer in these cases. |
| 251 | IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, AttemptRunFileChoosers) { |
| 252 | TestFileChooserWithPath(base::FilePath(FILE_PATH_LITERAL("../../*.txt"))); |
| 253 | TestFileChooserWithPath(base::FilePath(FILE_PATH_LITERAL("/etc/*.conf"))); |
| 254 | #if defined(OS_WIN) |
| 255 | TestFileChooserWithPath( |
| 256 | base::FilePath(FILE_PATH_LITERAL("\\\\evilserver\\evilshare\\*.txt"))); |
| 257 | TestFileChooserWithPath(base::FilePath(FILE_PATH_LITERAL("c:\\*.txt"))); |
| 258 | TestFileChooserWithPath(base::FilePath(FILE_PATH_LITERAL("..\\..\\*.txt"))); |
| 259 | #endif |
| 260 | } |
| 261 | |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 262 | class SecurityExploitTestInterstitialPage : public InterstitialPageDelegate { |
| 263 | public: |
| 264 | explicit SecurityExploitTestInterstitialPage(WebContents* contents) { |
| 265 | InterstitialPage* interstitial = InterstitialPage::Create( |
| 266 | contents, true, contents->GetLastCommittedURL(), this); |
| 267 | interstitial->Show(); |
| 268 | } |
| 269 | |
| 270 | // InterstitialPageDelegate implementation. |
| 271 | void CommandReceived(const std::string& command) override { |
| 272 | last_command_ = command; |
| 273 | } |
| 274 | |
| 275 | std::string GetHTMLContents() override { |
| 276 | return "<html><head><script>" |
| 277 | "window.domAutomationController.setAutomationId(1);" |
| 278 | "window.domAutomationController.send(\"okay\");" |
| 279 | "</script></head>" |
| 280 | "<body>this page is an interstitial</body></html>"; |
| 281 | } |
| 282 | |
| 283 | std::string last_command() { return last_command_; } |
| 284 | |
| 285 | private: |
| 286 | std::string last_command_; |
| 287 | DISALLOW_COPY_AND_ASSIGN(SecurityExploitTestInterstitialPage); |
| 288 | }; |
| 289 | |
| 290 | // Fails due to InterstitialPage's reliance on PostNonNestableTask |
| 291 | // http://crbug.com/432737 |
| 292 | #if defined(OS_ANDROID) |
| 293 | #define MAYBE_InterstitialCommandFromUnderlyingContent \ |
| 294 | DISABLED_InterstitialCommandFromUnderlyingContent |
| 295 | #else |
| 296 | #define MAYBE_InterstitialCommandFromUnderlyingContent \ |
| 297 | InterstitialCommandFromUnderlyingContent |
| 298 | #endif |
| 299 | |
| 300 | // The interstitial should not be controllable by the underlying content. |
| 301 | IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, |
| 302 | MAYBE_InterstitialCommandFromUnderlyingContent) { |
| 303 | // Start off with initial navigation, to allocate the process. |
| 304 | GURL foo("http://foo.com/simple_page.html"); |
| 305 | NavigateToURL(shell(), foo); |
| 306 | EXPECT_EQ(base::ASCIIToUTF16("OK"), shell()->web_contents()->GetTitle()); |
| 307 | |
| 308 | DOMMessageQueue message_queue; |
| 309 | |
| 310 | // Install and show an interstitial page. |
| 311 | SecurityExploitTestInterstitialPage* interstitial = |
| 312 | new SecurityExploitTestInterstitialPage(shell()->web_contents()); |
| 313 | |
| 314 | ASSERT_EQ("", interstitial->last_command()); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 315 | WaitForInterstitialAttach(shell()->web_contents()); |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 316 | |
| 317 | InterstitialPage* interstitial_page = |
| 318 | shell()->web_contents()->GetInterstitialPage(); |
| 319 | ASSERT_TRUE(interstitial_page != NULL); |
| 320 | ASSERT_TRUE(shell()->web_contents()->ShowingInterstitialPage()); |
| 321 | ASSERT_TRUE(interstitial_page->GetDelegateForTesting() == interstitial); |
| 322 | |
| 323 | // The interstitial page ought to be able to send a message. |
| 324 | std::string message; |
| 325 | ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 326 | ASSERT_EQ("\"okay\"", message); |
| 327 | ASSERT_EQ("\"okay\"", interstitial->last_command()); |
| 328 | |
| 329 | // Send an automation message from the underlying content and wait for it to |
| 330 | // be dispatched on this thread. This message should not be received by the |
| 331 | // interstitial. |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 332 | RenderFrameHost* compromised_renderer = |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 333 | shell()->web_contents()->GetMainFrame(); |
| 334 | FrameHostMsg_DomOperationResponse evil(compromised_renderer->GetRoutingID(), |
avi | 60bd490 | 2015-09-23 20:39:24 | [diff] [blame] | 335 | "evil"); |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 336 | IpcSecurityTestUtil::PwnMessageReceived( |
| 337 | compromised_renderer->GetProcess()->GetChannel(), evil); |
| 338 | |
| 339 | ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 340 | ASSERT_EQ("evil", message) |
| 341 | << "Automation message should be received by WebContents."; |
| 342 | ASSERT_EQ("\"okay\"", interstitial->last_command()) |
| 343 | << "Interstitial should not be affected."; |
| 344 | |
| 345 | // Send a second message from the interstitial page, and make sure that the |
| 346 | // "evil" message doesn't arrive in the intervening period. |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 347 | ASSERT_TRUE(ExecuteScript(interstitial_page->GetMainFrame(), |
| 348 | "window.domAutomationController.send(\"okay2\");")); |
nick | 4c8dfd4 | 2014-11-14 04:11:49 | [diff] [blame] | 349 | ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 350 | ASSERT_EQ("\"okay2\"", message); |
| 351 | ASSERT_EQ("\"okay2\"", interstitial->last_command()); |
| 352 | } |
| 353 | |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 354 | class IsolatedAppContentBrowserClient : public TestContentBrowserClient { |
| 355 | public: |
| 356 | bool IsIllegalOrigin(content::ResourceContext* resource_context, |
| 357 | int child_process_id, |
| 358 | const GURL& origin) override { |
| 359 | // Simulate a case where an app origin is not in an app process. |
| 360 | return true; |
| 361 | } |
| 362 | }; |
| 363 | |
| 364 | // Renderer processes should not be able to spoof Origin HTTP headers. |
| 365 | IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, InvalidOriginHeaders) { |
| 366 | // Create a set of IPC messages with various Origin headers. |
| 367 | ResourceHostMsg_Request chrome_origin_msg( |
| 368 | CreateXHRRequestWithOrigin("chrome://settings")); |
| 369 | ResourceHostMsg_Request embedder_isolated_origin_msg( |
| 370 | CreateXHRRequestWithOrigin("https://isolated.bar.com")); |
| 371 | ResourceHostMsg_Request invalid_origin_msg( |
| 372 | CreateXHRRequestWithOrigin("invalidurl")); |
| 373 | ResourceHostMsg_Request invalid_scheme_origin_msg( |
| 374 | CreateXHRRequestWithOrigin("fake-scheme://foo")); |
| 375 | |
| 376 | GURL web_url("http://foo.com/simple_page.html"); |
| 377 | NavigateToURL(shell(), web_url); |
| 378 | RenderFrameHost* web_rfh = shell()->web_contents()->GetMainFrame(); |
| 379 | |
| 380 | // Web processes cannot make XHRs with chrome:// Origin headers. |
| 381 | { |
| 382 | RenderProcessHostWatcher web_process_killed( |
| 383 | web_rfh->GetProcess(), |
| 384 | RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 385 | IPC::IpcSecurityTestUtil::PwnMessageReceived( |
| 386 | web_rfh->GetProcess()->GetChannel(), |
| 387 | ResourceHostMsg_RequestResource(web_rfh->GetRoutingID(), 1, |
| 388 | chrome_origin_msg)); |
| 389 | web_process_killed.Wait(); |
| 390 | } |
| 391 | |
| 392 | // Web processes cannot make XHRs with URLs that the content embedder expects |
| 393 | // to have process isolation. Ideally this would test chrome-extension:// |
| 394 | // URLs for Chrome Apps, but those can't be tested inside content/ and the |
| 395 | // ResourceHostMsg_Request IPC can't be created in a test outside content/. |
| 396 | NavigateToURL(shell(), web_url); |
| 397 | { |
| 398 | // Set up a ContentBrowserClient that simulates an app URL in a non-app |
| 399 | // process. |
| 400 | IsolatedAppContentBrowserClient app_client; |
| 401 | ContentBrowserClient* old_client = SetBrowserClientForTesting(&app_client); |
| 402 | RenderProcessHostWatcher web_process_killed( |
| 403 | web_rfh->GetProcess(), |
| 404 | RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 405 | IPC::IpcSecurityTestUtil::PwnMessageReceived( |
| 406 | web_rfh->GetProcess()->GetChannel(), |
| 407 | ResourceHostMsg_RequestResource(web_rfh->GetRoutingID(), 1, |
| 408 | embedder_isolated_origin_msg)); |
| 409 | web_process_killed.Wait(); |
| 410 | SetBrowserClientForTesting(old_client); |
| 411 | } |
| 412 | |
| 413 | // Web processes cannot make XHRs with invalid Origin headers. |
| 414 | NavigateToURL(shell(), web_url); |
| 415 | { |
| 416 | RenderProcessHostWatcher web_process_killed( |
| 417 | web_rfh->GetProcess(), |
| 418 | RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 419 | IPC::IpcSecurityTestUtil::PwnMessageReceived( |
| 420 | web_rfh->GetProcess()->GetChannel(), |
| 421 | ResourceHostMsg_RequestResource(web_rfh->GetRoutingID(), 1, |
| 422 | invalid_origin_msg)); |
| 423 | web_process_killed.Wait(); |
| 424 | } |
| 425 | |
| 426 | // Web processes cannot make XHRs with invalid scheme Origin headers. |
| 427 | NavigateToURL(shell(), web_url); |
| 428 | { |
| 429 | RenderProcessHostWatcher web_process_killed( |
| 430 | web_rfh->GetProcess(), |
| 431 | RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 432 | IPC::IpcSecurityTestUtil::PwnMessageReceived( |
| 433 | web_rfh->GetProcess()->GetChannel(), |
| 434 | ResourceHostMsg_RequestResource(web_rfh->GetRoutingID(), 1, |
| 435 | invalid_scheme_origin_msg)); |
| 436 | web_process_killed.Wait(); |
| 437 | } |
| 438 | } |
| 439 | |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 440 | } // namespace content |