[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 5 | #include <set> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | #include <string> |
| 7 | |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 9 | #include "content/browser/child_process_security_policy_impl.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 10 | #include "content/public/common/url_constants.h" |
[email protected] | c6681f3 | 2012-06-05 14:43:01 | [diff] [blame] | 11 | #include "content/test/test_content_browser_client.h" |
pilgrim | e92c5fcd | 2014-09-10 23:31:23 | [diff] [blame] | 12 | #include "storage/browser/fileapi/file_permission_policy.h" |
| 13 | #include "storage/browser/fileapi/file_system_url.h" |
| 14 | #include "storage/browser/fileapi/isolated_context.h" |
pilgrim | 1633055 | 2014-09-10 01:32:22 | [diff] [blame] | 15 | #include "storage/common/fileapi/file_system_types.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 16 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 707e1c4 | 2013-07-09 21:18:58 | [diff] [blame] | 17 | #include "url/gurl.h" |
paulmeyer | 1eefa26e | 2015-10-01 02:11:13 | [diff] [blame] | 18 | #include "url/origin.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 20 | namespace content { |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 21 | namespace { |
| 22 | |
| 23 | const int kRendererID = 42; |
| 24 | const int kWorkerRendererID = kRendererID + 1; |
| 25 | |
[email protected] | f0ecca452 | 2013-01-07 21:50:56 | [diff] [blame] | 26 | #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 27 | #define TEST_PATH(x) FILE_PATH_LITERAL("c:") FILE_PATH_LITERAL(x) |
| 28 | #else |
| 29 | #define TEST_PATH(x) FILE_PATH_LITERAL(x) |
| 30 | #endif |
| 31 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 32 | class ChildProcessSecurityPolicyTestBrowserClient |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 33 | : public TestContentBrowserClient { |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 34 | public: |
| 35 | ChildProcessSecurityPolicyTestBrowserClient() {} |
| 36 | |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 37 | bool IsHandledURL(const GURL& url) override { |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 38 | return schemes_.find(url.scheme()) != schemes_.end(); |
[email protected] | e353940 | 2011-07-19 09:31:08 | [diff] [blame] | 39 | } |
| 40 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 41 | void ClearSchemes() { |
| 42 | schemes_.clear(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 43 | } |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 44 | |
| 45 | void AddScheme(const std::string& scheme) { |
| 46 | schemes_.insert(scheme); |
| 47 | } |
| 48 | |
| 49 | private: |
| 50 | std::set<std::string> schemes_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 51 | }; |
| 52 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 53 | } // namespace |
| 54 | |
| 55 | class ChildProcessSecurityPolicyTest : public testing::Test { |
| 56 | public: |
| 57 | ChildProcessSecurityPolicyTest() : old_browser_client_(NULL) { |
| 58 | } |
| 59 | |
dcheng | fa85b15 | 2014-10-28 01:13:42 | [diff] [blame] | 60 | void SetUp() override { |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 61 | old_browser_client_ = SetBrowserClientForTesting(&test_browser_client_); |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 62 | |
| 63 | // Claim to always handle chrome:// URLs because the CPSP's notion of |
| 64 | // allowing WebUI bindings is hard-wired to this particular scheme. |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 65 | test_browser_client_.AddScheme(kChromeUIScheme); |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 66 | |
| 67 | // Claim to always handle file:// URLs like the browser would. |
| 68 | // net::URLRequest::IsHandledURL() no longer claims support for default |
| 69 | // protocols as this is the responsibility of the browser (which is |
| 70 | // responsible for adding the appropriate ProtocolHandler). |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 71 | test_browser_client_.AddScheme(url::kFileScheme); |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 72 | } |
| 73 | |
dcheng | fa85b15 | 2014-10-28 01:13:42 | [diff] [blame] | 74 | void TearDown() override { |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 75 | test_browser_client_.ClearSchemes(); |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 76 | SetBrowserClientForTesting(old_browser_client_); |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | protected: |
| 80 | void RegisterTestScheme(const std::string& scheme) { |
| 81 | test_browser_client_.AddScheme(scheme); |
| 82 | } |
| 83 | |
[email protected] | bfcf1e9 | 2013-07-11 04:37:25 | [diff] [blame] | 84 | void GrantPermissionsForFile(ChildProcessSecurityPolicyImpl* p, |
| 85 | int child_id, |
| 86 | const base::FilePath& file, |
| 87 | int permissions) { |
| 88 | p->GrantPermissionsForFile(child_id, file, permissions); |
| 89 | } |
| 90 | |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 91 | void CheckHasNoFileSystemPermission(ChildProcessSecurityPolicyImpl* p, |
| 92 | const std::string& child_id) { |
| 93 | EXPECT_FALSE(p->CanReadFileSystem(kRendererID, child_id)); |
| 94 | EXPECT_FALSE(p->CanReadWriteFileSystem(kRendererID, child_id)); |
| 95 | EXPECT_FALSE(p->CanCopyIntoFileSystem(kRendererID, child_id)); |
| 96 | EXPECT_FALSE(p->CanDeleteFromFileSystem(kRendererID, child_id)); |
| 97 | } |
| 98 | |
| 99 | void CheckHasNoFileSystemFilePermission(ChildProcessSecurityPolicyImpl* p, |
| 100 | const base::FilePath& file, |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 101 | const storage::FileSystemURL& url) { |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 102 | EXPECT_FALSE(p->CanReadFile(kRendererID, file)); |
| 103 | EXPECT_FALSE(p->CanCreateReadWriteFile(kRendererID, file)); |
| 104 | EXPECT_FALSE(p->CanReadFileSystemFile(kRendererID, url)); |
| 105 | EXPECT_FALSE(p->CanWriteFileSystemFile(kRendererID, url)); |
| 106 | EXPECT_FALSE(p->CanCreateFileSystemFile(kRendererID, url)); |
| 107 | EXPECT_FALSE(p->CanCreateReadWriteFileSystemFile(kRendererID, url)); |
| 108 | EXPECT_FALSE(p->CanCopyIntoFileSystemFile(kRendererID, url)); |
| 109 | EXPECT_FALSE(p->CanDeleteFileSystemFile(kRendererID, url)); |
| 110 | } |
| 111 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 112 | private: |
| 113 | ChildProcessSecurityPolicyTestBrowserClient test_browser_client_; |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 114 | ContentBrowserClient* old_browser_client_; |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 115 | }; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 116 | |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 117 | |
[email protected] | f58ddcf | 2009-05-18 22:22:06 | [diff] [blame] | 118 | TEST_F(ChildProcessSecurityPolicyTest, IsWebSafeSchemeTest) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 119 | ChildProcessSecurityPolicyImpl* p = |
| 120 | ChildProcessSecurityPolicyImpl::GetInstance(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 121 | |
[email protected] | e8ca69c | 2014-05-07 15:31:19 | [diff] [blame] | 122 | EXPECT_TRUE(p->IsWebSafeScheme(url::kHttpScheme)); |
| 123 | EXPECT_TRUE(p->IsWebSafeScheme(url::kHttpsScheme)); |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 124 | EXPECT_TRUE(p->IsWebSafeScheme(url::kFtpScheme)); |
| 125 | EXPECT_TRUE(p->IsWebSafeScheme(url::kDataScheme)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 126 | EXPECT_TRUE(p->IsWebSafeScheme("feed")); |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 127 | EXPECT_TRUE(p->IsWebSafeScheme(url::kBlobScheme)); |
| 128 | EXPECT_TRUE(p->IsWebSafeScheme(url::kFileSystemScheme)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 129 | |
| 130 | EXPECT_FALSE(p->IsWebSafeScheme("registered-web-safe-scheme")); |
| 131 | p->RegisterWebSafeScheme("registered-web-safe-scheme"); |
| 132 | EXPECT_TRUE(p->IsWebSafeScheme("registered-web-safe-scheme")); |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 133 | |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 134 | EXPECT_FALSE(p->IsWebSafeScheme(kChromeUIScheme)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 135 | } |
| 136 | |
[email protected] | f58ddcf | 2009-05-18 22:22:06 | [diff] [blame] | 137 | TEST_F(ChildProcessSecurityPolicyTest, IsPseudoSchemeTest) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 138 | ChildProcessSecurityPolicyImpl* p = |
| 139 | ChildProcessSecurityPolicyImpl::GetInstance(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 140 | |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 141 | EXPECT_TRUE(p->IsPseudoScheme(url::kAboutScheme)); |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 142 | EXPECT_TRUE(p->IsPseudoScheme(url::kJavaScriptScheme)); |
[email protected] | dbdda540 | 2013-05-30 22:13:48 | [diff] [blame] | 143 | EXPECT_TRUE(p->IsPseudoScheme(kViewSourceScheme)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 144 | |
[email protected] | 419a057 | 2011-04-18 22:21:46 | [diff] [blame] | 145 | EXPECT_FALSE(p->IsPseudoScheme("registered-pseudo-scheme")); |
| 146 | p->RegisterPseudoScheme("registered-pseudo-scheme"); |
| 147 | EXPECT_TRUE(p->IsPseudoScheme("registered-pseudo-scheme")); |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 148 | |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 149 | EXPECT_FALSE(p->IsPseudoScheme(kChromeUIScheme)); |
[email protected] | 419a057 | 2011-04-18 22:21:46 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | f58ddcf | 2009-05-18 22:22:06 | [diff] [blame] | 152 | TEST_F(ChildProcessSecurityPolicyTest, StandardSchemesTest) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 153 | ChildProcessSecurityPolicyImpl* p = |
| 154 | ChildProcessSecurityPolicyImpl::GetInstance(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 155 | |
| 156 | p->Add(kRendererID); |
| 157 | |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 158 | // Safe to request or commit. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 159 | EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("http://www.google.com/"))); |
| 160 | EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("https://www.paypal.com/"))); |
| 161 | EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("ftp://ftp.gnu.org/"))); |
| 162 | EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("data:text/html,<b>Hi</b>"))); |
[email protected] | 039c7b0b2 | 2011-03-04 23:15:42 | [diff] [blame] | 163 | EXPECT_TRUE(p->CanRequestURL( |
| 164 | kRendererID, GURL("filesystem:http://localhost/temporary/a.gif"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 165 | EXPECT_TRUE(p->CanCommitURL(kRendererID, GURL("http://www.google.com/"))); |
| 166 | EXPECT_TRUE(p->CanCommitURL(kRendererID, GURL("https://www.paypal.com/"))); |
| 167 | EXPECT_TRUE(p->CanCommitURL(kRendererID, GURL("ftp://ftp.gnu.org/"))); |
| 168 | EXPECT_TRUE(p->CanCommitURL(kRendererID, GURL("data:text/html,<b>Hi</b>"))); |
| 169 | EXPECT_TRUE(p->CanCommitURL( |
| 170 | kRendererID, GURL("filesystem:http://localhost/temporary/a.gif"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 171 | |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 172 | // Dangerous to request or commit. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 173 | EXPECT_FALSE(p->CanRequestURL(kRendererID, |
| 174 | GURL("file:///etc/passwd"))); |
| 175 | EXPECT_FALSE(p->CanRequestURL(kRendererID, |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 176 | GURL("chrome://foo/bar"))); |
meacer | ce6b6603 | 2016-06-02 20:56:05 | [diff] [blame] | 177 | EXPECT_FALSE(p->CanRequestURL(kRendererID, |
| 178 | GURL("view-source:http://www.google.com/"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 179 | EXPECT_FALSE(p->CanCommitURL(kRendererID, |
| 180 | GURL("file:///etc/passwd"))); |
| 181 | EXPECT_FALSE(p->CanCommitURL(kRendererID, |
| 182 | GURL("chrome://foo/bar"))); |
meacer | ce6b6603 | 2016-06-02 20:56:05 | [diff] [blame] | 183 | EXPECT_FALSE( |
| 184 | p->CanCommitURL(kRendererID, GURL("view-source:http://www.google.com/"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 185 | |
| 186 | p->Remove(kRendererID); |
| 187 | } |
| 188 | |
[email protected] | f58ddcf | 2009-05-18 22:22:06 | [diff] [blame] | 189 | TEST_F(ChildProcessSecurityPolicyTest, AboutTest) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 190 | ChildProcessSecurityPolicyImpl* p = |
| 191 | ChildProcessSecurityPolicyImpl::GetInstance(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 192 | |
| 193 | p->Add(kRendererID); |
| 194 | |
| 195 | EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("about:blank"))); |
| 196 | EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("about:BlAnK"))); |
| 197 | EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("aBouT:BlAnK"))); |
| 198 | EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("aBouT:blank"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 199 | EXPECT_TRUE(p->CanCommitURL(kRendererID, GURL("about:blank"))); |
| 200 | EXPECT_TRUE(p->CanCommitURL(kRendererID, GURL("about:BlAnK"))); |
| 201 | EXPECT_TRUE(p->CanCommitURL(kRendererID, GURL("aBouT:BlAnK"))); |
| 202 | EXPECT_TRUE(p->CanCommitURL(kRendererID, GURL("aBouT:blank"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 203 | |
[email protected] | ed3456f | 2009-02-26 20:24:48 | [diff] [blame] | 204 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:crash"))); |
| 205 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:cache"))); |
| 206 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:hang"))); |
asvitkine | 2c4b4d1a | 2016-03-19 14:18:07 | [diff] [blame] | 207 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:version"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 208 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("about:crash"))); |
| 209 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("about:cache"))); |
| 210 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("about:hang"))); |
asvitkine | 2c4b4d1a | 2016-03-19 14:18:07 | [diff] [blame] | 211 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("about:version"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 212 | |
asvitkine | 2c4b4d1a | 2016-03-19 14:18:07 | [diff] [blame] | 213 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("aBoUt:version"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 214 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:CrASh"))); |
| 215 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("abOuT:cAChe"))); |
asvitkine | 2c4b4d1a | 2016-03-19 14:18:07 | [diff] [blame] | 216 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("aBoUt:version"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 217 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("about:CrASh"))); |
| 218 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("abOuT:cAChe"))); |
asvitkine | 2c4b4d1a | 2016-03-19 14:18:07 | [diff] [blame] | 219 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("aBoUt:version"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 220 | |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 221 | // Requests for about: pages should be denied. |
| 222 | p->GrantRequestURL(kRendererID, GURL("about:crash")); |
| 223 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:crash"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 224 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("about:crash"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 225 | |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 226 | // These requests for chrome:// pages should be granted. |
[email protected] | e068c2d | 2012-10-23 16:45:18 | [diff] [blame] | 227 | GURL chrome_url("chrome://foo"); |
| 228 | p->GrantRequestURL(kRendererID, chrome_url); |
| 229 | EXPECT_TRUE(p->CanRequestURL(kRendererID, chrome_url)); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 230 | EXPECT_TRUE(p->CanCommitURL(kRendererID, chrome_url)); |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 231 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 232 | p->Remove(kRendererID); |
| 233 | } |
| 234 | |
[email protected] | f58ddcf | 2009-05-18 22:22:06 | [diff] [blame] | 235 | TEST_F(ChildProcessSecurityPolicyTest, JavaScriptTest) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 236 | ChildProcessSecurityPolicyImpl* p = |
| 237 | ChildProcessSecurityPolicyImpl::GetInstance(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 238 | |
| 239 | p->Add(kRendererID); |
| 240 | |
| 241 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("javascript:alert('xss')"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 242 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("javascript:alert('xss')"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 243 | p->GrantRequestURL(kRendererID, GURL("javascript:alert('xss')")); |
| 244 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("javascript:alert('xss')"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 245 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("javascript:alert('xss')"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 246 | |
| 247 | p->Remove(kRendererID); |
| 248 | } |
| 249 | |
[email protected] | f58ddcf | 2009-05-18 22:22:06 | [diff] [blame] | 250 | TEST_F(ChildProcessSecurityPolicyTest, RegisterWebSafeSchemeTest) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 251 | ChildProcessSecurityPolicyImpl* p = |
| 252 | ChildProcessSecurityPolicyImpl::GetInstance(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 253 | |
| 254 | p->Add(kRendererID); |
| 255 | |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 256 | // Currently, "asdf" is destined for ShellExecute, so it is allowed to be |
| 257 | // requested but not committed. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 258 | EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 259 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("asdf:rockers"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 260 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 261 | // Once we register "asdf", we default to deny. |
| 262 | RegisterTestScheme("asdf"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 263 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 264 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("asdf:rockers"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 265 | |
| 266 | // We can allow new schemes by adding them to the whitelist. |
| 267 | p->RegisterWebSafeScheme("asdf"); |
| 268 | EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 269 | EXPECT_TRUE(p->CanCommitURL(kRendererID, GURL("asdf:rockers"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 270 | |
| 271 | // Cleanup. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 272 | p->Remove(kRendererID); |
| 273 | } |
| 274 | |
[email protected] | f58ddcf | 2009-05-18 22:22:06 | [diff] [blame] | 275 | TEST_F(ChildProcessSecurityPolicyTest, CanServiceCommandsTest) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 276 | ChildProcessSecurityPolicyImpl* p = |
| 277 | ChildProcessSecurityPolicyImpl::GetInstance(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 278 | |
| 279 | p->Add(kRendererID); |
| 280 | |
| 281 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("file:///etc/passwd"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 282 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("file:///etc/passwd"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 283 | p->GrantRequestURL(kRendererID, GURL("file:///etc/passwd")); |
| 284 | EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("file:///etc/passwd"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 285 | EXPECT_TRUE(p->CanCommitURL(kRendererID, GURL("file:///etc/passwd"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 286 | |
| 287 | // We should forget our state if we repeat a renderer id. |
| 288 | p->Remove(kRendererID); |
| 289 | p->Add(kRendererID); |
| 290 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("file:///etc/passwd"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 291 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("file:///etc/passwd"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 292 | p->Remove(kRendererID); |
| 293 | } |
| 294 | |
[email protected] | f58ddcf | 2009-05-18 22:22:06 | [diff] [blame] | 295 | TEST_F(ChildProcessSecurityPolicyTest, ViewSource) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 296 | ChildProcessSecurityPolicyImpl* p = |
| 297 | ChildProcessSecurityPolicyImpl::GetInstance(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 298 | |
| 299 | p->Add(kRendererID); |
| 300 | |
meacer | ce6b6603 | 2016-06-02 20:56:05 | [diff] [blame] | 301 | // Child processes cannot request view source URLs. |
| 302 | EXPECT_FALSE(p->CanRequestURL(kRendererID, |
| 303 | GURL("view-source:http://www.google.com/"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 304 | EXPECT_FALSE(p->CanRequestURL(kRendererID, |
| 305 | GURL("view-source:file:///etc/passwd"))); |
| 306 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("file:///etc/passwd"))); |
[email protected] | 690d0a917 | 2010-01-06 00:19:36 | [diff] [blame] | 307 | EXPECT_FALSE(p->CanRequestURL( |
| 308 | kRendererID, GURL("view-source:view-source:http://www.google.com/"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 309 | |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 310 | // View source URLs don't actually commit; the renderer is put into view |
| 311 | // source mode, and the inner URL commits. |
| 312 | EXPECT_FALSE(p->CanCommitURL(kRendererID, |
| 313 | GURL("view-source:http://www.google.com/"))); |
| 314 | EXPECT_FALSE(p->CanCommitURL(kRendererID, |
| 315 | GURL("view-source:file:///etc/passwd"))); |
| 316 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("file:///etc/passwd"))); |
| 317 | EXPECT_FALSE(p->CanCommitURL( |
| 318 | kRendererID, GURL("view-source:view-source:http://www.google.com/"))); |
| 319 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 320 | p->GrantRequestURL(kRendererID, GURL("view-source:file:///etc/passwd")); |
meacer | ce6b6603 | 2016-06-02 20:56:05 | [diff] [blame] | 321 | EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("file:///etc/passwd"))); |
| 322 | EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("file:///etc/passwd"))); |
| 323 | EXPECT_FALSE( |
| 324 | p->CanRequestURL(kRendererID, GURL("view-source:file:///etc/passwd"))); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 325 | EXPECT_FALSE(p->CanCommitURL(kRendererID, |
| 326 | GURL("view-source:file:///etc/passwd"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 327 | p->Remove(kRendererID); |
| 328 | } |
| 329 | |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 330 | TEST_F(ChildProcessSecurityPolicyTest, SpecificFile) { |
| 331 | ChildProcessSecurityPolicyImpl* p = |
| 332 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 333 | |
| 334 | p->Add(kRendererID); |
| 335 | |
| 336 | GURL icon_url("file:///tmp/foo.png"); |
| 337 | GURL sensitive_url("file:///etc/passwd"); |
| 338 | EXPECT_FALSE(p->CanRequestURL(kRendererID, icon_url)); |
| 339 | EXPECT_FALSE(p->CanRequestURL(kRendererID, sensitive_url)); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 340 | EXPECT_FALSE(p->CanCommitURL(kRendererID, icon_url)); |
| 341 | EXPECT_FALSE(p->CanCommitURL(kRendererID, sensitive_url)); |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 342 | |
| 343 | p->GrantRequestSpecificFileURL(kRendererID, icon_url); |
| 344 | EXPECT_TRUE(p->CanRequestURL(kRendererID, icon_url)); |
| 345 | EXPECT_FALSE(p->CanRequestURL(kRendererID, sensitive_url)); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 346 | EXPECT_TRUE(p->CanCommitURL(kRendererID, icon_url)); |
| 347 | EXPECT_FALSE(p->CanCommitURL(kRendererID, sensitive_url)); |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 348 | |
| 349 | p->GrantRequestURL(kRendererID, icon_url); |
| 350 | EXPECT_TRUE(p->CanRequestURL(kRendererID, icon_url)); |
| 351 | EXPECT_TRUE(p->CanRequestURL(kRendererID, sensitive_url)); |
creis | 3710b238 | 2015-08-18 00:12:15 | [diff] [blame] | 352 | EXPECT_TRUE(p->CanCommitURL(kRendererID, icon_url)); |
| 353 | EXPECT_TRUE(p->CanCommitURL(kRendererID, sensitive_url)); |
[email protected] | dc67e1c3 | 2012-06-08 00:10:40 | [diff] [blame] | 354 | |
| 355 | p->Remove(kRendererID); |
| 356 | } |
| 357 | |
[email protected] | b78c188fa6 | 2013-07-23 18:04:45 | [diff] [blame] | 358 | TEST_F(ChildProcessSecurityPolicyTest, FileSystemGrantsTest) { |
| 359 | ChildProcessSecurityPolicyImpl* p = |
| 360 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 361 | |
| 362 | p->Add(kRendererID); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 363 | std::string read_id = |
| 364 | storage::IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( |
| 365 | storage::kFileSystemTypeTest, "read_filesystem", base::FilePath()); |
| 366 | std::string read_write_id = |
| 367 | storage::IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( |
| 368 | storage::kFileSystemTypeTest, |
| 369 | "read_write_filesystem", |
| 370 | base::FilePath()); |
| 371 | std::string copy_into_id = |
| 372 | storage::IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( |
| 373 | storage::kFileSystemTypeTest, |
| 374 | "copy_into_filesystem", |
| 375 | base::FilePath()); |
| 376 | std::string delete_from_id = |
| 377 | storage::IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( |
| 378 | storage::kFileSystemTypeTest, |
| 379 | "delete_from_filesystem", |
| 380 | base::FilePath()); |
[email protected] | b78c188fa6 | 2013-07-23 18:04:45 | [diff] [blame] | 381 | |
| 382 | // Test initially having no permissions. |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 383 | CheckHasNoFileSystemPermission(p, read_id); |
| 384 | CheckHasNoFileSystemPermission(p, read_write_id); |
| 385 | CheckHasNoFileSystemPermission(p, copy_into_id); |
| 386 | CheckHasNoFileSystemPermission(p, delete_from_id); |
[email protected] | b78c188fa6 | 2013-07-23 18:04:45 | [diff] [blame] | 387 | |
| 388 | // Testing varying combinations of grants and checks. |
| 389 | p->GrantReadFileSystem(kRendererID, read_id); |
| 390 | EXPECT_TRUE(p->CanReadFileSystem(kRendererID, read_id)); |
| 391 | EXPECT_FALSE(p->CanReadWriteFileSystem(kRendererID, read_id)); |
| 392 | EXPECT_FALSE(p->CanCopyIntoFileSystem(kRendererID, read_id)); |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 393 | EXPECT_FALSE(p->CanDeleteFromFileSystem(kRendererID, read_id)); |
[email protected] | b78c188fa6 | 2013-07-23 18:04:45 | [diff] [blame] | 394 | |
| 395 | p->GrantReadFileSystem(kRendererID, read_write_id); |
| 396 | p->GrantWriteFileSystem(kRendererID, read_write_id); |
| 397 | EXPECT_TRUE(p->CanReadFileSystem(kRendererID, read_write_id)); |
| 398 | EXPECT_TRUE(p->CanReadWriteFileSystem(kRendererID, read_write_id)); |
| 399 | EXPECT_FALSE(p->CanCopyIntoFileSystem(kRendererID, read_write_id)); |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 400 | EXPECT_FALSE(p->CanDeleteFromFileSystem(kRendererID, read_write_id)); |
[email protected] | b78c188fa6 | 2013-07-23 18:04:45 | [diff] [blame] | 401 | |
| 402 | p->GrantCopyIntoFileSystem(kRendererID, copy_into_id); |
| 403 | EXPECT_FALSE(p->CanReadFileSystem(kRendererID, copy_into_id)); |
| 404 | EXPECT_FALSE(p->CanReadWriteFileSystem(kRendererID, copy_into_id)); |
| 405 | EXPECT_TRUE(p->CanCopyIntoFileSystem(kRendererID, copy_into_id)); |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 406 | EXPECT_FALSE(p->CanDeleteFromFileSystem(kRendererID, copy_into_id)); |
| 407 | |
| 408 | p->GrantDeleteFromFileSystem(kRendererID, delete_from_id); |
| 409 | EXPECT_FALSE(p->CanReadFileSystem(kRendererID, delete_from_id)); |
| 410 | EXPECT_FALSE(p->CanReadWriteFileSystem(kRendererID, delete_from_id)); |
| 411 | EXPECT_FALSE(p->CanCopyIntoFileSystem(kRendererID, delete_from_id)); |
| 412 | EXPECT_TRUE(p->CanDeleteFromFileSystem(kRendererID, delete_from_id)); |
[email protected] | b78c188fa6 | 2013-07-23 18:04:45 | [diff] [blame] | 413 | |
| 414 | // Test revoke permissions on renderer ID removal. |
| 415 | p->Remove(kRendererID); |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 416 | CheckHasNoFileSystemPermission(p, read_id); |
| 417 | CheckHasNoFileSystemPermission(p, read_write_id); |
| 418 | CheckHasNoFileSystemPermission(p, copy_into_id); |
| 419 | CheckHasNoFileSystemPermission(p, delete_from_id); |
[email protected] | b78c188fa6 | 2013-07-23 18:04:45 | [diff] [blame] | 420 | |
| 421 | // Test having no permissions upon re-adding same renderer ID. |
| 422 | p->Add(kRendererID); |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 423 | CheckHasNoFileSystemPermission(p, read_id); |
| 424 | CheckHasNoFileSystemPermission(p, read_write_id); |
| 425 | CheckHasNoFileSystemPermission(p, copy_into_id); |
| 426 | CheckHasNoFileSystemPermission(p, delete_from_id); |
[email protected] | b78c188fa6 | 2013-07-23 18:04:45 | [diff] [blame] | 427 | |
| 428 | // Cleanup. |
| 429 | p->Remove(kRendererID); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 430 | storage::IsolatedContext::GetInstance()->RevokeFileSystem(read_id); |
| 431 | storage::IsolatedContext::GetInstance()->RevokeFileSystem(read_write_id); |
| 432 | storage::IsolatedContext::GetInstance()->RevokeFileSystem(copy_into_id); |
| 433 | storage::IsolatedContext::GetInstance()->RevokeFileSystem(delete_from_id); |
[email protected] | b78c188fa6 | 2013-07-23 18:04:45 | [diff] [blame] | 434 | } |
| 435 | |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 436 | TEST_F(ChildProcessSecurityPolicyTest, FilePermissionGrantingAndRevoking) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 437 | ChildProcessSecurityPolicyImpl* p = |
| 438 | ChildProcessSecurityPolicyImpl::GetInstance(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 439 | |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 440 | p->RegisterFileSystemPermissionPolicy( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 441 | storage::kFileSystemTypeTest, |
| 442 | storage::FILE_PERMISSION_USE_FILE_PERMISSION); |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 443 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 444 | p->Add(kRendererID); |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 445 | base::FilePath file(TEST_PATH("/dir/testfile")); |
| 446 | file = file.NormalizePathSeparators(); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 447 | storage::FileSystemURL url = storage::FileSystemURL::CreateForTest( |
| 448 | GURL("http://foo/"), storage::kFileSystemTypeTest, file); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 449 | |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 450 | // Test initially having no permissions. |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 451 | CheckHasNoFileSystemFilePermission(p, file, url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 452 | |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 453 | // Testing every combination of permissions granting and revoking. |
| 454 | p->GrantReadFile(kRendererID, file); |
| 455 | EXPECT_TRUE(p->CanReadFile(kRendererID, file)); |
[email protected] | d4c797f | 2013-09-26 08:18:53 | [diff] [blame] | 456 | EXPECT_FALSE(p->CanCreateReadWriteFile(kRendererID, file)); |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 457 | EXPECT_TRUE(p->CanReadFileSystemFile(kRendererID, url)); |
| 458 | EXPECT_FALSE(p->CanWriteFileSystemFile(kRendererID, url)); |
| 459 | EXPECT_FALSE(p->CanCreateFileSystemFile(kRendererID, url)); |
[email protected] | d4c797f | 2013-09-26 08:18:53 | [diff] [blame] | 460 | EXPECT_FALSE(p->CanCreateReadWriteFileSystemFile(kRendererID, url)); |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 461 | EXPECT_FALSE(p->CanCopyIntoFileSystemFile(kRendererID, url)); |
| 462 | EXPECT_FALSE(p->CanDeleteFileSystemFile(kRendererID, url)); |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 463 | p->RevokeAllPermissionsForFile(kRendererID, file); |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 464 | CheckHasNoFileSystemFilePermission(p, file, url); |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 465 | |
| 466 | p->GrantCreateReadWriteFile(kRendererID, file); |
| 467 | EXPECT_TRUE(p->CanReadFile(kRendererID, file)); |
[email protected] | d4c797f | 2013-09-26 08:18:53 | [diff] [blame] | 468 | EXPECT_TRUE(p->CanCreateReadWriteFile(kRendererID, file)); |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 469 | EXPECT_TRUE(p->CanReadFileSystemFile(kRendererID, url)); |
| 470 | EXPECT_TRUE(p->CanWriteFileSystemFile(kRendererID, url)); |
| 471 | EXPECT_TRUE(p->CanCreateFileSystemFile(kRendererID, url)); |
[email protected] | d4c797f | 2013-09-26 08:18:53 | [diff] [blame] | 472 | EXPECT_TRUE(p->CanCreateReadWriteFileSystemFile(kRendererID, url)); |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 473 | EXPECT_TRUE(p->CanCopyIntoFileSystemFile(kRendererID, url)); |
| 474 | EXPECT_TRUE(p->CanDeleteFileSystemFile(kRendererID, url)); |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 475 | p->RevokeAllPermissionsForFile(kRendererID, file); |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 476 | CheckHasNoFileSystemFilePermission(p, file, url); |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 477 | |
| 478 | // Test revoke permissions on renderer ID removal. |
| 479 | p->GrantCreateReadWriteFile(kRendererID, file); |
| 480 | EXPECT_TRUE(p->CanReadFile(kRendererID, file)); |
[email protected] | d4c797f | 2013-09-26 08:18:53 | [diff] [blame] | 481 | EXPECT_TRUE(p->CanCreateReadWriteFile(kRendererID, file)); |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 482 | EXPECT_TRUE(p->CanReadFileSystemFile(kRendererID, url)); |
| 483 | EXPECT_TRUE(p->CanWriteFileSystemFile(kRendererID, url)); |
| 484 | EXPECT_TRUE(p->CanCreateFileSystemFile(kRendererID, url)); |
[email protected] | d4c797f | 2013-09-26 08:18:53 | [diff] [blame] | 485 | EXPECT_TRUE(p->CanCreateReadWriteFileSystemFile(kRendererID, url)); |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 486 | EXPECT_TRUE(p->CanCopyIntoFileSystemFile(kRendererID, url)); |
| 487 | EXPECT_TRUE(p->CanDeleteFileSystemFile(kRendererID, url)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 488 | p->Remove(kRendererID); |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 489 | CheckHasNoFileSystemFilePermission(p, file, url); |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 490 | |
| 491 | // Test having no permissions upon re-adding same renderer ID. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 492 | p->Add(kRendererID); |
[email protected] | 5a65fde3 | 2013-10-22 05:15:34 | [diff] [blame] | 493 | CheckHasNoFileSystemFilePermission(p, file, url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 494 | |
[email protected] | 9f10431 | 2013-07-23 23:18:19 | [diff] [blame] | 495 | // Cleanup. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 496 | p->Remove(kRendererID); |
| 497 | } |
| 498 | |
[email protected] | e54edc3 | 2010-09-28 01:09:19 | [diff] [blame] | 499 | TEST_F(ChildProcessSecurityPolicyTest, FilePermissions) { |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 500 | base::FilePath granted_file = base::FilePath(TEST_PATH("/home/joe")); |
| 501 | base::FilePath sibling_file = base::FilePath(TEST_PATH("/home/bob")); |
| 502 | base::FilePath child_file = base::FilePath(TEST_PATH("/home/joe/file")); |
| 503 | base::FilePath parent_file = base::FilePath(TEST_PATH("/home")); |
| 504 | base::FilePath parent_slash_file = base::FilePath(TEST_PATH("/home/")); |
| 505 | base::FilePath child_traversal1 = |
| 506 | base::FilePath(TEST_PATH("/home/joe/././file")); |
| 507 | base::FilePath child_traversal2 = base::FilePath( |
[email protected] | f0ecca452 | 2013-01-07 21:50:56 | [diff] [blame] | 508 | TEST_PATH("/home/joe/file/../otherfile")); |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 509 | base::FilePath evil_traversal1 = |
[email protected] | 023ad6ab | 2013-02-17 05:07:23 | [diff] [blame] | 510 | base::FilePath(TEST_PATH("/home/joe/../../etc/passwd")); |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 511 | base::FilePath evil_traversal2 = base::FilePath( |
[email protected] | f0ecca452 | 2013-01-07 21:50:56 | [diff] [blame] | 512 | TEST_PATH("/home/joe/./.././../etc/passwd")); |
[email protected] | c42de73 | 2013-02-16 06:26:31 | [diff] [blame] | 513 | base::FilePath self_traversal = |
| 514 | base::FilePath(TEST_PATH("/home/joe/../joe/file")); |
| 515 | base::FilePath relative_file = base::FilePath(FILE_PATH_LITERAL("home/joe")); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 516 | |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 517 | ChildProcessSecurityPolicyImpl* p = |
| 518 | ChildProcessSecurityPolicyImpl::GetInstance(); |
[email protected] | e54edc3 | 2010-09-28 01:09:19 | [diff] [blame] | 519 | |
| 520 | // Grant permissions for a file. |
| 521 | p->Add(kRendererID); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 522 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 523 | base::File::FLAG_OPEN)); |
[email protected] | e54edc3 | 2010-09-28 01:09:19 | [diff] [blame] | 524 | |
[email protected] | bfcf1e9 | 2013-07-11 04:37:25 | [diff] [blame] | 525 | GrantPermissionsForFile(p, kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 526 | base::File::FLAG_OPEN | |
| 527 | base::File::FLAG_OPEN_TRUNCATED | |
| 528 | base::File::FLAG_READ | |
| 529 | base::File::FLAG_WRITE); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 530 | EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 531 | base::File::FLAG_OPEN | |
| 532 | base::File::FLAG_OPEN_TRUNCATED | |
| 533 | base::File::FLAG_READ | |
| 534 | base::File::FLAG_WRITE)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 535 | EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 536 | base::File::FLAG_OPEN | |
| 537 | base::File::FLAG_READ)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 538 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 539 | base::File::FLAG_CREATE)); |
[email protected] | f0ecca452 | 2013-01-07 21:50:56 | [diff] [blame] | 540 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, 0)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 541 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 542 | base::File::FLAG_CREATE | |
| 543 | base::File::FLAG_OPEN_TRUNCATED | |
| 544 | base::File::FLAG_READ | |
| 545 | base::File::FLAG_WRITE)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 546 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, sibling_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 547 | base::File::FLAG_OPEN | |
| 548 | base::File::FLAG_READ)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 549 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, parent_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 550 | base::File::FLAG_OPEN | |
| 551 | base::File::FLAG_READ)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 552 | EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, child_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 553 | base::File::FLAG_OPEN | |
| 554 | base::File::FLAG_READ)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 555 | EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, child_traversal1, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 556 | base::File::FLAG_OPEN | |
| 557 | base::File::FLAG_READ)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 558 | EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, child_traversal2, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 559 | base::File::FLAG_OPEN | |
| 560 | base::File::FLAG_READ)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 561 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, evil_traversal1, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 562 | base::File::FLAG_OPEN | |
| 563 | base::File::FLAG_READ)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 564 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, evil_traversal2, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 565 | base::File::FLAG_OPEN | |
| 566 | base::File::FLAG_READ)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 567 | // CPSP doesn't allow this case for the sake of simplicity. |
| 568 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, self_traversal, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 569 | base::File::FLAG_OPEN | |
| 570 | base::File::FLAG_READ)); |
[email protected] | e54edc3 | 2010-09-28 01:09:19 | [diff] [blame] | 571 | p->Remove(kRendererID); |
| 572 | |
| 573 | // Grant permissions for the directory the file is in. |
| 574 | p->Add(kRendererID); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 575 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 576 | base::File::FLAG_OPEN)); |
[email protected] | bfcf1e9 | 2013-07-11 04:37:25 | [diff] [blame] | 577 | GrantPermissionsForFile(p, kRendererID, parent_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 578 | base::File::FLAG_OPEN | |
| 579 | base::File::FLAG_READ); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 580 | EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 581 | base::File::FLAG_OPEN)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 582 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 583 | base::File::FLAG_READ | |
| 584 | base::File::FLAG_WRITE)); |
[email protected] | e54edc3 | 2010-09-28 01:09:19 | [diff] [blame] | 585 | p->Remove(kRendererID); |
| 586 | |
| 587 | // Grant permissions for the directory the file is in (with trailing '/'). |
| 588 | p->Add(kRendererID); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 589 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 590 | base::File::FLAG_OPEN)); |
[email protected] | bfcf1e9 | 2013-07-11 04:37:25 | [diff] [blame] | 591 | GrantPermissionsForFile(p, kRendererID, parent_slash_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 592 | base::File::FLAG_OPEN | |
| 593 | base::File::FLAG_READ); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 594 | EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 595 | base::File::FLAG_OPEN)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 596 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 597 | base::File::FLAG_READ | |
| 598 | base::File::FLAG_WRITE)); |
[email protected] | e54edc3 | 2010-09-28 01:09:19 | [diff] [blame] | 599 | |
| 600 | // Grant permissions for the file (should overwrite the permissions granted |
| 601 | // for the directory). |
[email protected] | bfcf1e9 | 2013-07-11 04:37:25 | [diff] [blame] | 602 | GrantPermissionsForFile(p, kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 603 | base::File::FLAG_TEMPORARY); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 604 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 605 | base::File::FLAG_OPEN)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 606 | EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 607 | base::File::FLAG_TEMPORARY)); |
[email protected] | 77930fe | 2010-10-01 22:45:34 | [diff] [blame] | 608 | |
| 609 | // Revoke all permissions for the file (it should inherit its permissions |
| 610 | // from the directory again). |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 611 | p->RevokeAllPermissionsForFile(kRendererID, granted_file); |
| 612 | EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 613 | base::File::FLAG_OPEN | |
| 614 | base::File::FLAG_READ)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 615 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 616 | base::File::FLAG_TEMPORARY)); |
[email protected] | e54edc3 | 2010-09-28 01:09:19 | [diff] [blame] | 617 | p->Remove(kRendererID); |
[email protected] | cee64fd3 | 2011-05-02 18:59:07 | [diff] [blame] | 618 | |
| 619 | // Grant file permissions for the file to main thread renderer process, |
| 620 | // make sure its worker thread renderer process inherits those. |
| 621 | p->Add(kRendererID); |
[email protected] | bfcf1e9 | 2013-07-11 04:37:25 | [diff] [blame] | 622 | GrantPermissionsForFile(p, kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 623 | base::File::FLAG_OPEN | |
| 624 | base::File::FLAG_READ); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 625 | EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 626 | base::File::FLAG_OPEN | |
| 627 | base::File::FLAG_READ)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 628 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 629 | base::File::FLAG_WRITE)); |
[email protected] | cee64fd3 | 2011-05-02 18:59:07 | [diff] [blame] | 630 | p->AddWorker(kWorkerRendererID, kRendererID); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 631 | EXPECT_TRUE(p->HasPermissionsForFile(kWorkerRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 632 | base::File::FLAG_OPEN | |
| 633 | base::File::FLAG_READ)); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 634 | EXPECT_FALSE(p->HasPermissionsForFile(kWorkerRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 635 | base::File::FLAG_WRITE)); |
[email protected] | cee64fd3 | 2011-05-02 18:59:07 | [diff] [blame] | 636 | p->Remove(kRendererID); |
[email protected] | 8083841 | 2012-11-20 01:53:59 | [diff] [blame] | 637 | EXPECT_FALSE(p->HasPermissionsForFile(kWorkerRendererID, granted_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 638 | base::File::FLAG_OPEN | |
| 639 | base::File::FLAG_READ)); |
[email protected] | cee64fd3 | 2011-05-02 18:59:07 | [diff] [blame] | 640 | p->Remove(kWorkerRendererID); |
[email protected] | f0ecca452 | 2013-01-07 21:50:56 | [diff] [blame] | 641 | |
| 642 | p->Add(kRendererID); |
[email protected] | bfcf1e9 | 2013-07-11 04:37:25 | [diff] [blame] | 643 | GrantPermissionsForFile(p, kRendererID, relative_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 644 | base::File::FLAG_OPEN); |
[email protected] | f0ecca452 | 2013-01-07 21:50:56 | [diff] [blame] | 645 | EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, relative_file, |
[email protected] | 2c288ed | 2014-06-05 22:07:41 | [diff] [blame] | 646 | base::File::FLAG_OPEN)); |
[email protected] | f0ecca452 | 2013-01-07 21:50:56 | [diff] [blame] | 647 | p->Remove(kRendererID); |
[email protected] | e54edc3 | 2010-09-28 01:09:19 | [diff] [blame] | 648 | } |
| 649 | |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 650 | TEST_F(ChildProcessSecurityPolicyTest, CanServiceWebUIBindings) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 651 | ChildProcessSecurityPolicyImpl* p = |
| 652 | ChildProcessSecurityPolicyImpl::GetInstance(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 653 | |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 654 | GURL url("chrome://thumb/http://www.google.com/"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 655 | |
| 656 | p->Add(kRendererID); |
| 657 | |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 658 | EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 659 | EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 660 | p->GrantWebUIBindings(kRendererID); |
| 661 | EXPECT_TRUE(p->HasWebUIBindings(kRendererID)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 662 | EXPECT_TRUE(p->CanRequestURL(kRendererID, url)); |
| 663 | |
| 664 | p->Remove(kRendererID); |
| 665 | } |
| 666 | |
[email protected] | f58ddcf | 2009-05-18 22:22:06 | [diff] [blame] | 667 | TEST_F(ChildProcessSecurityPolicyTest, RemoveRace) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 668 | ChildProcessSecurityPolicyImpl* p = |
| 669 | ChildProcessSecurityPolicyImpl::GetInstance(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 670 | |
| 671 | GURL url("file:///etc/passwd"); |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 672 | base::FilePath file(TEST_PATH("/etc/passwd")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 673 | |
| 674 | p->Add(kRendererID); |
| 675 | |
| 676 | p->GrantRequestURL(kRendererID, url); |
[email protected] | e54edc3 | 2010-09-28 01:09:19 | [diff] [blame] | 677 | p->GrantReadFile(kRendererID, file); |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 678 | p->GrantWebUIBindings(kRendererID); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 679 | |
| 680 | EXPECT_TRUE(p->CanRequestURL(kRendererID, url)); |
[email protected] | e54edc3 | 2010-09-28 01:09:19 | [diff] [blame] | 681 | EXPECT_TRUE(p->CanReadFile(kRendererID, file)); |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 682 | EXPECT_TRUE(p->HasWebUIBindings(kRendererID)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 683 | |
| 684 | p->Remove(kRendererID); |
| 685 | |
| 686 | // Renderers are added and removed on the UI thread, but the policy can be |
[email protected] | 58052263 | 2009-08-17 21:55:55 | [diff] [blame] | 687 | // queried on the IO thread. The ChildProcessSecurityPolicy needs to be |
| 688 | // prepared to answer policy questions about renderers who no longer exist. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 689 | |
| 690 | // In this case, we default to secure behavior. |
| 691 | EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); |
[email protected] | e54edc3 | 2010-09-28 01:09:19 | [diff] [blame] | 692 | EXPECT_FALSE(p->CanReadFile(kRendererID, file)); |
[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 693 | EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 694 | } |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 695 | |
paulmeyer | 1eefa26e | 2015-10-01 02:11:13 | [diff] [blame] | 696 | // Test the granting of origin permissions, and their interactions with |
| 697 | // granting scheme permissions. |
| 698 | TEST_F(ChildProcessSecurityPolicyTest, OriginGranting) { |
| 699 | ChildProcessSecurityPolicyImpl* p = |
| 700 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 701 | |
| 702 | p->Add(kRendererID); |
| 703 | |
| 704 | GURL url_foo1("chrome://foo/resource1"); |
| 705 | GURL url_foo2("chrome://foo/resource2"); |
| 706 | GURL url_bar("chrome://bar/resource3"); |
| 707 | |
| 708 | EXPECT_FALSE(p->CanRequestURL(kRendererID, url_foo1)); |
| 709 | EXPECT_FALSE(p->CanRequestURL(kRendererID, url_foo2)); |
| 710 | EXPECT_FALSE(p->CanRequestURL(kRendererID, url_bar)); |
| 711 | EXPECT_FALSE(p->CanCommitURL(kRendererID, url_foo1)); |
| 712 | EXPECT_FALSE(p->CanCommitURL(kRendererID, url_foo2)); |
| 713 | EXPECT_FALSE(p->CanCommitURL(kRendererID, url_bar)); |
| 714 | |
| 715 | p->GrantOrigin(kRendererID, url::Origin(url_foo1)); |
| 716 | |
| 717 | EXPECT_TRUE(p->CanRequestURL(kRendererID, url_foo1)); |
| 718 | EXPECT_TRUE(p->CanRequestURL(kRendererID, url_foo2)); |
| 719 | EXPECT_FALSE(p->CanRequestURL(kRendererID, url_bar)); |
| 720 | EXPECT_TRUE(p->CanCommitURL(kRendererID, url_foo1)); |
| 721 | EXPECT_TRUE(p->CanCommitURL(kRendererID, url_foo2)); |
| 722 | EXPECT_FALSE(p->CanCommitURL(kRendererID, url_bar)); |
| 723 | |
| 724 | p->GrantScheme(kRendererID, kChromeUIScheme); |
| 725 | |
| 726 | EXPECT_TRUE(p->CanRequestURL(kRendererID, url_foo1)); |
| 727 | EXPECT_TRUE(p->CanRequestURL(kRendererID, url_foo2)); |
| 728 | EXPECT_TRUE(p->CanRequestURL(kRendererID, url_bar)); |
| 729 | EXPECT_TRUE(p->CanCommitURL(kRendererID, url_foo1)); |
| 730 | EXPECT_TRUE(p->CanCommitURL(kRendererID, url_foo2)); |
| 731 | EXPECT_TRUE(p->CanCommitURL(kRendererID, url_bar)); |
| 732 | |
| 733 | p->Remove(kRendererID); |
| 734 | } |
| 735 | |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 736 | } // namespace content |