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

Unified Diff: third_party/WebKit/Source/core/frame/csp/CSPSource.h

Issue 2708873002: Stop CSP from matching independent scheme/port upgrades (Closed)
Patch Set: Refactoring port/scheme matching logic to have an easier time with auto-upgrading 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.h
diff --git a/third_party/WebKit/Source/core/frame/csp/CSPSource.h b/third_party/WebKit/Source/core/frame/csp/CSPSource.h
index a01b57157a0a6a12722fa0b80a03a780125317b9..a994100f59d233bddd6fb886f8b012cfa86f9930 100644
--- a/third_party/WebKit/Source/core/frame/csp/CSPSource.h
+++ b/third_party/WebKit/Source/core/frame/csp/CSPSource.h
@@ -22,6 +22,20 @@ class CORE_EXPORT CSPSource : public GarbageCollectedFinalized<CSPSource> {
public:
enum WildcardDisposition { NoWildcard, HasWildcard };
+ // NotMatching is the only negative member, the rest are different types of
+ // matches. NotMatching should always be 0 to let if statements work nicely
Mike West 2017/02/24 10:56:28 Nit: Did you consider making this an `enum class`
andypaicu 2017/03/13 10:07:20 I have no strong feelings one way or the other htt
+ enum PortMatchingResult {
+ PortNotMatching = 0,
+ PortMatchingWildcard,
+ PortMatchingUpgrade,
+ PortMatchingExact
+ };
Mike West 2017/02/24 10:56:28 Tiny nit: Newline after the enum.
andypaicu 2017/03/13 10:07:20 Done.
+ enum SchemeMatchingResult {
+ SchemeNotMatching = 0,
+ SchemeMatchingUpgrade,
+ SchemeMatchingExact
+ };
+
CSPSource(ContentSecurityPolicy*,
const String& scheme,
const String& host,
@@ -63,13 +77,29 @@ class CORE_EXPORT CSPSource : public GarbageCollectedFinalized<CSPSource> {
FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, SubsumesWithSelf);
FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, GetSources);
- bool schemeMatches(const String&) const;
+ SchemeMatchingResult schemeMatches(const String&) const;
bool hostMatches(const String&) const;
bool pathMatches(const String&) const;
// Protocol is necessary to determine default port if it is zero.
- bool portMatches(int port, const String& protocol) const;
+ PortMatchingResult portMatches(int port, const String& protocol) const;
bool isSimilar(CSPSource* other) const;
+ // Helper inline functions for Port and Scheme MatchingResult enums
+ bool inline requiresUpgrade(const PortMatchingResult result) const {
+ return result == PortMatchingUpgrade;
+ }
+ bool inline requiresUpgrade(const SchemeMatchingResult result) const {
+ return result == SchemeMatchingUpgrade;
+ }
+
+ bool inline canUpgrade(const PortMatchingResult result) const {
+ return result == PortMatchingUpgrade || result == PortMatchingWildcard;
+ }
+
+ bool inline canUpgrade(const SchemeMatchingResult result) const {
+ return result == SchemeMatchingUpgrade;
+ }
+
Member<ContentSecurityPolicy> m_policy;
String m_scheme;
String m_host;

Powered by Google App Engine
This is Rietveld 408576698