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 17 matching lines...) Expand all Loading... |
28 skipWhile<UChar, isASCIISpace>(position, end); | 28 skipWhile<UChar, isASCIISpace>(position, end); |
29 if (position != end) | 29 if (position != end) |
30 return false; | 30 return false; |
31 | 31 |
32 return true; | 32 return true; |
33 } | 33 } |
34 | 34 |
35 CSPSourceList::CSPSourceList(ContentSecurityPolicy* policy, const String& direct
iveName) | 35 CSPSourceList::CSPSourceList(ContentSecurityPolicy* policy, const String& direct
iveName) |
36 : m_policy(policy) | 36 : m_policy(policy) |
37 , m_directiveName(directiveName) | 37 , m_directiveName(directiveName) |
| 38 , m_allowSelf(false) |
38 , m_allowStar(false) | 39 , m_allowStar(false) |
39 , m_allowInline(false) | 40 , m_allowInline(false) |
40 , m_allowEval(false) | 41 , m_allowEval(false) |
41 , m_hashAlgorithmsUsed(0) | 42 , m_hashAlgorithmsUsed(0) |
42 { | 43 { |
43 } | 44 } |
44 | 45 |
45 bool CSPSourceList::matches(const KURL& url) const | 46 bool CSPSourceList::matches(const KURL& url) const |
46 { | 47 { |
47 if (m_allowStar) | 48 if (m_allowStar) |
48 return true; | 49 return true; |
49 | 50 |
50 KURL effectiveURL = SecurityOrigin::shouldUseInnerURL(url) ? SecurityOrigin:
:extractInnerURL(url) : url; | 51 KURL effectiveURL = SecurityOrigin::shouldUseInnerURL(url) ? SecurityOrigin:
:extractInnerURL(url) : url; |
51 | 52 |
| 53 if (m_allowSelf && m_policy->urlMatchesSelf(effectiveURL)) |
| 54 return true; |
| 55 |
52 for (size_t i = 0; i < m_list.size(); ++i) { | 56 for (size_t i = 0; i < m_list.size(); ++i) { |
53 if (m_list[i].matches(effectiveURL)) | 57 if (m_list[i].matches(effectiveURL)) |
54 return true; | 58 return true; |
55 } | 59 } |
56 | 60 |
57 return false; | 61 return false; |
58 } | 62 } |
59 | 63 |
60 bool CSPSourceList::allowInline() const | 64 bool CSPSourceList::allowInline() const |
61 { | 65 { |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 if (position != end) | 449 if (position != end) |
446 return false; | 450 return false; |
447 | 451 |
448 bool ok; | 452 bool ok; |
449 port = charactersToIntStrict(begin, end - begin, &ok); | 453 port = charactersToIntStrict(begin, end - begin, &ok); |
450 return ok; | 454 return ok; |
451 } | 455 } |
452 | 456 |
453 void CSPSourceList::addSourceSelf() | 457 void CSPSourceList::addSourceSelf() |
454 { | 458 { |
455 m_list.append(CSPSource(m_policy, m_policy->securityOrigin()->protocol(), m_
policy->securityOrigin()->host(), m_policy->securityOrigin()->port(), String(),
false, false)); | 459 m_allowSelf = true; |
456 } | 460 } |
457 | 461 |
458 void CSPSourceList::addSourceStar() | 462 void CSPSourceList::addSourceStar() |
459 { | 463 { |
460 m_allowStar = true; | 464 m_allowStar = true; |
461 } | 465 } |
462 | 466 |
463 void CSPSourceList::addSourceUnsafeInline() | 467 void CSPSourceList::addSourceUnsafeInline() |
464 { | 468 { |
465 m_allowInline = true; | 469 m_allowInline = true; |
(...skipping 10 matching lines...) Expand all Loading... |
476 } | 480 } |
477 | 481 |
478 void CSPSourceList::addSourceHash(const ContentSecurityPolicyHashAlgorithm& algo
rithm, const DigestValue& hash) | 482 void CSPSourceList::addSourceHash(const ContentSecurityPolicyHashAlgorithm& algo
rithm, const DigestValue& hash) |
479 { | 483 { |
480 m_hashes.add(CSPHashValue(algorithm, hash)); | 484 m_hashes.add(CSPHashValue(algorithm, hash)); |
481 m_hashAlgorithmsUsed |= algorithm; | 485 m_hashAlgorithmsUsed |= algorithm; |
482 } | 486 } |
483 | 487 |
484 | 488 |
485 } // namespace blink | 489 } // namespace blink |
OLD | NEW |