Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/strings/pattern.h" | 6 #include "base/strings/pattern.h" |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
| 10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
| 11 #include "content/public/common/resource_type.h" | 11 #include "content/public/common/resource_type.h" |
| 12 #include "content/public/test/browser_test_utils.h" | 12 #include "content/public/test/browser_test_utils.h" |
| 13 #include "content/public/test/content_browser_test.h" | 13 #include "content/public/test/content_browser_test.h" |
| 14 #include "content/public/test/content_browser_test_utils.h" | 14 #include "content/public/test/content_browser_test_utils.h" |
| 15 #include "content/shell/browser/shell.h" | 15 #include "content/shell/browser/shell.h" |
|
mmenke
2015/11/03 19:12:57
include embedded_test_server.h
svaldez
2015/11/03 19:33:16
Done.
| |
| 16 #include "net/test/spawned_test_server/spawned_test_server.h" | |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 18 | 17 |
| 19 namespace content { | 18 namespace content { |
| 20 | 19 |
| 21 // These tests simulate exploited renderer processes, which can fetch arbitrary | 20 // These tests simulate exploited renderer processes, which can fetch arbitrary |
| 22 // resources from other websites, not constrained by the Same Origin Policy. We | 21 // resources from other websites, not constrained by the Same Origin Policy. We |
| 23 // are trying to verify that the renderer cannot fetch any cross-site document | 22 // are trying to verify that the renderer cannot fetch any cross-site document |
| 24 // responses even when the Same Origin Policy is turned off inside the renderer. | 23 // responses even when the Same Origin Policy is turned off inside the renderer. |
| 25 class SiteIsolationStatsGathererBrowserTest : public ContentBrowserTest { | 24 class SiteIsolationStatsGathererBrowserTest : public ContentBrowserTest { |
| 26 public: | 25 public: |
| 27 SiteIsolationStatsGathererBrowserTest() {} | 26 SiteIsolationStatsGathererBrowserTest() {} |
| 28 ~SiteIsolationStatsGathererBrowserTest() override {} | 27 ~SiteIsolationStatsGathererBrowserTest() override {} |
| 29 | 28 |
| 30 void SetUpCommandLine(base::CommandLine* command_line) override { | 29 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 31 ASSERT_TRUE(test_server()->Start()); | 30 ASSERT_TRUE(embedded_test_server()->Start()); |
| 32 // Add a host resolver rule to map all outgoing requests to the test server. | 31 // Add a host resolver rule to map all outgoing requests to the test server. |
| 33 // This allows us to use "real" hostnames in URLs, which we can use to | 32 // This allows us to use "real" hostnames in URLs, which we can use to |
| 34 // create arbitrary SiteInstances. | 33 // create arbitrary SiteInstances. |
| 35 command_line->AppendSwitchASCII( | 34 command_line->AppendSwitchASCII( |
| 36 switches::kHostResolverRules, | 35 switches::kHostResolverRules, |
| 37 "MAP * " + test_server()->host_port_pair().ToString() + | 36 "MAP * " + embedded_test_server()->host_port_pair().ToString() + |
| 38 ",EXCLUDE localhost"); | 37 ",EXCLUDE localhost"); |
| 39 | 38 |
| 40 // Since we assume exploited renderer process, it can bypass the same origin | 39 // Since we assume exploited renderer process, it can bypass the same origin |
| 41 // policy at will. Simulate that by passing the disable-web-security flag. | 40 // policy at will. Simulate that by passing the disable-web-security flag. |
| 42 command_line->AppendSwitch(switches::kDisableWebSecurity); | 41 command_line->AppendSwitch(switches::kDisableWebSecurity); |
| 43 } | 42 } |
| 44 | 43 |
| 45 void InspectHistograms(const base::HistogramTester& histograms, | 44 void InspectHistograms(const base::HistogramTester& histograms, |
| 46 bool should_be_blocked, | 45 bool should_be_blocked, |
| 47 const std::string& resource_name) { | 46 const std::string& resource_name) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 histograms.GetAllSamples(base + ".Blocked.RenderableStatusCode"), | 104 histograms.GetAllSamples(base + ".Blocked.RenderableStatusCode"), |
| 106 testing::ElementsAre(base::Bucket(RESOURCE_TYPE_XHR, 1))) | 105 testing::ElementsAre(base::Bucket(RESOURCE_TYPE_XHR, 1))) |
| 107 << "The wrong RenderableStatusCode bucket was incremented."; | 106 << "The wrong RenderableStatusCode bucket was incremented."; |
| 108 } | 107 } |
| 109 } | 108 } |
| 110 | 109 |
| 111 private: | 110 private: |
| 112 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGathererBrowserTest); | 111 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGathererBrowserTest); |
| 113 }; | 112 }; |
| 114 | 113 |
| 115 // TODO(dsjang): we cannot run these tests on Android since SetUpCommandLine() | |
| 116 // is executed before the I/O thread is created on Android. After this bug | |
| 117 // (crbug.com/278425) is resolved, we can enable this test case on Android. | |
| 118 #if defined(OS_ANDROID) | |
| 119 #define MAYBE_CrossSiteDocumentBlockingForMimeType \ | |
| 120 DISABLED_CrossSiteDocumentBlockingForMimeType | |
| 121 #else | |
| 122 #define MAYBE_CrossSiteDocumentBlockingForMimeType \ | |
| 123 CrossSiteDocumentBlockingForMimeType | |
| 124 #endif | |
| 125 | |
| 126 IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest, | 114 IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest, |
| 127 MAYBE_CrossSiteDocumentBlockingForMimeType) { | 115 CrossSiteDocumentBlockingForMimeType) { |
| 128 // Load a page that issues illegal cross-site document requests to bar.com. | 116 // Load a page that issues illegal cross-site document requests to bar.com. |
| 129 // The page uses XHR to request HTML/XML/JSON documents from bar.com, and | 117 // The page uses XHR to request HTML/XML/JSON documents from bar.com, and |
| 130 // inspects if any of them were successfully received. Currently, on illegal | 118 // inspects if any of them were successfully received. Currently, on illegal |
| 131 // access, the XHR requests should succeed, but the UMA histograms should | 119 // access, the XHR requests should succeed, but the UMA histograms should |
| 132 // record that they would have been blocked. This test is only possible since | 120 // record that they would have been blocked. This test is only possible since |
| 133 // we run the browser without the same origin policy. | 121 // we run the browser without the same origin policy. |
| 134 GURL foo("http://foo.com/files/cross_site_document_request.html"); | 122 GURL foo("http://foo.com/cross_site_document_request.html"); |
| 135 | 123 |
| 136 NavigateToURL(shell(), foo); | 124 NavigateToURL(shell(), foo); |
| 137 | 125 |
| 138 // Flush out existing histogram activity. | 126 // Flush out existing histogram activity. |
| 139 FetchHistogramsFromChildProcesses(); | 127 FetchHistogramsFromChildProcesses(); |
| 140 | 128 |
| 141 // The following are files under content/test/data/site_isolation. All | 129 // The following are files under content/test/data/site_isolation. All |
| 142 // should be disallowed for cross site XHR under the document blocking policy. | 130 // should be disallowed for cross site XHR under the document blocking policy. |
| 143 const char* blocked_resources[] = { | 131 const char* blocked_resources[] = { |
| 144 "comment_valid.html", | 132 "comment_valid.html", |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 bool was_blocked; | 173 bool was_blocked; |
| 186 ASSERT_TRUE(ExecuteScriptAndExtractBool( | 174 ASSERT_TRUE(ExecuteScriptAndExtractBool( |
| 187 shell()->web_contents(), | 175 shell()->web_contents(), |
| 188 base::StringPrintf("sendRequest(\"%s\");", resource), &was_blocked)); | 176 base::StringPrintf("sendRequest(\"%s\");", resource), &was_blocked)); |
| 189 ASSERT_FALSE(was_blocked); | 177 ASSERT_FALSE(was_blocked); |
| 190 | 178 |
| 191 InspectHistograms(histograms, false, resource); | 179 InspectHistograms(histograms, false, resource); |
| 192 } | 180 } |
| 193 } | 181 } |
| 194 | 182 |
| 195 // TODO(dsjang): we cannot run these tests on Android since SetUpCommandLine() | |
| 196 // is executed before the I/O thread is created on Android. After this bug | |
| 197 // (crbug.com/278425) is resolved, we can enable this test case on Android. | |
| 198 #if defined(OS_ANDROID) | |
| 199 #define MAYBE_CrossSiteDocumentBlockingForDifferentTargets \ | |
| 200 DISABLED_CrossSiteDocumentBlockingForDifferentTargets | |
| 201 #else | |
| 202 #define MAYBE_CrossSiteDocumentBlockingForDifferentTargets \ | |
| 203 CrossSiteDocumentBlockingForDifferentTargets | |
| 204 #endif | |
| 205 | |
| 206 IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest, | 183 IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest, |
| 207 MAYBE_CrossSiteDocumentBlockingForDifferentTargets) { | 184 CrossSiteDocumentBlockingForDifferentTargets) { |
| 208 // This webpage loads a cross-site HTML page in different targets such as | 185 // This webpage loads a cross-site HTML page in different targets such as |
| 209 // <img>,<link>,<embed>, etc. Since the requested document is blocked, and one | 186 // <img>,<link>,<embed>, etc. Since the requested document is blocked, and one |
| 210 // character string (' ') is returned instead, this tests that the renderer | 187 // character string (' ') is returned instead, this tests that the renderer |
| 211 // does not crash even when it receives a response body which is " ", whose | 188 // does not crash even when it receives a response body which is " ", whose |
| 212 // length is different from what's described in "content-length" for such | 189 // length is different from what's described in "content-length" for such |
| 213 // different targets. | 190 // different targets. |
| 214 | 191 |
| 215 // TODO(nick): Split up these cases, and add positive assertions here about | 192 // TODO(nick): Split up these cases, and add positive assertions here about |
| 216 // what actually happens in these various resource-block cases. | 193 // what actually happens in these various resource-block cases. |
| 217 GURL foo("http://foo.com/files/cross_site_document_request_target.html"); | 194 GURL foo("http://foo.com/cross_site_document_request_target.html"); |
| 218 NavigateToURL(shell(), foo); | 195 NavigateToURL(shell(), foo); |
| 219 } | 196 } |
| 220 | 197 |
| 221 } // namespace content | 198 } // namespace content |
| OLD | NEW |