| Index: Source/core/page/ContentSecurityPolicy.cpp
|
| diff --git a/Source/core/page/ContentSecurityPolicy.cpp b/Source/core/page/ContentSecurityPolicy.cpp
|
| index 7f5d43417693f8f274b31e0117a981e36e911b63..3b3899606ecfba181b46b633908396bf56539bce 100644
|
| --- a/Source/core/page/ContentSecurityPolicy.cpp
|
| +++ b/Source/core/page/ContentSecurityPolicy.cpp
|
| @@ -41,6 +41,7 @@
|
| #include "core/page/Frame.h"
|
| #include "core/page/UseCounter.h"
|
| #include "core/platform/JSONValues.h"
|
| +#include "core/platform/ParsingUtilities.h"
|
| #include "core/platform/network/FormData.h"
|
| #include "core/platform/network/ResourceResponse.h"
|
| #include "weborigin/KURL.h"
|
| @@ -165,48 +166,16 @@ UseCounter::Feature getUseCounterType(ContentSecurityPolicy::HeaderType type)
|
|
|
| } // namespace
|
|
|
| -static bool skipExactly(const UChar*& position, const UChar* end, UChar delimiter)
|
| -{
|
| - if (position < end && *position == delimiter) {
|
| - ++position;
|
| - return true;
|
| - }
|
| - return false;
|
| -}
|
| -
|
| -template<bool characterPredicate(UChar)>
|
| -static bool skipExactly(const UChar*& position, const UChar* end)
|
| -{
|
| - if (position < end && characterPredicate(*position)) {
|
| - ++position;
|
| - return true;
|
| - }
|
| - return false;
|
| -}
|
| -
|
| -static void skipUntil(const UChar*& position, const UChar* end, UChar delimiter)
|
| -{
|
| - while (position < end && *position != delimiter)
|
| - ++position;
|
| -}
|
| -
|
| -template<bool characterPredicate(UChar)>
|
| -static void skipWhile(const UChar*& position, const UChar* end)
|
| -{
|
| - while (position < end && characterPredicate(*position))
|
| - ++position;
|
| -}
|
| -
|
| static bool isSourceListNone(const UChar* begin, const UChar* end)
|
| {
|
| - skipWhile<isASCIISpace>(begin, end);
|
| + skipWhile<UChar, isASCIISpace>(begin, end);
|
|
|
| const UChar* position = begin;
|
| - skipWhile<isSourceCharacter>(position, end);
|
| + skipWhile<UChar, isSourceCharacter>(position, end);
|
| if (!equalIgnoringCase("'none'", begin, position - begin))
|
| return false;
|
|
|
| - skipWhile<isASCIISpace>(position, end);
|
| + skipWhile<UChar, isASCIISpace>(position, end);
|
| if (position != end)
|
| return false;
|
|
|
| @@ -369,12 +338,12 @@ void CSPSourceList::parse(const UChar* begin, const UChar* end)
|
|
|
| const UChar* position = begin;
|
| while (position < end) {
|
| - skipWhile<isASCIISpace>(position, end);
|
| + skipWhile<UChar, isASCIISpace>(position, end);
|
| if (position == end)
|
| return;
|
|
|
| const UChar* beginSource = position;
|
| - skipWhile<isSourceCharacter>(position, end);
|
| + skipWhile<UChar, isSourceCharacter>(position, end);
|
|
|
| String scheme, host, path;
|
| int port = 0;
|
| @@ -447,7 +416,7 @@ bool CSPSourceList::parseSource(const UChar* begin, const UChar* end,
|
| const UChar* beginPath = end;
|
| const UChar* beginPort = 0;
|
|
|
| - skipWhile<isNotColonOrSlash>(position, end);
|
| + skipWhile<UChar, isNotColonOrSlash>(position, end);
|
|
|
| if (position == end) {
|
| // host
|
| @@ -472,21 +441,21 @@ bool CSPSourceList::parseSource(const UChar* begin, const UChar* end,
|
| // scheme://host || scheme://
|
| // ^ ^
|
| if (!parseScheme(begin, position, scheme)
|
| - || !skipExactly(position, end, ':')
|
| - || !skipExactly(position, end, '/')
|
| - || !skipExactly(position, end, '/'))
|
| + || !skipExactly<UChar>(position, end, ':')
|
| + || !skipExactly<UChar>(position, end, '/')
|
| + || !skipExactly<UChar>(position, end, '/'))
|
| return false;
|
| if (position == end)
|
| return true;
|
| beginHost = position;
|
| - skipWhile<isNotColonOrSlash>(position, end);
|
| + skipWhile<UChar, isNotColonOrSlash>(position, end);
|
| }
|
|
|
| if (position < end && *position == ':') {
|
| // host:port || scheme://host:port
|
| // ^ ^
|
| beginPort = position;
|
| - skipUntil(position, end, '/');
|
| + skipUntil<UChar>(position, end, '/');
|
| }
|
| }
|
|
|
| @@ -529,7 +498,7 @@ bool CSPSourceList::parseNonce(const UChar* begin, const UChar* end, String& non
|
| const UChar* position = begin + noncePrefix.length();
|
| const UChar* nonceBegin = position;
|
|
|
| - skipWhile<isNonceCharacter>(position, end);
|
| + skipWhile<UChar, isNonceCharacter>(position, end);
|
| ASSERT(nonceBegin <= position);
|
|
|
| if (((position + 1) != end && *position != '\'') || !(position - nonceBegin))
|
| @@ -552,10 +521,10 @@ bool CSPSourceList::parseScheme(const UChar* begin, const UChar* end, String& sc
|
|
|
| const UChar* position = begin;
|
|
|
| - if (!skipExactly<isASCIIAlpha>(position, end))
|
| + if (!skipExactly<UChar, isASCIIAlpha>(position, end))
|
| return false;
|
|
|
| - skipWhile<isSchemeContinuationCharacter>(position, end);
|
| + skipWhile<UChar, isSchemeContinuationCharacter>(position, end);
|
|
|
| if (position != end)
|
| return false;
|
| @@ -579,25 +548,25 @@ bool CSPSourceList::parseHost(const UChar* begin, const UChar* end, String& host
|
|
|
| const UChar* position = begin;
|
|
|
| - if (skipExactly(position, end, '*')) {
|
| + if (skipExactly<UChar>(position, end, '*')) {
|
| hostHasWildcard = true;
|
|
|
| if (position == end)
|
| return true;
|
|
|
| - if (!skipExactly(position, end, '.'))
|
| + if (!skipExactly<UChar>(position, end, '.'))
|
| return false;
|
| }
|
|
|
| const UChar* hostBegin = position;
|
|
|
| while (position < end) {
|
| - if (!skipExactly<isHostCharacter>(position, end))
|
| + if (!skipExactly<UChar, isHostCharacter>(position, end))
|
| return false;
|
|
|
| - skipWhile<isHostCharacter>(position, end);
|
| + skipWhile<UChar, isHostCharacter>(position, end);
|
|
|
| - if (position < end && !skipExactly(position, end, '.'))
|
| + if (position < end && !skipExactly<UChar>(position, end, '.'))
|
| return false;
|
| }
|
|
|
| @@ -612,7 +581,7 @@ bool CSPSourceList::parsePath(const UChar* begin, const UChar* end, String& path
|
| ASSERT(path.isEmpty());
|
|
|
| const UChar* position = begin;
|
| - skipWhile<isPathComponentCharacter>(position, end);
|
| + skipWhile<UChar, isPathComponentCharacter>(position, end);
|
| // path/to/file.js?query=string || path/to/file.js#anchor
|
| // ^ ^
|
| if (position < end)
|
| @@ -633,7 +602,7 @@ bool CSPSourceList::parsePort(const UChar* begin, const UChar* end, int& port, b
|
| ASSERT(!port);
|
| ASSERT(!portHasWildcard);
|
|
|
| - if (!skipExactly(begin, end, ':'))
|
| + if (!skipExactly<UChar>(begin, end, ':'))
|
| ASSERT_NOT_REACHED();
|
|
|
| if (begin == end)
|
| @@ -646,7 +615,7 @@ bool CSPSourceList::parsePort(const UChar* begin, const UChar* end, int& port, b
|
| }
|
|
|
| const UChar* position = begin;
|
| - skipWhile<isASCIIDigit>(position, end);
|
| + skipWhile<UChar, isASCIIDigit>(position, end);
|
|
|
| if (position != end)
|
| return false;
|
| @@ -730,41 +699,41 @@ private:
|
| while (position < end) {
|
| // _____ OR _____mime1/mime1
|
| // ^ ^
|
| - skipWhile<isASCIISpace>(position, end);
|
| + skipWhile<UChar, isASCIISpace>(position, end);
|
| if (position == end)
|
| return;
|
|
|
| // mime1/mime1 mime2/mime2
|
| // ^
|
| begin = position;
|
| - if (!skipExactly<isMediaTypeCharacter>(position, end)) {
|
| - skipWhile<isNotASCIISpace>(position, end);
|
| + if (!skipExactly<UChar, isMediaTypeCharacter>(position, end)) {
|
| + skipWhile<UChar, isNotASCIISpace>(position, end);
|
| policy()->reportInvalidPluginTypes(String(begin, position - begin));
|
| continue;
|
| }
|
| - skipWhile<isMediaTypeCharacter>(position, end);
|
| + skipWhile<UChar, isMediaTypeCharacter>(position, end);
|
|
|
| // mime1/mime1 mime2/mime2
|
| // ^
|
| - if (!skipExactly(position, end, '/')) {
|
| - skipWhile<isNotASCIISpace>(position, end);
|
| + if (!skipExactly<UChar>(position, end, '/')) {
|
| + skipWhile<UChar, isNotASCIISpace>(position, end);
|
| policy()->reportInvalidPluginTypes(String(begin, position - begin));
|
| continue;
|
| }
|
|
|
| // mime1/mime1 mime2/mime2
|
| // ^
|
| - if (!skipExactly<isMediaTypeCharacter>(position, end)) {
|
| - skipWhile<isNotASCIISpace>(position, end);
|
| + if (!skipExactly<UChar, isMediaTypeCharacter>(position, end)) {
|
| + skipWhile<UChar, isNotASCIISpace>(position, end);
|
| policy()->reportInvalidPluginTypes(String(begin, position - begin));
|
| continue;
|
| }
|
| - skipWhile<isMediaTypeCharacter>(position, end);
|
| + skipWhile<UChar, isMediaTypeCharacter>(position, end);
|
|
|
| // mime1/mime1 mime2/mime2 OR mime1/mime1 OR mime1/mime1/error
|
| // ^ ^ ^
|
| if (position < end && isNotASCIISpace(*position)) {
|
| - skipWhile<isNotASCIISpace>(position, end);
|
| + skipWhile<UChar, isNotASCIISpace>(position, end);
|
| policy()->reportInvalidPluginTypes(String(begin, position - begin));
|
| continue;
|
| }
|
| @@ -1213,7 +1182,7 @@ void CSPDirectiveList::parse(const UChar* begin, const UChar* end)
|
| const UChar* position = begin;
|
| while (position < end) {
|
| const UChar* directiveBegin = position;
|
| - skipUntil(position, end, ';');
|
| + skipUntil<UChar>(position, end, ';');
|
|
|
| String name, value;
|
| if (parseDirective(directiveBegin, position, name, value)) {
|
| @@ -1222,7 +1191,7 @@ void CSPDirectiveList::parse(const UChar* begin, const UChar* end)
|
| }
|
|
|
| ASSERT(position == end || *position == ';');
|
| - skipExactly(position, end, ';');
|
| + skipExactly<UChar>(position, end, ';');
|
| }
|
| }
|
|
|
| @@ -1236,18 +1205,18 @@ bool CSPDirectiveList::parseDirective(const UChar* begin, const UChar* end, Stri
|
| ASSERT(value.isEmpty());
|
|
|
| const UChar* position = begin;
|
| - skipWhile<isASCIISpace>(position, end);
|
| + skipWhile<UChar, isASCIISpace>(position, end);
|
|
|
| // Empty directive (e.g. ";;;"). Exit early.
|
| if (position == end)
|
| return false;
|
|
|
| const UChar* nameBegin = position;
|
| - skipWhile<isDirectiveNameCharacter>(position, end);
|
| + skipWhile<UChar, isDirectiveNameCharacter>(position, end);
|
|
|
| // The directive-name must be non-empty.
|
| if (nameBegin == position) {
|
| - skipWhile<isNotASCIISpace>(position, end);
|
| + skipWhile<UChar, isNotASCIISpace>(position, end);
|
| m_policy->reportUnsupportedDirective(String(nameBegin, position - nameBegin));
|
| return false;
|
| }
|
| @@ -1257,16 +1226,16 @@ bool CSPDirectiveList::parseDirective(const UChar* begin, const UChar* end, Stri
|
| if (position == end)
|
| return true;
|
|
|
| - if (!skipExactly<isASCIISpace>(position, end)) {
|
| - skipWhile<isNotASCIISpace>(position, end);
|
| + if (!skipExactly<UChar, isASCIISpace>(position, end)) {
|
| + skipWhile<UChar, isNotASCIISpace>(position, end);
|
| m_policy->reportUnsupportedDirective(String(nameBegin, position - nameBegin));
|
| return false;
|
| }
|
|
|
| - skipWhile<isASCIISpace>(position, end);
|
| + skipWhile<UChar, isASCIISpace>(position, end);
|
|
|
| const UChar* valueBegin = position;
|
| - skipWhile<isDirectiveValueCharacter>(position, end);
|
| + skipWhile<UChar, isDirectiveValueCharacter>(position, end);
|
|
|
| if (position != end) {
|
| m_policy->reportInvalidDirectiveValueCharacter(name, String(valueBegin, end - valueBegin));
|
| @@ -1295,10 +1264,10 @@ void CSPDirectiveList::parseReportURI(const String& name, const String& value)
|
| const UChar* end = position + characters.size();
|
|
|
| while (position < end) {
|
| - skipWhile<isASCIISpace>(position, end);
|
| + skipWhile<UChar, isASCIISpace>(position, end);
|
|
|
| const UChar* urlBegin = position;
|
| - skipWhile<isNotASCIISpace>(position, end);
|
| + skipWhile<UChar, isNotASCIISpace>(position, end);
|
|
|
| if (urlBegin < position) {
|
| String url = String(urlBegin, position - urlBegin);
|
| @@ -1351,9 +1320,9 @@ void CSPDirectiveList::parseReflectedXSS(const String& name, const String& value
|
| const UChar* position = characters.data();
|
| const UChar* end = position + characters.size();
|
|
|
| - skipWhile<isASCIISpace>(position, end);
|
| + skipWhile<UChar, isASCIISpace>(position, end);
|
| const UChar* begin = position;
|
| - skipWhile<isNotASCIISpace>(position, end);
|
| + skipWhile<UChar, isNotASCIISpace>(position, end);
|
|
|
| // value1
|
| // ^
|
| @@ -1369,7 +1338,7 @@ void CSPDirectiveList::parseReflectedXSS(const String& name, const String& value
|
| return;
|
| }
|
|
|
| - skipWhile<isASCIISpace>(position, end);
|
| + skipWhile<UChar, isASCIISpace>(position, end);
|
| if (position == end && m_reflectedXSSDisposition != ContentSecurityPolicy::ReflectedXSSUnset)
|
| return;
|
|
|
| @@ -1476,7 +1445,7 @@ void ContentSecurityPolicy::addPolicyFromHeaderValue(const String& header, Heade
|
| // separated chunk as a separate header.
|
| const UChar* position = begin;
|
| while (position < end) {
|
| - skipUntil(position, end, ',');
|
| + skipUntil<UChar>(position, end, ',');
|
|
|
| // header1,header2 OR header1
|
| // ^ ^
|
| @@ -1490,7 +1459,7 @@ void ContentSecurityPolicy::addPolicyFromHeaderValue(const String& header, Heade
|
|
|
| // Skip the comma, and begin the next header from the current position.
|
| ASSERT(position == end || *position == ',');
|
| - skipExactly(position, end, ',');
|
| + skipExactly<UChar>(position, end, ',');
|
| begin = position;
|
| }
|
| }
|
|
|