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/CSPSource.cpp

Issue 2708873002: Stop CSP from matching independent scheme/port upgrades (Closed)
Patch Set: Created 3 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/frame/UseCounter.h" 7 #include "core/frame/UseCounter.h"
8 #include "core/frame/csp/ContentSecurityPolicy.h" 8 #include "core/frame/csp/ContentSecurityPolicy.h"
9 #include "platform/weborigin/KURL.h" 9 #include "platform/weborigin/KURL.h"
10 #include "platform/weborigin/KnownPorts.h" 10 #include "platform/weborigin/KnownPorts.h"
(...skipping 21 matching lines...) Expand all
32 ResourceRequest::RedirectStatus redirectStatus) const { 32 ResourceRequest::RedirectStatus redirectStatus) const {
33 bool schemesMatch = m_scheme.isEmpty() ? m_policy->protocolMatchesSelf(url) 33 bool schemesMatch = m_scheme.isEmpty() ? m_policy->protocolMatchesSelf(url)
34 : schemeMatches(url.protocol()); 34 : schemeMatches(url.protocol());
35 if (!schemesMatch) 35 if (!schemesMatch)
36 return false; 36 return false;
37 if (isSchemeOnly()) 37 if (isSchemeOnly())
38 return true; 38 return true;
39 bool pathsMatch = (redirectStatus == RedirectStatus::FollowedRedirect) || 39 bool pathsMatch = (redirectStatus == RedirectStatus::FollowedRedirect) ||
40 pathMatches(url.path()); 40 pathMatches(url.path());
41 return hostMatches(url.host()) && portMatches(url.port(), url.protocol()) && 41 return hostMatches(url.host()) && portMatches(url.port(), url.protocol()) &&
42 pathsMatch; 42 pathsMatch && portAndSchemeUpgradeAllowed(url.port(), url.protocol());
43 } 43 }
44 44
45 bool CSPSource::schemeMatches(const String& protocol) const { 45 bool CSPSource::schemeMatches(const String& protocol) const {
46 DCHECK_EQ(protocol, protocol.lower()); 46 DCHECK_EQ(protocol, protocol.lower());
47 if (m_scheme == "http") 47 if (m_scheme == "http")
48 return protocol == "http" || protocol == "https"; 48 return protocol == "http" || protocol == "https";
49 if (m_scheme == "ws") 49 if (m_scheme == "ws")
50 return protocol == "ws" || protocol == "wss"; 50 return protocol == "ws" || protocol == "wss";
51 return protocol == m_scheme; 51 return protocol == m_scheme;
52 } 52 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 if (!port) 106 if (!port)
107 return isDefaultPortForProtocol(m_port, protocol); 107 return isDefaultPortForProtocol(m_port, protocol);
108 108
109 if (!m_port) 109 if (!m_port)
110 return isDefaultPortForProtocol(port, protocol); 110 return isDefaultPortForProtocol(port, protocol);
111 111
112 return false; 112 return false;
113 } 113 }
114 114
115 bool CSPSource::portAndSchemeUpgradeAllowed(int port,
116 const String& protocol) const {
117 bool isPortUpgrade = false;
118 bool isSchemeUpgrade = false;
119 bool isSchemeHttp = false;
120
121 if (m_scheme.isEmpty())
122 isSchemeHttp = m_policy->protocolIsEqual("http");
Mike West 2017/02/21 14:24:04 This will return true if the page's scheme is `htt
andypaicu 2017/02/21 15:51:44 I believe that a fallback mechanism is necessary i
Mike West 2017/02/22 12:03:40 Ok, so in the case that the source doesn't specify
123 else
124 isSchemeHttp = equalIgnoringCase("http", m_scheme);
125
126 if ((m_port == 80 || (m_port == 0 && isSchemeHttp)) &&
127 (port == 443 || (port == 0 && defaultPortForProtocol(protocol) == 443)))
128 isPortUpgrade = true;
Mike West 2017/02/21 14:24:04 1) Nit: You need braces if the `if` clause is mult
andypaicu 2017/02/21 15:51:44 ::portMatches is used in a lot of places and the c
Mike West 2017/02/22 12:03:40 Then I think we should figure out how to make it i
129
130 isSchemeUpgrade = isSchemeHttp && equalIgnoringCase("https", protocol);
131
132 if (isPortUpgrade || isSchemeUpgrade)
133 return isPortUpgrade && isSchemeUpgrade;
134
135 return true;
136 }
137
115 bool CSPSource::subsumes(CSPSource* other) const { 138 bool CSPSource::subsumes(CSPSource* other) const {
116 if (!schemeMatches(other->m_scheme)) 139 if (!schemeMatches(other->m_scheme))
117 return false; 140 return false;
118 141
119 if (other->isSchemeOnly() || isSchemeOnly()) 142 if (other->isSchemeOnly() || isSchemeOnly())
120 return isSchemeOnly(); 143 return isSchemeOnly();
121 144
122 if ((m_hostWildcard == NoWildcard && other->m_hostWildcard == HasWildcard) || 145 if ((m_hostWildcard == NoWildcard && other->m_hostWildcard == HasWildcard) ||
123 (m_portWildcard == NoWildcard && other->m_portWildcard == HasWildcard)) { 146 (m_portWildcard == NoWildcard && other->m_portWildcard == HasWildcard)) {
124 return false; 147 return false;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 return false; 226 return false;
204 } 227 }
205 return true; 228 return true;
206 } 229 }
207 230
208 DEFINE_TRACE(CSPSource) { 231 DEFINE_TRACE(CSPSource) {
209 visitor->trace(m_policy); 232 visitor->trace(m_policy);
210 } 233 }
211 234
212 } // namespace blink 235 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698