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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
diff --git a/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp b/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
index 3b5ed5cce1c5cc84c004ccdbf3283fdcdd77ed51..edd48a6246771a106978888ef9c819704d87d7e5 100644
--- a/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
@@ -39,7 +39,7 @@ bool CSPSource::matches(const KURL& url,
bool pathsMatch = (redirectStatus == RedirectStatus::FollowedRedirect) ||
pathMatches(url.path());
return hostMatches(url.host()) && portMatches(url.port(), url.protocol()) &&
- pathsMatch;
+ pathsMatch && portAndSchemeUpgradeAllowed(url.port(), url.protocol());
}
bool CSPSource::schemeMatches(const String& protocol) const {
@@ -112,6 +112,29 @@ bool CSPSource::portMatches(int port, const String& protocol) const {
return false;
}
+bool CSPSource::portAndSchemeUpgradeAllowed(int port,
+ const String& protocol) const {
+ bool isPortUpgrade = false;
+ bool isSchemeUpgrade = false;
+ bool isSchemeHttp = false;
+
+ if (m_scheme.isEmpty())
+ 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
+ else
+ isSchemeHttp = equalIgnoringCase("http", m_scheme);
+
+ if ((m_port == 80 || (m_port == 0 && isSchemeHttp)) &&
+ (port == 443 || (port == 0 && defaultPortForProtocol(protocol) == 443)))
+ 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
+
+ isSchemeUpgrade = isSchemeHttp && equalIgnoringCase("https", protocol);
+
+ if (isPortUpgrade || isSchemeUpgrade)
+ return isPortUpgrade && isSchemeUpgrade;
+
+ return true;
+}
+
bool CSPSource::subsumes(CSPSource* other) const {
if (!schemeMatches(other->m_scheme))
return false;

Powered by Google App Engine
This is Rietveld 408576698