Chromium Code Reviews| Index: Source/core/frame/csp/CSPDirectiveList.cpp |
| diff --git a/Source/core/frame/csp/CSPDirectiveList.cpp b/Source/core/frame/csp/CSPDirectiveList.cpp |
| index e7dbb996d57cd1090d3233ed4aafc458d2a35e19..183364b3adf6d90a0aae3f664bfc4cec72d06741 100644 |
| --- a/Source/core/frame/csp/CSPDirectiveList.cpp |
| +++ b/Source/core/frame/csp/CSPDirectiveList.cpp |
| @@ -43,7 +43,8 @@ CSPDirectiveList::CSPDirectiveList(ContentSecurityPolicy* policy, ContentSecurit |
| , m_headerType(type) |
| , m_headerSource(source) |
| , m_reportOnly(false) |
| - , m_haveSandboxPolicy(false) |
| + , m_hasSandboxPolicy(false) |
| + , m_hasSuboriginPolicy(false) |
| , m_reflectedXSSDisposition(ReflectedXSSUnset) |
| , m_didSetReferrerPolicy(false) |
| , m_referrerPolicy(ReferrerPolicyDefault) |
| @@ -532,11 +533,11 @@ void CSPDirectiveList::applySandboxPolicy(const String& name, const String& sand |
| m_policy->reportInvalidInReportOnly(name); |
| return; |
| } |
| - if (m_haveSandboxPolicy) { |
| + if (m_hasSandboxPolicy) { |
| m_policy->reportDuplicateDirective(name); |
| return; |
| } |
| - m_haveSandboxPolicy = true; |
| + m_hasSandboxPolicy = true; |
| String invalidTokens; |
| m_policy->enforceSandboxFlags(parseSandboxPolicy(sandboxPolicy, invalidTokens)); |
| if (!invalidTokens.isNull()) |
| @@ -576,6 +577,23 @@ void CSPDirectiveList::enableInsecureRequestsUpgrade(const String& name, const S |
| m_policy->reportValueForEmptyDirective(name, value); |
| } |
| +void CSPDirectiveList::applySuboriginPolicy(const String& name, const String& suboriginPolicy) |
| +{ |
|
Mike West
2015/03/23 07:32:55
Nit: ASSERT(RuntimeEnabledFeatures::suboriginsEnab
jww
2015/04/11 02:52:36
Done.
|
| + if (m_headerSource == ContentSecurityPolicyHeaderSourceMeta) { |
| + m_policy->reportSuboriginInMeta(suboriginPolicy); |
| + return; |
| + } |
| + |
| + if (m_hasSuboriginPolicy) { |
| + m_policy->reportDuplicateDirective(name); |
| + return; |
| + } |
| + m_hasSuboriginPolicy = true; |
| + String suboriginName = parseSuboriginName(suboriginPolicy); |
| + if (!suboriginName.isNull()) |
| + m_policy->enforceSuborigin(suboriginName); |
| +} |
| + |
| void CSPDirectiveList::parseReflectedXSS(const String& name, const String& value) |
| { |
| if (m_reflectedXSSDisposition != ReflectedXSSUnset) { |
| @@ -676,7 +694,38 @@ void CSPDirectiveList::parseReferrer(const String& name, const String& value) |
| // ^ |
| m_referrerPolicy = ReferrerPolicyNever; |
| m_policy->reportInvalidReferrer(value); |
| +} |
| + |
| +String CSPDirectiveList::parseSuboriginName(const String& policy) |
|
Mike West
2015/03/23 07:32:55
We really need to add some parser unittests. Would
|
| +{ |
| + Vector<UChar> characters; |
| + policy.appendTo(characters); |
| + |
| + const UChar* position = characters.data(); |
| + const UChar* end = position + characters.size(); |
| + |
| + // Parse the name of the suborigin (no spaces, single string) |
| + skipWhile<UChar, isASCIISpace>(position, end); |
| + if (position == end) { |
| + m_policy->reportInvalidSuboriginFlags("No suborigin name specified."); |
| + return String(); |
| + } |
| + |
| + const UChar* begin = position; |
| + |
| + skipWhile<UChar, isASCIIAlphanumeric>(position, end); |
| + if (position != end && !isASCIISpace(*position)) { |
| + m_policy->reportInvalidSuboriginFlags("Invalid character \'" + String(position, 1) + "\' in suborigin."); |
| + return String(); |
| + } |
| + size_t length = position - begin; |
| + skipWhile<UChar, isASCIISpace>(position, end); |
| + if (position != end) { |
| + m_policy->reportInvalidSuboriginFlags("Whitespace is not allowed in suborigin names."); |
| + return String(); |
| + } |
| + return String(begin, length); |
| } |
| void CSPDirectiveList::addDirective(const String& name, const String& value) |
| @@ -721,6 +770,8 @@ void CSPDirectiveList::addDirective(const String& name, const String& value) |
| parseReflectedXSS(name, value); |
| } else if (equalIgnoringCase(name, ContentSecurityPolicy::Referrer)) { |
| parseReferrer(name, value); |
| + } else if (RuntimeEnabledFeatures::suboriginsEnabled() && equalIgnoringCase(name, ContentSecurityPolicy::Suborigin)) { |
| + applySuboriginPolicy(name, value); |
| } else if (m_policy->experimentalFeaturesEnabled()) { |
| if (equalIgnoringCase(name, ContentSecurityPolicy::ManifestSrc)) |
| setCSPDirective<SourceListDirective>(name, value, m_manifestSrc); |