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

Side by Side Diff: content/browser/child_process_security_policy_unittest.cc

Issue 2347163004: Disallow navigations to blob URLs with non-canonical origins. (Closed)
Patch Set: Fix issues and add unittest. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "content/browser/child_process_security_policy_impl.h" 9 #include "content/browser/child_process_security_policy_impl.h"
10 #include "content/public/common/url_constants.h" 10 #include "content/public/common/url_constants.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 EXPECT_FALSE(p->CanCommitURL(kRendererID, 179 EXPECT_FALSE(p->CanCommitURL(kRendererID,
180 GURL("file:///etc/passwd"))); 180 GURL("file:///etc/passwd")));
181 EXPECT_FALSE(p->CanCommitURL(kRendererID, 181 EXPECT_FALSE(p->CanCommitURL(kRendererID,
182 GURL("chrome://foo/bar"))); 182 GURL("chrome://foo/bar")));
183 EXPECT_FALSE( 183 EXPECT_FALSE(
184 p->CanCommitURL(kRendererID, GURL("view-source:http://www.google.com/"))); 184 p->CanCommitURL(kRendererID, GURL("view-source:http://www.google.com/")));
185 185
186 p->Remove(kRendererID); 186 p->Remove(kRendererID);
187 } 187 }
188 188
189 TEST_F(ChildProcessSecurityPolicyTest, BlobSchemeTest) {
190 ChildProcessSecurityPolicyImpl* p =
191 ChildProcessSecurityPolicyImpl::GetInstance();
192
193 p->Add(kRendererID);
194
195 EXPECT_TRUE(
196 p->CanCommitURL(kRendererID, GURL("blob:http://localhost/some-guid")));
197 EXPECT_TRUE(p->CanCommitURL(kRendererID, GURL("blob:null/some-guid")));
198 EXPECT_TRUE(
199 p->CanCommitURL(kRendererID, GURL("blob:http://localhost/some-guid")));
200 EXPECT_TRUE(p->CanCommitURL(kRendererID, GURL("blob:NulL/some-guid")));
201 EXPECT_FALSE(p->CanCommitURL(
202 kRendererID, GURL("blob:http://username@localhost/some-guid")));
203 EXPECT_FALSE(p->CanCommitURL(
204 kRendererID, GURL("blob:http://username @localhost/some-guid")));
205 EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("blob:blob:some-guid")));
206 EXPECT_FALSE(p->CanCommitURL(kRendererID, GURL("blob:some-guid")));
207 EXPECT_FALSE(p->CanCommitURL(kRendererID,
208 GURL("blob:filesystem:http://localhost/path")));
209 EXPECT_FALSE(p->CanCommitURL(kRendererID,
210 GURL("filesystem:blob:http://localhost/guid")));
211
212 EXPECT_TRUE(
213 p->CanRequestURL(kRendererID, GURL("blob:http://localhost/some-guid")));
Charlie Reis 2016/09/20 23:19:06 nit: Let's put the CanRequest block above the CanC
ncarter (slow) 2016/09/21 17:03:16 Done.
214 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("blob:null/some-guid")));
215 EXPECT_TRUE(
216 p->CanRequestURL(kRendererID, GURL("blob:http://localhost/some-guid")));
217 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("blob:NulL/some-guid")));
218 EXPECT_FALSE(p->CanRequestURL(
219 kRendererID, GURL("blob:http://username@localhost/some-guid")));
220 EXPECT_FALSE(p->CanRequestURL(
221 kRendererID, GURL("blob:http://username @localhost/some-guid")));
222 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("blob:blob:some-guid")));
223 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("blob:some-guid")));
224 EXPECT_FALSE(p->CanRequestURL(kRendererID,
225 GURL("blob:filesystem:http://localhost/path")));
226 EXPECT_FALSE(p->CanRequestURL(kRendererID,
227 GURL("filesystem:blob:http://localhost/guid")));
228
229 p->Remove(kRendererID);
230 }
231
189 TEST_F(ChildProcessSecurityPolicyTest, AboutTest) { 232 TEST_F(ChildProcessSecurityPolicyTest, AboutTest) {
190 ChildProcessSecurityPolicyImpl* p = 233 ChildProcessSecurityPolicyImpl* p =
191 ChildProcessSecurityPolicyImpl::GetInstance(); 234 ChildProcessSecurityPolicyImpl::GetInstance();
192 235
193 p->Add(kRendererID); 236 p->Add(kRendererID);
194 237
195 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("about:blank"))); 238 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("about:blank")));
196 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("about:BlAnK"))); 239 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("about:BlAnK")));
197 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("aBouT:BlAnK"))); 240 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("aBouT:BlAnK")));
198 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("aBouT:blank"))); 241 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("aBouT:blank")));
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 EXPECT_TRUE(p->CanRequestURL(kRendererID, url_foo2)); 770 EXPECT_TRUE(p->CanRequestURL(kRendererID, url_foo2));
728 EXPECT_TRUE(p->CanRequestURL(kRendererID, url_bar)); 771 EXPECT_TRUE(p->CanRequestURL(kRendererID, url_bar));
729 EXPECT_TRUE(p->CanCommitURL(kRendererID, url_foo1)); 772 EXPECT_TRUE(p->CanCommitURL(kRendererID, url_foo1));
730 EXPECT_TRUE(p->CanCommitURL(kRendererID, url_foo2)); 773 EXPECT_TRUE(p->CanCommitURL(kRendererID, url_foo2));
731 EXPECT_TRUE(p->CanCommitURL(kRendererID, url_bar)); 774 EXPECT_TRUE(p->CanCommitURL(kRendererID, url_bar));
732 775
733 p->Remove(kRendererID); 776 p->Remove(kRendererID);
734 } 777 }
735 778
736 } // namespace content 779 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698