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

Side by Side Diff: third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp

Issue 2708873002: Stop CSP from matching independent scheme/port upgrades (Closed)
Patch Set: rebase-update Created 3 years, 9 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 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 "core/frame/csp/CSPSource.h" 5 #include "core/frame/csp/CSPSource.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/frame/csp/ContentSecurityPolicy.h" 8 #include "core/frame/csp/ContentSecurityPolicy.h"
9 #include "platform/network/ResourceRequest.h" 9 #include "platform/network/ResourceRequest.h"
10 #include "platform/weborigin/KURL.h" 10 #include "platform/weborigin/KURL.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 KURL base; 98 KURL base;
99 CSPSource source(csp.get(), "http", "example.com", 8000, "/bar/", 99 CSPSource source(csp.get(), "http", "example.com", 8000, "/bar/",
100 CSPSource::NoWildcard, CSPSource::NoWildcard); 100 CSPSource::NoWildcard, CSPSource::NoWildcard);
101 101
102 EXPECT_TRUE( 102 EXPECT_TRUE(
103 source.matches(KURL(base, "http://example.com:8000/"), 103 source.matches(KURL(base, "http://example.com:8000/"),
104 ResourceRequest::RedirectStatus::FollowedRedirect)); 104 ResourceRequest::RedirectStatus::FollowedRedirect));
105 EXPECT_TRUE( 105 EXPECT_TRUE(
106 source.matches(KURL(base, "http://example.com:8000/foo"), 106 source.matches(KURL(base, "http://example.com:8000/foo"),
107 ResourceRequest::RedirectStatus::FollowedRedirect)); 107 ResourceRequest::RedirectStatus::FollowedRedirect));
108 EXPECT_TRUE( 108 // Should not allow upgrade of port or scheme without upgrading both
109 EXPECT_FALSE(
109 source.matches(KURL(base, "https://example.com:8000/foo"), 110 source.matches(KURL(base, "https://example.com:8000/foo"),
110 ResourceRequest::RedirectStatus::FollowedRedirect)); 111 ResourceRequest::RedirectStatus::FollowedRedirect));
111
112 EXPECT_FALSE( 112 EXPECT_FALSE(
113 source.matches(KURL(base, "http://not-example.com:8000/foo"), 113 source.matches(KURL(base, "http://not-example.com:8000/foo"),
114 ResourceRequest::RedirectStatus::FollowedRedirect)); 114 ResourceRequest::RedirectStatus::FollowedRedirect));
115 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:9000/foo/"), 115 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:9000/foo/"),
116 ResourceRequest::RedirectStatus::NoRedirect)); 116 ResourceRequest::RedirectStatus::NoRedirect));
117 } 117 }
118 118
119 TEST_F(CSPSourceTest, InsecureSchemeMatchesSecureScheme) { 119 TEST_F(CSPSourceTest, InsecureSchemeMatchesSecureScheme) {
120 KURL base; 120 KURL base;
121 CSPSource source(csp.get(), "http", "", 0, "/", CSPSource::NoWildcard, 121 CSPSource source(csp.get(), "http", "", 0, "/", CSPSource::NoWildcard,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 // Self scheme is https. 158 // Self scheme is https.
159 { 159 {
160 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create()); 160 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create());
161 csp->setupSelf(*SecurityOrigin::createFromString("https://a.com/")); 161 csp->setupSelf(*SecurityOrigin::createFromString("https://a.com/"));
162 CSPSource source(csp.get(), "", "a.com", 0, "/", CSPSource::NoWildcard, 162 CSPSource source(csp.get(), "", "a.com", 0, "/", CSPSource::NoWildcard,
163 CSPSource::NoWildcard); 163 CSPSource::NoWildcard);
164 EXPECT_FALSE(source.matches(KURL(base, "http://a.com"))); 164 EXPECT_FALSE(source.matches(KURL(base, "http://a.com")));
165 EXPECT_TRUE(source.matches(KURL(base, "https://a.com"))); 165 EXPECT_TRUE(source.matches(KURL(base, "https://a.com")));
166 EXPECT_FALSE(source.matches(KURL(base, "http-so://a.com"))); 166 EXPECT_FALSE(source.matches(KURL(base, "http-so://a.com")));
167 // TODO(mkwst, arthursonzogni): Maybe it should return true. 167 // TODO(jochen): Maybe it should return false?
168 // See http://crbug.com/692442 168 EXPECT_TRUE(source.matches(KURL(base, "https-so://a.com")));
169 EXPECT_FALSE(source.matches(KURL(base, "https-so://a.com")));
170 EXPECT_FALSE(source.matches(KURL(base, "ftp://a.com"))); 169 EXPECT_FALSE(source.matches(KURL(base, "ftp://a.com")));
171 } 170 }
172 171
173 // Self scheme is not in the http familly. 172 // Self scheme is not in the http familly.
174 { 173 {
175 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create()); 174 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create());
176 csp->setupSelf(*SecurityOrigin::createFromString("ftp://a.com/")); 175 csp->setupSelf(*SecurityOrigin::createFromString("ftp://a.com/"));
177 CSPSource source(csp.get(), "", "a.com", 0, "/", CSPSource::NoWildcard, 176 CSPSource source(csp.get(), "", "a.com", 0, "/", CSPSource::NoWildcard,
178 CSPSource::NoWildcard); 177 CSPSource::NoWildcard);
179 EXPECT_FALSE(source.matches(KURL(base, "http://a.com"))); 178 EXPECT_FALSE(source.matches(KURL(base, "http://a.com")));
(...skipping 20 matching lines...) Expand all
200 199
201 TEST_F(CSPSourceTest, InsecureHostSchemePortMatchesSecurePort) { 200 TEST_F(CSPSourceTest, InsecureHostSchemePortMatchesSecurePort) {
202 KURL base; 201 KURL base;
203 202
204 // source scheme is "http" 203 // source scheme is "http"
205 { 204 {
206 CSPSource source(csp.get(), "http", "example.com", 80, "/", 205 CSPSource source(csp.get(), "http", "example.com", 80, "/",
207 CSPSource::NoWildcard, CSPSource::NoWildcard); 206 CSPSource::NoWildcard, CSPSource::NoWildcard);
208 EXPECT_TRUE(source.matches(KURL(base, "http://example.com/"))); 207 EXPECT_TRUE(source.matches(KURL(base, "http://example.com/")));
209 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:80/"))); 208 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:80/")));
210 // TODO(mkwst, arthursonzogni): It is weird to upgrade the port without the 209
211 // sheme. See http://crbug.com/692499 210 // Should not allow scheme upgrades unless both port and scheme are upgraded
212 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:443/"))); 211 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:443/")));
213 EXPECT_TRUE(source.matches(KURL(base, "https://example.com/"))); 212 EXPECT_TRUE(source.matches(KURL(base, "https://example.com/")));
214 // TODO(mkwst, arthursonzogni): It is weird to upgrade the scheme without 213 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:80/")));
215 // the port. See http://crbug.com/692499 214
216 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:80/")));
217 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:443/"))); 215 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:443/")));
218 216
219 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:8443/"))); 217 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:8443/")));
220 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:8443/"))); 218 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:8443/")));
221 219
222 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com/"))); 220 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com/")));
223 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:80/"))); 221 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:80/")));
224 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:443/"))); 222 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:443/")));
225 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com/"))); 223 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com/")));
226 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:80/"))); 224 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:80/")));
227 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:443/"))); 225 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:443/")));
228 } 226 }
229 227
230 // source scheme is empty 228 // source scheme is empty
231 { 229 {
232 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create()); 230 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create());
233 csp->setupSelf(*SecurityOrigin::createFromString("http://example.com")); 231 csp->setupSelf(*SecurityOrigin::createFromString("http://example.com"));
234 CSPSource source(csp.get(), "", "example.com", 80, "/", 232 CSPSource source(csp.get(), "", "example.com", 80, "/",
235 CSPSource::NoWildcard, CSPSource::NoWildcard); 233 CSPSource::NoWildcard, CSPSource::NoWildcard);
236 EXPECT_TRUE(source.matches(KURL(base, "http://example.com/"))); 234 EXPECT_TRUE(source.matches(KURL(base, "http://example.com/")));
237 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:443"))); 235 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:443")));
238 // TODO(mkwst, arthursonzogni): It is weird to upgrade the port without the 236 // Should not allow upgrade of port or scheme without upgrading both
239 // sheme. See http://crbug.com/692499 237 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:443")));
240 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:443"))); 238 }
239
240 // source port is empty
241 {
242 CSPSource source(csp.get(), "http", "example.com", 0, "/",
243 CSPSource::NoWildcard, CSPSource::NoWildcard);
244
245 EXPECT_TRUE(source.matches(KURL(base, "http://example.com")));
246 EXPECT_TRUE(source.matches(KURL(base, "https://example.com")));
247 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:443")));
248 // Should not allow upgrade of port or scheme without upgrading both
249 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:80")));
250 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:443")));
241 } 251 }
242 } 252 }
243 253
244 TEST_F(CSPSourceTest, HostMatches) { 254 TEST_F(CSPSourceTest, HostMatches) {
245 KURL base; 255 KURL base;
246 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create()); 256 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create());
247 csp->setupSelf(*SecurityOrigin::createFromString("http://a.com")); 257 csp->setupSelf(*SecurityOrigin::createFromString("http://a.com"));
248 258
249 // Host is * (source-expression = "http://*") 259 // Host is * (source-expression = "http://*")
250 { 260 {
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 normalized = B->intersect(A); 910 normalized = B->intersect(A);
901 Source intersectBA = { 911 Source intersectBA = {
902 normalized->m_scheme, normalized->m_host, 912 normalized->m_scheme, normalized->m_host,
903 normalized->m_path, normalized->m_port, 913 normalized->m_path, normalized->m_port,
904 normalized->m_hostWildcard, normalized->m_portWildcard}; 914 normalized->m_hostWildcard, normalized->m_portWildcard};
905 EXPECT_TRUE(equalSources(intersectBA, test.normalized)); 915 EXPECT_TRUE(equalSources(intersectBA, test.normalized));
906 } 916 }
907 } 917 }
908 918
909 } // namespace blink 919 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698