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 "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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 KURL base; | 132 KURL base; |
| 133 CSPSource source(csp.get(), "http", "example.com", 0, "/", | 133 CSPSource source(csp.get(), "http", "example.com", 0, "/", |
| 134 CSPSource::NoWildcard, CSPSource::HasWildcard); | 134 CSPSource::NoWildcard, CSPSource::HasWildcard); |
| 135 | 135 |
| 136 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"))); | 136 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"))); |
| 137 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/"))); | 137 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/"))); |
| 138 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/"))); | 138 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/"))); |
| 139 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:8000/"))); | 139 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:8000/"))); |
| 140 } | 140 } |
| 141 | 141 |
| 142 TEST_F(CSPSourceTest, SchemeIsEmpty) { | |
| 143 KURL base; | |
| 144 | |
| 145 // Self scheme is http. | |
| 146 { | |
| 147 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create()); | |
| 148 csp->setupSelf(*SecurityOrigin::createFromString("http://a.com/")); | |
| 149 CSPSource source(csp.get(), "", "a.com", 0, "/", CSPSource::NoWildcard, | |
| 150 CSPSource::NoWildcard); | |
| 151 EXPECT_TRUE(source.matches(KURL(base, "http://a.com"))); | |
| 152 EXPECT_TRUE(source.matches(KURL(base, "https://a.com"))); | |
| 153 EXPECT_TRUE(source.matches(KURL(base, "http-so://a.com"))); | |
| 154 EXPECT_TRUE(source.matches(KURL(base, "https-so://a.com"))); | |
| 155 EXPECT_FALSE(source.matches(KURL(base, "ftp://a.com"))); | |
| 156 } | |
| 157 | |
| 158 // Self scheme is https. | |
| 159 { | |
| 160 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create()); | |
| 161 csp->setupSelf(*SecurityOrigin::createFromString("https://a.com/")); | |
| 162 CSPSource source(csp.get(), "", "a.com", 0, "/", CSPSource::NoWildcard, | |
| 163 CSPSource::NoWildcard); | |
| 164 EXPECT_FALSE(source.matches(KURL(base, "http://a.com"))); | |
| 165 EXPECT_TRUE(source.matches(KURL(base, "https://a.com"))); | |
| 166 EXPECT_FALSE(source.matches(KURL(base, "http-so://a.com"))); | |
| 167 EXPECT_FALSE(source.matches(KURL(base, "https-so://a.com"))); | |
|
arthursonzogni
2017/02/14 12:54:22
Same unexpected behavior as in https://codereview.
Mike West
2017/02/15 06:46:00
Yes, please file a bug and add a TODO. I don't kno
arthursonzogni
2017/02/15 12:00:14
Done, BUG=692442
| |
| 168 EXPECT_FALSE(source.matches(KURL(base, "ftp://a.com"))); | |
| 169 } | |
| 170 | |
| 171 // Self scheme is not in the http familly. | |
| 172 { | |
| 173 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create()); | |
| 174 csp->setupSelf(*SecurityOrigin::createFromString("ftp://a.com/")); | |
| 175 CSPSource source(csp.get(), "", "a.com", 0, "/", CSPSource::NoWildcard, | |
| 176 CSPSource::NoWildcard); | |
| 177 EXPECT_FALSE(source.matches(KURL(base, "http://a.com"))); | |
| 178 EXPECT_TRUE(source.matches(KURL(base, "ftp://a.com"))); | |
| 179 } | |
| 180 | |
| 181 // Self scheme is unique | |
| 182 { | |
| 183 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create()); | |
| 184 csp->setupSelf( | |
| 185 *SecurityOrigin::createFromString("non-standard-scheme://a.com/")); | |
| 186 CSPSource source(csp.get(), "", "a.com", 0, "/", CSPSource::NoWildcard, | |
| 187 CSPSource::NoWildcard); | |
| 188 EXPECT_FALSE(source.matches(KURL(base, "http://a.com"))); | |
| 189 EXPECT_FALSE(source.matches(KURL(base, "non-standard-scheme://a.com"))); | |
|
arthursonzogni
2017/02/14 12:54:23
Same behavior as in https://codereview.chromium.or
Mike West
2017/02/15 06:46:00
Please file a bug and add a TODO. This seems wrong
arthursonzogni
2017/02/15 12:00:14
Done. BUG=692449
| |
| 190 } | |
| 191 } | |
| 192 | |
| 142 TEST_F(CSPSourceTest, InsecureHostSchemePortMatchesSecurePort) { | 193 TEST_F(CSPSourceTest, InsecureHostSchemePortMatchesSecurePort) { |
| 143 KURL base; | 194 KURL base; |
| 144 CSPSource source(csp.get(), "http", "example.com", 80, "/", | 195 CSPSource source(csp.get(), "http", "example.com", 80, "/", |
| 145 CSPSource::NoWildcard, CSPSource::NoWildcard); | 196 CSPSource::NoWildcard, CSPSource::NoWildcard); |
| 146 EXPECT_TRUE(source.matches(KURL(base, "http://example.com/"))); | 197 EXPECT_TRUE(source.matches(KURL(base, "http://example.com/"))); |
| 147 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:80/"))); | 198 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:80/"))); |
| 148 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:443/"))); | 199 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:443/"))); |
| 149 EXPECT_TRUE(source.matches(KURL(base, "https://example.com/"))); | 200 EXPECT_TRUE(source.matches(KURL(base, "https://example.com/"))); |
| 150 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:80/"))); | 201 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:80/"))); |
| 151 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:443/"))); | 202 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:443/"))); |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 780 normalized = B->intersect(A); | 831 normalized = B->intersect(A); |
| 781 Source intersectBA = { | 832 Source intersectBA = { |
| 782 normalized->m_scheme, normalized->m_host, | 833 normalized->m_scheme, normalized->m_host, |
| 783 normalized->m_path, normalized->m_port, | 834 normalized->m_path, normalized->m_port, |
| 784 normalized->m_hostWildcard, normalized->m_portWildcard}; | 835 normalized->m_hostWildcard, normalized->m_portWildcard}; |
| 785 EXPECT_TRUE(equalSources(intersectBA, test.normalized)); | 836 EXPECT_TRUE(equalSources(intersectBA, test.normalized)); |
| 786 } | 837 } |
| 787 } | 838 } |
| 788 | 839 |
| 789 } // namespace blink | 840 } // namespace blink |
| OLD | NEW |