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/CSPDirectiveList.h" | 6 #include "core/frame/csp/CSPDirectiveList.h" |
7 | 7 |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
10 #include "core/inspector/ConsoleMessage.h" | 10 #include "core/inspector/ConsoleMessage.h" |
11 #include "platform/ParsingUtilities.h" | 11 #include "platform/ParsingUtilities.h" |
12 #include "platform/RuntimeEnabledFeatures.h" | 12 #include "platform/RuntimeEnabledFeatures.h" |
13 #include "platform/weborigin/KURL.h" | 13 #include "platform/weborigin/KURL.h" |
14 #include "wtf/text/WTFString.h" | 14 #include "wtf/text/WTFString.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 CSPDirectiveList::CSPDirectiveList(ContentSecurityPolicy* policy, ContentSecurit yPolicyHeaderType type, ContentSecurityPolicyHeaderSource source) | 18 CSPDirectiveList::CSPDirectiveList(ContentSecurityPolicy* policy, ContentSecurit yPolicyHeaderType type, ContentSecurityPolicyHeaderSource source) |
19 : m_policy(policy) | 19 : m_policy(policy) |
20 , m_headerType(type) | 20 , m_headerType(type) |
21 , m_headerSource(source) | 21 , m_headerSource(source) |
22 , m_reportOnly(false) | 22 , m_reportOnly(false) |
23 , m_haveSandboxPolicy(false) | 23 , m_haveSandboxPolicy(false) |
24 , m_haveSuboriginPolicy(false) | |
24 , m_reflectedXSSDisposition(ReflectedXSSUnset) | 25 , m_reflectedXSSDisposition(ReflectedXSSUnset) |
25 , m_didSetReferrerPolicy(false) | 26 , m_didSetReferrerPolicy(false) |
26 , m_referrerPolicy(ReferrerPolicyDefault) | 27 , m_referrerPolicy(ReferrerPolicyDefault) |
27 { | 28 { |
28 m_reportOnly = type == ContentSecurityPolicyHeaderTypeReport; | 29 m_reportOnly = type == ContentSecurityPolicyHeaderTypeReport; |
29 } | 30 } |
30 | 31 |
31 PassOwnPtr<CSPDirectiveList> CSPDirectiveList::create(ContentSecurityPolicy* pol icy, const UChar* begin, const UChar* end, ContentSecurityPolicyHeaderType type, ContentSecurityPolicyHeaderSource source) | 32 PassOwnPtr<CSPDirectiveList> CSPDirectiveList::create(ContentSecurityPolicy* pol icy, const UChar* begin, const UChar* end, ContentSecurityPolicyHeaderType type, ContentSecurityPolicyHeaderSource source) |
32 { | 33 { |
33 OwnPtr<CSPDirectiveList> directives = adoptPtr(new CSPDirectiveList(policy, type, source)); | 34 OwnPtr<CSPDirectiveList> directives = adoptPtr(new CSPDirectiveList(policy, type, source)); |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 m_policy->reportDuplicateDirective(name); | 534 m_policy->reportDuplicateDirective(name); |
534 return; | 535 return; |
535 } | 536 } |
536 m_haveSandboxPolicy = true; | 537 m_haveSandboxPolicy = true; |
537 String invalidTokens; | 538 String invalidTokens; |
538 m_policy->enforceSandboxFlags(parseSandboxPolicy(sandboxPolicy, invalidToken s)); | 539 m_policy->enforceSandboxFlags(parseSandboxPolicy(sandboxPolicy, invalidToken s)); |
539 if (!invalidTokens.isNull()) | 540 if (!invalidTokens.isNull()) |
540 m_policy->reportInvalidSandboxFlags(invalidTokens); | 541 m_policy->reportInvalidSandboxFlags(invalidTokens); |
541 } | 542 } |
542 | 543 |
544 void CSPDirectiveList::applySuboriginPolicy(const String& name, const String& su boriginPolicy) | |
545 { | |
546 if (m_haveSuboriginPolicy) { | |
547 m_policy->reportDuplicateDirective(name); | |
548 return; | |
549 } | |
Mike West
2014/10/23 12:59:19
abarth@ is right: we shouldn't land this with <met
jww
2015/03/20 22:50:03
Done.
| |
550 m_haveSuboriginPolicy = true; | |
551 String invalidTokens; | |
Mike West
2014/10/23 12:59:19
Nit: Unused?
jww
2015/03/20 22:50:02
Done.
| |
552 String suboriginName = parseSuboriginName(suboriginPolicy); | |
553 if (!suboriginName.isNull()) { | |
Mike West
2014/10/23 12:59:19
Again, isNull or isEmpty?
jww
2015/03/20 22:50:03
See earlier comment (NULL means no suborigin; empt
| |
554 m_policy->enforceSuborigin(suboriginName); | |
555 } | |
Mike West
2014/10/23 12:59:19
Nit: No {} for oneliners.
jww
2015/03/20 22:50:03
Done.
| |
556 } | |
557 | |
543 void CSPDirectiveList::parseReflectedXSS(const String& name, const String& value ) | 558 void CSPDirectiveList::parseReflectedXSS(const String& name, const String& value ) |
544 { | 559 { |
545 if (m_reflectedXSSDisposition != ReflectedXSSUnset) { | 560 if (m_reflectedXSSDisposition != ReflectedXSSUnset) { |
546 m_policy->reportDuplicateDirective(name); | 561 m_policy->reportDuplicateDirective(name); |
547 m_reflectedXSSDisposition = ReflectedXSSInvalid; | 562 m_reflectedXSSDisposition = ReflectedXSSInvalid; |
548 return; | 563 return; |
549 } | 564 } |
550 | 565 |
551 if (value.isEmpty()) { | 566 if (value.isEmpty()) { |
552 m_reflectedXSSDisposition = ReflectedXSSInvalid; | 567 m_reflectedXSSDisposition = ReflectedXSSInvalid; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 if (position == end) | 649 if (position == end) |
635 return; | 650 return; |
636 | 651 |
637 // value1 value2 | 652 // value1 value2 |
638 // ^ | 653 // ^ |
639 m_referrerPolicy = ReferrerPolicyNever; | 654 m_referrerPolicy = ReferrerPolicyNever; |
640 m_policy->reportInvalidReferrer(value); | 655 m_policy->reportInvalidReferrer(value); |
641 | 656 |
642 } | 657 } |
643 | 658 |
659 String CSPDirectiveList::parseSuboriginName(const String& policy) | |
660 { | |
661 Vector<UChar> characters; | |
662 policy.appendTo(characters); | |
663 | |
664 const UChar* position = characters.data(); | |
665 const UChar* end = position + characters.size(); | |
666 | |
667 // Parse the name of the suborigin (no spaces, single string) | |
668 skipWhile<UChar, isASCIISpace>(position, end); | |
669 if (position == end) { | |
670 m_policy->reportInvalidSuboriginFlags("No suborigin name specified."); | |
671 return String(); | |
Mike West
2014/10/23 12:59:19
I think s/String()/emptyString()/ would be margina
jww
2015/03/20 22:50:03
As per an earlier comment, we're distinguishing a
| |
672 } | |
673 | |
674 const UChar* begin = position; | |
675 | |
676 skipWhile<UChar, isASCIIAlphanumeric>(position, end); | |
677 if (position != end && !isASCIISpace(*position)) { | |
678 m_policy->reportInvalidSuboriginFlags("Invalid character \'" + String(po sition, 1) + "\' in suborigin."); | |
679 return String(); | |
680 } | |
681 size_t length = position - begin; | |
682 skipWhile<UChar, isASCIISpace>(position, end); | |
683 if (position != end) { | |
684 m_policy->reportInvalidSuboriginFlags("Invalid whitespace in suborigin. Whitespace may only appear at the beginning and end of a suborigin, and it is ig nored."); | |
Mike West
2014/10/23 12:59:19
1. I think you can clarify this error message: "Wh
jww
2015/03/20 22:50:03
Done.
| |
685 } | |
686 | |
687 return String(begin, length); | |
688 } | |
689 | |
644 void CSPDirectiveList::addDirective(const String& name, const String& value) | 690 void CSPDirectiveList::addDirective(const String& name, const String& value) |
645 { | 691 { |
646 ASSERT(!name.isEmpty()); | 692 ASSERT(!name.isEmpty()); |
647 | 693 |
648 if (equalIgnoringCase(name, ContentSecurityPolicy::DefaultSrc)) { | 694 if (equalIgnoringCase(name, ContentSecurityPolicy::DefaultSrc)) { |
649 setCSPDirective<SourceListDirective>(name, value, m_defaultSrc); | 695 setCSPDirective<SourceListDirective>(name, value, m_defaultSrc); |
650 } else if (equalIgnoringCase(name, ContentSecurityPolicy::ScriptSrc)) { | 696 } else if (equalIgnoringCase(name, ContentSecurityPolicy::ScriptSrc)) { |
651 setCSPDirective<SourceListDirective>(name, value, m_scriptSrc); | 697 setCSPDirective<SourceListDirective>(name, value, m_scriptSrc); |
652 m_policy->usesScriptHashAlgorithms(m_scriptSrc->hashAlgorithmsUsed()); | 698 m_policy->usesScriptHashAlgorithms(m_scriptSrc->hashAlgorithmsUsed()); |
653 } else if (equalIgnoringCase(name, ContentSecurityPolicy::ObjectSrc)) { | 699 } else if (equalIgnoringCase(name, ContentSecurityPolicy::ObjectSrc)) { |
(...skipping 22 matching lines...) Expand all Loading... | |
676 } else if (equalIgnoringCase(name, ContentSecurityPolicy::ChildSrc)) { | 722 } else if (equalIgnoringCase(name, ContentSecurityPolicy::ChildSrc)) { |
677 setCSPDirective<SourceListDirective>(name, value, m_childSrc); | 723 setCSPDirective<SourceListDirective>(name, value, m_childSrc); |
678 } else if (equalIgnoringCase(name, ContentSecurityPolicy::FormAction)) { | 724 } else if (equalIgnoringCase(name, ContentSecurityPolicy::FormAction)) { |
679 setCSPDirective<SourceListDirective>(name, value, m_formAction); | 725 setCSPDirective<SourceListDirective>(name, value, m_formAction); |
680 } else if (equalIgnoringCase(name, ContentSecurityPolicy::PluginTypes)) { | 726 } else if (equalIgnoringCase(name, ContentSecurityPolicy::PluginTypes)) { |
681 setCSPDirective<MediaListDirective>(name, value, m_pluginTypes); | 727 setCSPDirective<MediaListDirective>(name, value, m_pluginTypes); |
682 } else if (equalIgnoringCase(name, ContentSecurityPolicy::ReflectedXSS)) { | 728 } else if (equalIgnoringCase(name, ContentSecurityPolicy::ReflectedXSS)) { |
683 parseReflectedXSS(name, value); | 729 parseReflectedXSS(name, value); |
684 } else if (equalIgnoringCase(name, ContentSecurityPolicy::Referrer)) { | 730 } else if (equalIgnoringCase(name, ContentSecurityPolicy::Referrer)) { |
685 parseReferrer(name, value); | 731 parseReferrer(name, value); |
732 } else if (equalIgnoringCase(name, ContentSecurityPolicy::Suborigin)) { | |
Mike West
2014/10/23 12:59:19
This ought to be guarded by the experimental flag.
jww
2015/03/20 22:50:03
Done.
| |
733 applySuboriginPolicy(name, value); | |
686 } else if (m_policy->experimentalFeaturesEnabled()) { | 734 } else if (m_policy->experimentalFeaturesEnabled()) { |
687 if (equalIgnoringCase(name, ContentSecurityPolicy::ManifestSrc)) | 735 if (equalIgnoringCase(name, ContentSecurityPolicy::ManifestSrc)) |
688 setCSPDirective<SourceListDirective>(name, value, m_manifestSrc); | 736 setCSPDirective<SourceListDirective>(name, value, m_manifestSrc); |
689 else | 737 else |
690 m_policy->reportUnsupportedDirective(name); | 738 m_policy->reportUnsupportedDirective(name); |
691 } else { | 739 } else { |
692 m_policy->reportUnsupportedDirective(name); | 740 m_policy->reportUnsupportedDirective(name); |
693 } | 741 } |
694 } | 742 } |
695 | 743 |
696 | 744 |
697 } // namespace blink | 745 } // namespace blink |
OLD | NEW |