| OLD | NEW |
| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/frame/csp/CSPSourceList.h" | 6 #include "core/frame/csp/CSPSourceList.h" |
| 7 | 7 |
| 8 #include "core/frame/csp/CSPSource.h" | 8 #include "core/frame/csp/CSPSource.h" |
| 9 #include "core/frame/csp/ContentSecurityPolicy.h" | 9 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 10 #include "platform/ParsingUtilities.h" | 10 #include "platform/ParsingUtilities.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 while (position < end) { | 104 while (position < end) { |
| 105 skipWhile<UChar, isASCIISpace>(position, end); | 105 skipWhile<UChar, isASCIISpace>(position, end); |
| 106 if (position == end) | 106 if (position == end) |
| 107 return; | 107 return; |
| 108 | 108 |
| 109 const UChar* beginSource = position; | 109 const UChar* beginSource = position; |
| 110 skipWhile<UChar, isSourceCharacter>(position, end); | 110 skipWhile<UChar, isSourceCharacter>(position, end); |
| 111 | 111 |
| 112 String scheme, host, path; | 112 String scheme, host, path; |
| 113 int port = 0; | 113 int port = 0; |
| 114 bool hostHasWildcard = false; | 114 CSPSource::WildcardDisposition hostWildcard = CSPSource::NoWildcard; |
| 115 bool portHasWildcard = false; | 115 CSPSource::WildcardDisposition portWildcard = CSPSource::NoWildcard; |
| 116 | 116 |
| 117 if (parseSource(beginSource, position, scheme, host, port, path, hostHas
Wildcard, portHasWildcard)) { | 117 if (parseSource(beginSource, position, scheme, host, port, path, hostWil
dcard, portWildcard)) { |
| 118 // Wildcard hosts and keyword sources ('self', 'unsafe-inline', | 118 // Wildcard hosts and keyword sources ('self', 'unsafe-inline', |
| 119 // etc.) aren't stored in m_list, but as attributes on the source | 119 // etc.) aren't stored in m_list, but as attributes on the source |
| 120 // list itself. | 120 // list itself. |
| 121 if (scheme.isEmpty() && host.isEmpty()) | 121 if (scheme.isEmpty() && host.isEmpty()) |
| 122 continue; | 122 continue; |
| 123 if (m_policy->isDirectiveName(host)) | 123 if (m_policy->isDirectiveName(host)) |
| 124 m_policy->reportDirectiveAsSourceExpression(m_directiveName, hos
t); | 124 m_policy->reportDirectiveAsSourceExpression(m_directiveName, hos
t); |
| 125 m_list.append(CSPSource(m_policy, scheme, host, port, path, hostHasW
ildcard, portHasWildcard)); | 125 m_list.append(CSPSource(m_policy, scheme, host, port, path, hostWild
card, portWildcard)); |
| 126 } else { | 126 } else { |
| 127 m_policy->reportInvalidSourceExpression(m_directiveName, String(begi
nSource, position - beginSource)); | 127 m_policy->reportInvalidSourceExpression(m_directiveName, String(begi
nSource, position - beginSource)); |
| 128 } | 128 } |
| 129 | 129 |
| 130 ASSERT(position == end || isASCIISpace(*position)); | 130 ASSERT(position == end || isASCIISpace(*position)); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 // source = scheme ":" | 134 // source = scheme ":" |
| 135 // / ( [ scheme "://" ] host [ port ] [ path ] ) | 135 // / ( [ scheme "://" ] host [ port ] [ path ] ) |
| 136 // / "'self'" | 136 // / "'self'" |
| 137 bool CSPSourceList::parseSource(const UChar* begin, const UChar* end, String& sc
heme, String& host, int& port, String& path, bool& hostHasWildcard, bool& portHa
sWildcard) | 137 bool CSPSourceList::parseSource(const UChar* begin, const UChar* end, String& sc
heme, String& host, int& port, String& path, CSPSource::WildcardDisposition& hos
tWildcard, CSPSource::WildcardDisposition& portWildcard) |
| 138 { | 138 { |
| 139 if (begin == end) | 139 if (begin == end) |
| 140 return false; | 140 return false; |
| 141 | 141 |
| 142 if (equalIgnoringCase("'none'", begin, end - begin)) | 142 if (equalIgnoringCase("'none'", begin, end - begin)) |
| 143 return false; | 143 return false; |
| 144 | 144 |
| 145 if (end - begin == 1 && *begin == '*') { | 145 if (end - begin == 1 && *begin == '*') { |
| 146 addSourceStar(); | 146 addSourceStar(); |
| 147 return true; | 147 return true; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 const UChar* position = begin; | 184 const UChar* position = begin; |
| 185 const UChar* beginHost = begin; | 185 const UChar* beginHost = begin; |
| 186 const UChar* beginPath = end; | 186 const UChar* beginPath = end; |
| 187 const UChar* beginPort = 0; | 187 const UChar* beginPort = 0; |
| 188 | 188 |
| 189 skipWhile<UChar, isNotColonOrSlash>(position, end); | 189 skipWhile<UChar, isNotColonOrSlash>(position, end); |
| 190 | 190 |
| 191 if (position == end) { | 191 if (position == end) { |
| 192 // host | 192 // host |
| 193 // ^ | 193 // ^ |
| 194 return parseHost(beginHost, position, host, hostHasWildcard); | 194 return parseHost(beginHost, position, host, hostWildcard); |
| 195 } | 195 } |
| 196 | 196 |
| 197 if (position < end && *position == '/') { | 197 if (position < end && *position == '/') { |
| 198 // host/path || host/ || / | 198 // host/path || host/ || / |
| 199 // ^ ^ ^ | 199 // ^ ^ ^ |
| 200 return parseHost(beginHost, position, host, hostHasWildcard) && parsePat
h(position, end, path); | 200 return parseHost(beginHost, position, host, hostWildcard) && parsePath(p
osition, end, path); |
| 201 } | 201 } |
| 202 | 202 |
| 203 if (position < end && *position == ':') { | 203 if (position < end && *position == ':') { |
| 204 if (end - position == 1) { | 204 if (end - position == 1) { |
| 205 // scheme: | 205 // scheme: |
| 206 // ^ | 206 // ^ |
| 207 return parseScheme(begin, position, scheme); | 207 return parseScheme(begin, position, scheme); |
| 208 } | 208 } |
| 209 | 209 |
| 210 if (position[1] == '/') { | 210 if (position[1] == '/') { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 230 } | 230 } |
| 231 | 231 |
| 232 if (position < end && *position == '/') { | 232 if (position < end && *position == '/') { |
| 233 // scheme://host/path || scheme://host:port/path | 233 // scheme://host/path || scheme://host:port/path |
| 234 // ^ ^ | 234 // ^ ^ |
| 235 if (position == beginHost) | 235 if (position == beginHost) |
| 236 return false; | 236 return false; |
| 237 beginPath = position; | 237 beginPath = position; |
| 238 } | 238 } |
| 239 | 239 |
| 240 if (!parseHost(beginHost, beginPort ? beginPort : beginPath, host, hostHasWi
ldcard)) | 240 if (!parseHost(beginHost, beginPort ? beginPort : beginPath, host, hostWildc
ard)) |
| 241 return false; | 241 return false; |
| 242 | 242 |
| 243 if (beginPort) { | 243 if (beginPort) { |
| 244 if (!parsePort(beginPort, beginPath, port, portHasWildcard)) | 244 if (!parsePort(beginPort, beginPath, port, portWildcard)) |
| 245 return false; | 245 return false; |
| 246 } else { | 246 } else { |
| 247 port = 0; | 247 port = 0; |
| 248 } | 248 } |
| 249 | 249 |
| 250 if (beginPath != end) { | 250 if (beginPath != end) { |
| 251 if (!parsePath(beginPath, end, path)) | 251 if (!parsePath(beginPath, end, path)) |
| 252 return false; | 252 return false; |
| 253 } | 253 } |
| 254 | 254 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 return false; | 359 return false; |
| 360 | 360 |
| 361 scheme = String(begin, end - begin); | 361 scheme = String(begin, end - begin); |
| 362 return true; | 362 return true; |
| 363 } | 363 } |
| 364 | 364 |
| 365 // host = [ "*." ] 1*host-char *( "." 1*host-char ) | 365 // host = [ "*." ] 1*host-char *( "." 1*host-char ) |
| 366 // / "*" | 366 // / "*" |
| 367 // host-char = ALPHA / DIGIT / "-" | 367 // host-char = ALPHA / DIGIT / "-" |
| 368 // | 368 // |
| 369 bool CSPSourceList::parseHost(const UChar* begin, const UChar* end, String& host
, bool& hostHasWildcard) | 369 bool CSPSourceList::parseHost(const UChar* begin, const UChar* end, String& host
, CSPSource::WildcardDisposition& hostWildcard) |
| 370 { | 370 { |
| 371 ASSERT(begin <= end); | 371 ASSERT(begin <= end); |
| 372 ASSERT(host.isEmpty()); | 372 ASSERT(host.isEmpty()); |
| 373 ASSERT(!hostHasWildcard); | 373 ASSERT(hostWildcard == CSPSource::NoWildcard); |
| 374 | 374 |
| 375 if (begin == end) | 375 if (begin == end) |
| 376 return false; | 376 return false; |
| 377 | 377 |
| 378 const UChar* position = begin; | 378 const UChar* position = begin; |
| 379 | 379 |
| 380 if (skipExactly<UChar>(position, end, '*')) { | 380 if (skipExactly<UChar>(position, end, '*')) { |
| 381 hostHasWildcard = true; | 381 hostWildcard = CSPSource::HasWildcard; |
| 382 | 382 |
| 383 if (position == end) | 383 if (position == end) |
| 384 return true; | 384 return true; |
| 385 | 385 |
| 386 if (!skipExactly<UChar>(position, end, '.')) | 386 if (!skipExactly<UChar>(position, end, '.')) |
| 387 return false; | 387 return false; |
| 388 } | 388 } |
| 389 | 389 |
| 390 const UChar* hostBegin = position; | 390 const UChar* hostBegin = position; |
| 391 | 391 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 418 | 418 |
| 419 path = decodeURLEscapeSequences(String(begin, position - begin)); | 419 path = decodeURLEscapeSequences(String(begin, position - begin)); |
| 420 | 420 |
| 421 ASSERT(position <= end); | 421 ASSERT(position <= end); |
| 422 ASSERT(position == end || (*position == '#' || *position == '?')); | 422 ASSERT(position == end || (*position == '#' || *position == '?')); |
| 423 return true; | 423 return true; |
| 424 } | 424 } |
| 425 | 425 |
| 426 // port = ":" ( 1*DIGIT / "*" ) | 426 // port = ":" ( 1*DIGIT / "*" ) |
| 427 // | 427 // |
| 428 bool CSPSourceList::parsePort(const UChar* begin, const UChar* end, int& port, b
ool& portHasWildcard) | 428 bool CSPSourceList::parsePort(const UChar* begin, const UChar* end, int& port, C
SPSource::WildcardDisposition& portWildcard) |
| 429 { | 429 { |
| 430 ASSERT(begin <= end); | 430 ASSERT(begin <= end); |
| 431 ASSERT(!port); | 431 ASSERT(!port); |
| 432 ASSERT(!portHasWildcard); | 432 ASSERT(portWildcard == CSPSource::NoWildcard); |
| 433 | 433 |
| 434 if (!skipExactly<UChar>(begin, end, ':')) | 434 if (!skipExactly<UChar>(begin, end, ':')) |
| 435 ASSERT_NOT_REACHED(); | 435 ASSERT_NOT_REACHED(); |
| 436 | 436 |
| 437 if (begin == end) | 437 if (begin == end) |
| 438 return false; | 438 return false; |
| 439 | 439 |
| 440 if (end - begin == 1 && *begin == '*') { | 440 if (end - begin == 1 && *begin == '*') { |
| 441 port = 0; | 441 port = 0; |
| 442 portHasWildcard = true; | 442 portWildcard = CSPSource::HasWildcard; |
| 443 return true; | 443 return true; |
| 444 } | 444 } |
| 445 | 445 |
| 446 const UChar* position = begin; | 446 const UChar* position = begin; |
| 447 skipWhile<UChar, isASCIIDigit>(position, end); | 447 skipWhile<UChar, isASCIIDigit>(position, end); |
| 448 | 448 |
| 449 if (position != end) | 449 if (position != end) |
| 450 return false; | 450 return false; |
| 451 | 451 |
| 452 bool ok; | 452 bool ok; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 480 } | 480 } |
| 481 | 481 |
| 482 void CSPSourceList::addSourceHash(const ContentSecurityPolicyHashAlgorithm& algo
rithm, const DigestValue& hash) | 482 void CSPSourceList::addSourceHash(const ContentSecurityPolicyHashAlgorithm& algo
rithm, const DigestValue& hash) |
| 483 { | 483 { |
| 484 m_hashes.add(CSPHashValue(algorithm, hash)); | 484 m_hashes.add(CSPHashValue(algorithm, hash)); |
| 485 m_hashAlgorithmsUsed |= algorithm; | 485 m_hashAlgorithmsUsed |= algorithm; |
| 486 } | 486 } |
| 487 | 487 |
| 488 | 488 |
| 489 } // namespace blink | 489 } // namespace blink |
| OLD | NEW |