OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google, Inc. All rights reserved. | 2 * Copyright (C) 2011 Google, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 return isASCIIAlphanumeric(c) || c == '-'; | 62 return isASCIIAlphanumeric(c) || c == '-'; |
63 } | 63 } |
64 | 64 |
65 bool isDirectiveValueCharacter(UChar c) | 65 bool isDirectiveValueCharacter(UChar c) |
66 { | 66 { |
67 return isASCIISpace(c) || (c >= 0x21 && c <= 0x7e); // Whitespace + VCHAR | 67 return isASCIISpace(c) || (c >= 0x21 && c <= 0x7e); // Whitespace + VCHAR |
68 } | 68 } |
69 | 69 |
70 bool isNonceCharacter(UChar c) | 70 bool isNonceCharacter(UChar c) |
71 { | 71 { |
72 return (c >= 0x21 && c <= 0x7e) && c != ',' && c != ';'; // VCHAR - ',' - ';
' | 72 return isASCIIAlphanumeric(c); |
73 } | 73 } |
74 | 74 |
75 bool isSourceCharacter(UChar c) | 75 bool isSourceCharacter(UChar c) |
76 { | 76 { |
77 return !isASCIISpace(c); | 77 return !isASCIISpace(c); |
78 } | 78 } |
79 | 79 |
80 bool isPathComponentCharacter(UChar c) | 80 bool isPathComponentCharacter(UChar c) |
81 { | 81 { |
82 return c != '?' && c != '#'; | 82 return c != '?' && c != '#'; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 static const char objectSrc[] = "object-src"; | 117 static const char objectSrc[] = "object-src"; |
118 static const char reportURI[] = "report-uri"; | 118 static const char reportURI[] = "report-uri"; |
119 static const char sandbox[] = "sandbox"; | 119 static const char sandbox[] = "sandbox"; |
120 static const char scriptSrc[] = "script-src"; | 120 static const char scriptSrc[] = "script-src"; |
121 static const char styleSrc[] = "style-src"; | 121 static const char styleSrc[] = "style-src"; |
122 | 122 |
123 // CSP 1.1 Directives | 123 // CSP 1.1 Directives |
124 static const char baseURI[] = "base-uri"; | 124 static const char baseURI[] = "base-uri"; |
125 static const char formAction[] = "form-action"; | 125 static const char formAction[] = "form-action"; |
126 static const char pluginTypes[] = "plugin-types"; | 126 static const char pluginTypes[] = "plugin-types"; |
127 static const char scriptNonce[] = "script-nonce"; | |
128 static const char reflectedXSS[] = "reflected-xss"; | 127 static const char reflectedXSS[] = "reflected-xss"; |
129 | 128 |
130 bool isDirectiveName(const String& name) | 129 bool isDirectiveName(const String& name) |
131 { | 130 { |
132 return (equalIgnoringCase(name, connectSrc) | 131 return (equalIgnoringCase(name, connectSrc) |
133 || equalIgnoringCase(name, defaultSrc) | 132 || equalIgnoringCase(name, defaultSrc) |
134 || equalIgnoringCase(name, fontSrc) | 133 || equalIgnoringCase(name, fontSrc) |
135 || equalIgnoringCase(name, frameSrc) | 134 || equalIgnoringCase(name, frameSrc) |
136 || equalIgnoringCase(name, imgSrc) | 135 || equalIgnoringCase(name, imgSrc) |
137 || equalIgnoringCase(name, mediaSrc) | 136 || equalIgnoringCase(name, mediaSrc) |
138 || equalIgnoringCase(name, objectSrc) | 137 || equalIgnoringCase(name, objectSrc) |
139 || equalIgnoringCase(name, reportURI) | 138 || equalIgnoringCase(name, reportURI) |
140 || equalIgnoringCase(name, sandbox) | 139 || equalIgnoringCase(name, sandbox) |
141 || equalIgnoringCase(name, scriptSrc) | 140 || equalIgnoringCase(name, scriptSrc) |
142 || equalIgnoringCase(name, styleSrc) | 141 || equalIgnoringCase(name, styleSrc) |
143 || equalIgnoringCase(name, baseURI) | 142 || equalIgnoringCase(name, baseURI) |
144 || equalIgnoringCase(name, formAction) | 143 || equalIgnoringCase(name, formAction) |
145 || equalIgnoringCase(name, pluginTypes) | 144 || equalIgnoringCase(name, pluginTypes) |
146 || equalIgnoringCase(name, scriptNonce) | |
147 || equalIgnoringCase(name, reflectedXSS) | 145 || equalIgnoringCase(name, reflectedXSS) |
148 ); | 146 ); |
149 } | 147 } |
150 | 148 |
151 UseCounter::Feature getUseCounterType(ContentSecurityPolicy::HeaderType type) | 149 UseCounter::Feature getUseCounterType(ContentSecurityPolicy::HeaderType type) |
152 { | 150 { |
153 switch (type) { | 151 switch (type) { |
154 case ContentSecurityPolicy::PrefixedEnforce: | 152 case ContentSecurityPolicy::PrefixedEnforce: |
155 return UseCounter::PrefixedContentSecurityPolicy; | 153 return UseCounter::PrefixedContentSecurityPolicy; |
156 case ContentSecurityPolicy::Enforce: | 154 case ContentSecurityPolicy::Enforce: |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 }; | 311 }; |
314 | 312 |
315 class CSPSourceList { | 313 class CSPSourceList { |
316 public: | 314 public: |
317 CSPSourceList(ContentSecurityPolicy*, const String& directiveName); | 315 CSPSourceList(ContentSecurityPolicy*, const String& directiveName); |
318 | 316 |
319 void parse(const String&); | 317 void parse(const String&); |
320 bool matches(const KURL&); | 318 bool matches(const KURL&); |
321 bool allowInline() const { return m_allowInline; } | 319 bool allowInline() const { return m_allowInline; } |
322 bool allowEval() const { return m_allowEval; } | 320 bool allowEval() const { return m_allowEval; } |
| 321 bool allowNonce(const String& nonce) const { return !nonce.isNull() && m_non
ces.contains(nonce); } |
323 | 322 |
324 private: | 323 private: |
325 void parse(const UChar* begin, const UChar* end); | 324 void parse(const UChar* begin, const UChar* end); |
326 | 325 |
327 bool parseSource(const UChar* begin, const UChar* end, String& scheme, Strin
g& host, int& port, String& path, bool& hostHasWildcard, bool& portHasWildcard); | 326 bool parseSource(const UChar* begin, const UChar* end, String& scheme, Strin
g& host, int& port, String& path, bool& hostHasWildcard, bool& portHasWildcard); |
328 bool parseScheme(const UChar* begin, const UChar* end, String& scheme); | 327 bool parseScheme(const UChar* begin, const UChar* end, String& scheme); |
329 bool parseHost(const UChar* begin, const UChar* end, String& host, bool& hos
tHasWildcard); | 328 bool parseHost(const UChar* begin, const UChar* end, String& host, bool& hos
tHasWildcard); |
330 bool parsePort(const UChar* begin, const UChar* end, int& port, bool& portHa
sWildcard); | 329 bool parsePort(const UChar* begin, const UChar* end, int& port, bool& portHa
sWildcard); |
331 bool parsePath(const UChar* begin, const UChar* end, String& path); | 330 bool parsePath(const UChar* begin, const UChar* end, String& path); |
| 331 bool parseNonce(const UChar* begin, const UChar* end, String& nonce); |
332 | 332 |
333 void addSourceSelf(); | 333 void addSourceSelf(); |
334 void addSourceStar(); | 334 void addSourceStar(); |
335 void addSourceUnsafeInline(); | 335 void addSourceUnsafeInline(); |
336 void addSourceUnsafeEval(); | 336 void addSourceUnsafeEval(); |
| 337 void addSourceNonce(const String& nonce); |
337 | 338 |
338 ContentSecurityPolicy* m_policy; | 339 ContentSecurityPolicy* m_policy; |
339 Vector<CSPSource> m_list; | 340 Vector<CSPSource> m_list; |
340 String m_directiveName; | 341 String m_directiveName; |
341 bool m_allowStar; | 342 bool m_allowStar; |
342 bool m_allowInline; | 343 bool m_allowInline; |
343 bool m_allowEval; | 344 bool m_allowEval; |
| 345 HashSet<String> m_nonces; |
344 }; | 346 }; |
345 | 347 |
346 CSPSourceList::CSPSourceList(ContentSecurityPolicy* policy, const String& direct
iveName) | 348 CSPSourceList::CSPSourceList(ContentSecurityPolicy* policy, const String& direct
iveName) |
347 : m_policy(policy) | 349 : m_policy(policy) |
348 , m_directiveName(directiveName) | 350 , m_directiveName(directiveName) |
349 , m_allowStar(false) | 351 , m_allowStar(false) |
350 , m_allowInline(false) | 352 , m_allowInline(false) |
351 , m_allowEval(false) | 353 , m_allowEval(false) |
352 { | 354 { |
353 } | 355 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 if (equalIgnoringCase("'unsafe-inline'", begin, end - begin)) { | 440 if (equalIgnoringCase("'unsafe-inline'", begin, end - begin)) { |
439 addSourceUnsafeInline(); | 441 addSourceUnsafeInline(); |
440 return true; | 442 return true; |
441 } | 443 } |
442 | 444 |
443 if (equalIgnoringCase("'unsafe-eval'", begin, end - begin)) { | 445 if (equalIgnoringCase("'unsafe-eval'", begin, end - begin)) { |
444 addSourceUnsafeEval(); | 446 addSourceUnsafeEval(); |
445 return true; | 447 return true; |
446 } | 448 } |
447 | 449 |
| 450 String nonce; |
| 451 if (!parseNonce(begin, end, nonce)) |
| 452 return false; |
| 453 |
| 454 if (!nonce.isNull()) { |
| 455 addSourceNonce(nonce); |
| 456 return true; |
| 457 } |
| 458 |
448 const UChar* position = begin; | 459 const UChar* position = begin; |
449 const UChar* beginHost = begin; | 460 const UChar* beginHost = begin; |
450 const UChar* beginPath = end; | 461 const UChar* beginPath = end; |
451 const UChar* beginPort = 0; | 462 const UChar* beginPort = 0; |
452 | 463 |
453 skipWhile<isNotColonOrSlash>(position, end); | 464 skipWhile<isNotColonOrSlash>(position, end); |
454 | 465 |
455 if (position == end) { | 466 if (position == end) { |
456 // host | 467 // host |
457 // ^ | 468 // ^ |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 } | 528 } |
518 | 529 |
519 if (beginPath != end) { | 530 if (beginPath != end) { |
520 if (!parsePath(beginPath, end, path)) | 531 if (!parsePath(beginPath, end, path)) |
521 return false; | 532 return false; |
522 } | 533 } |
523 | 534 |
524 return true; | 535 return true; |
525 } | 536 } |
526 | 537 |
| 538 // nonce-source = "'nonce-" nonce-value "'" |
| 539 // nonce-value = *( ALPHA / DIGIT ) |
| 540 // |
| 541 bool CSPSourceList::parseNonce(const UChar* begin, const UChar* end, String& non
ce) |
| 542 { |
| 543 DEFINE_STATIC_LOCAL(const String, noncePrefix, (ASCIILiteral("'nonce-"))); |
| 544 |
| 545 if (!equalIgnoringCase(noncePrefix.characters(), begin, noncePrefix.length()
)) |
| 546 return true; |
| 547 |
| 548 const UChar* position = begin + noncePrefix.length(); |
| 549 const UChar* nonceBegin = position; |
| 550 |
| 551 skipWhile<isNonceCharacter>(position, end); |
| 552 ASSERT(nonceBegin <= position); |
| 553 nonce = String(nonceBegin, position - nonceBegin); |
| 554 |
| 555 if ((position + 1) != end && *position != '\'') { |
| 556 return false; |
| 557 } |
| 558 |
| 559 return true; |
| 560 } |
| 561 |
527 // ; <scheme> production from RFC 3986 | 562 // ; <scheme> production from RFC 3986 |
528 // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) | 563 // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) |
529 // | 564 // |
530 bool CSPSourceList::parseScheme(const UChar* begin, const UChar* end, String& sc
heme) | 565 bool CSPSourceList::parseScheme(const UChar* begin, const UChar* end, String& sc
heme) |
531 { | 566 { |
532 ASSERT(begin <= end); | 567 ASSERT(begin <= end); |
533 ASSERT(scheme.isEmpty()); | 568 ASSERT(scheme.isEmpty()); |
534 | 569 |
535 if (begin == end) | 570 if (begin == end) |
536 return false; | 571 return false; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 void CSPSourceList::addSourceUnsafeInline() | 689 void CSPSourceList::addSourceUnsafeInline() |
655 { | 690 { |
656 m_allowInline = true; | 691 m_allowInline = true; |
657 } | 692 } |
658 | 693 |
659 void CSPSourceList::addSourceUnsafeEval() | 694 void CSPSourceList::addSourceUnsafeEval() |
660 { | 695 { |
661 m_allowEval = true; | 696 m_allowEval = true; |
662 } | 697 } |
663 | 698 |
| 699 void CSPSourceList::addSourceNonce(const String& nonce) |
| 700 { |
| 701 m_nonces.add(nonce); |
| 702 } |
| 703 |
664 class CSPDirective { | 704 class CSPDirective { |
665 public: | 705 public: |
666 CSPDirective(const String& name, const String& value, ContentSecurityPolicy*
policy) | 706 CSPDirective(const String& name, const String& value, ContentSecurityPolicy*
policy) |
667 : m_name(name) | 707 : m_name(name) |
668 , m_text(name + ' ' + value) | 708 , m_text(name + ' ' + value) |
669 , m_policy(policy) | 709 , m_policy(policy) |
670 { | 710 { |
671 } | 711 } |
672 | 712 |
673 const String& text() const { return m_text; } | 713 const String& text() const { return m_text; } |
674 | 714 |
675 protected: | 715 protected: |
676 const ContentSecurityPolicy* policy() const { return m_policy; } | 716 const ContentSecurityPolicy* policy() const { return m_policy; } |
677 | 717 |
678 private: | 718 private: |
679 String m_name; | 719 String m_name; |
680 String m_text; | 720 String m_text; |
681 ContentSecurityPolicy* m_policy; | 721 ContentSecurityPolicy* m_policy; |
682 }; | 722 }; |
683 | 723 |
684 class NonceDirective : public CSPDirective { | |
685 public: | |
686 NonceDirective(const String& name, const String& value, ContentSecurityPolic
y* policy) | |
687 : CSPDirective(name, value, policy) | |
688 { | |
689 parse(value); | |
690 } | |
691 | |
692 bool allows(const String& nonce) const | |
693 { | |
694 return (!m_scriptNonce.isEmpty() && nonce.stripWhiteSpace() == m_scriptN
once); | |
695 } | |
696 | |
697 private: | |
698 void parse(const String& value) | |
699 { | |
700 String nonce; | |
701 const UChar* position = value.characters(); | |
702 const UChar* end = position + value.length(); | |
703 | |
704 skipWhile<isASCIISpace>(position, end); | |
705 const UChar* nonceBegin = position; | |
706 if (position == end) { | |
707 policy()->reportInvalidNonce(String()); | |
708 m_scriptNonce = ""; | |
709 return; | |
710 } | |
711 skipWhile<isNonceCharacter>(position, end); | |
712 if (nonceBegin < position) | |
713 nonce = String(nonceBegin, position - nonceBegin); | |
714 | |
715 // Trim off trailing whitespace: If we're not at the end of the string,
log | |
716 // an error. | |
717 skipWhile<isASCIISpace>(position, end); | |
718 if (position < end) { | |
719 policy()->reportInvalidNonce(value); | |
720 m_scriptNonce = ""; | |
721 } else | |
722 m_scriptNonce = nonce; | |
723 } | |
724 | |
725 String m_scriptNonce; | |
726 }; | |
727 | |
728 class MediaListDirective : public CSPDirective { | 724 class MediaListDirective : public CSPDirective { |
729 public: | 725 public: |
730 MediaListDirective(const String& name, const String& value, ContentSecurityP
olicy* policy) | 726 MediaListDirective(const String& name, const String& value, ContentSecurityP
olicy* policy) |
731 : CSPDirective(name, value, policy) | 727 : CSPDirective(name, value, policy) |
732 { | 728 { |
733 parse(value); | 729 parse(value); |
734 } | 730 } |
735 | 731 |
736 bool allows(const String& type) | 732 bool allows(const String& type) |
737 { | 733 { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 m_sourceList.parse(value); | 806 m_sourceList.parse(value); |
811 } | 807 } |
812 | 808 |
813 bool allows(const KURL& url) | 809 bool allows(const KURL& url) |
814 { | 810 { |
815 return m_sourceList.matches(url.isEmpty() ? policy()->url() : url); | 811 return m_sourceList.matches(url.isEmpty() ? policy()->url() : url); |
816 } | 812 } |
817 | 813 |
818 bool allowInline() const { return m_sourceList.allowInline(); } | 814 bool allowInline() const { return m_sourceList.allowInline(); } |
819 bool allowEval() const { return m_sourceList.allowEval(); } | 815 bool allowEval() const { return m_sourceList.allowEval(); } |
| 816 bool allowNonce(const String& nonce) const { return m_sourceList.allowNonce(
nonce.stripWhiteSpace()); } |
820 | 817 |
821 private: | 818 private: |
822 CSPSourceList m_sourceList; | 819 CSPSourceList m_sourceList; |
823 }; | 820 }; |
824 | 821 |
825 class CSPDirectiveList { | 822 class CSPDirectiveList { |
826 WTF_MAKE_FAST_ALLOCATED; | 823 WTF_MAKE_FAST_ALLOCATED; |
827 public: | 824 public: |
828 static PassOwnPtr<CSPDirectiveList> create(ContentSecurityPolicy*, const Str
ing&, ContentSecurityPolicy::HeaderType); | 825 static PassOwnPtr<CSPDirectiveList> create(ContentSecurityPolicy*, const Str
ing&, ContentSecurityPolicy::HeaderType); |
829 | 826 |
830 const String& header() const { return m_header; } | 827 const String& header() const { return m_header; } |
831 ContentSecurityPolicy::HeaderType headerType() const { return m_headerType;
} | 828 ContentSecurityPolicy::HeaderType headerType() const { return m_headerType;
} |
832 | 829 |
833 bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber&
contextLine, ContentSecurityPolicy::ReportingStatus) const; | 830 bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber&
contextLine, ContentSecurityPolicy::ReportingStatus) const; |
834 bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNu
mber& contextLine, ContentSecurityPolicy::ReportingStatus) const; | 831 bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNu
mber& contextLine, ContentSecurityPolicy::ReportingStatus) const; |
835 bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& c
ontextLine, ContentSecurityPolicy::ReportingStatus) const; | 832 bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& c
ontextLine, ContentSecurityPolicy::ReportingStatus) const; |
836 bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& co
ntextLine, ContentSecurityPolicy::ReportingStatus) const; | 833 bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& co
ntextLine, ContentSecurityPolicy::ReportingStatus) const; |
837 bool allowEval(ScriptState*, ContentSecurityPolicy::ReportingStatus) const; | 834 bool allowEval(ScriptState*, ContentSecurityPolicy::ReportingStatus) const; |
838 bool allowScriptNonce(const String& nonce, const String& contextURL, const W
TF::OrdinalNumber& contextLine, const KURL&) const; | |
839 bool allowPluginType(const String& type, const String& typeAttribute, const
KURL&, ContentSecurityPolicy::ReportingStatus) const; | 835 bool allowPluginType(const String& type, const String& typeAttribute, const
KURL&, ContentSecurityPolicy::ReportingStatus) const; |
840 | 836 |
841 bool allowScriptFromSource(const KURL&, ContentSecurityPolicy::ReportingStat
us) const; | 837 bool allowScriptFromSource(const KURL&, ContentSecurityPolicy::ReportingStat
us) const; |
842 bool allowObjectFromSource(const KURL&, ContentSecurityPolicy::ReportingStat
us) const; | 838 bool allowObjectFromSource(const KURL&, ContentSecurityPolicy::ReportingStat
us) const; |
843 bool allowChildFrameFromSource(const KURL&, ContentSecurityPolicy::Reporting
Status) const; | 839 bool allowChildFrameFromSource(const KURL&, ContentSecurityPolicy::Reporting
Status) const; |
844 bool allowImageFromSource(const KURL&, ContentSecurityPolicy::ReportingStatu
s) const; | 840 bool allowImageFromSource(const KURL&, ContentSecurityPolicy::ReportingStatu
s) const; |
845 bool allowStyleFromSource(const KURL&, ContentSecurityPolicy::ReportingStatu
s) const; | 841 bool allowStyleFromSource(const KURL&, ContentSecurityPolicy::ReportingStatu
s) const; |
846 bool allowFontFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus
) const; | 842 bool allowFontFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus
) const; |
847 bool allowMediaFromSource(const KURL&, ContentSecurityPolicy::ReportingStatu
s) const; | 843 bool allowMediaFromSource(const KURL&, ContentSecurityPolicy::ReportingStatu
s) const; |
848 bool allowConnectToSource(const KURL&, ContentSecurityPolicy::ReportingStatu
s) const; | 844 bool allowConnectToSource(const KURL&, ContentSecurityPolicy::ReportingStatu
s) const; |
849 bool allowFormAction(const KURL&, ContentSecurityPolicy::ReportingStatus) co
nst; | 845 bool allowFormAction(const KURL&, ContentSecurityPolicy::ReportingStatus) co
nst; |
850 bool allowBaseURI(const KURL&, ContentSecurityPolicy::ReportingStatus) const
; | 846 bool allowBaseURI(const KURL&, ContentSecurityPolicy::ReportingStatus) const
; |
| 847 bool allowNonce(const String&) const; |
851 | 848 |
852 void gatherReportURIs(DOMStringList&) const; | 849 void gatherReportURIs(DOMStringList&) const; |
853 const String& evalDisabledErrorMessage() { return m_evalDisabledErrorMessage
; } | 850 const String& evalDisabledErrorMessage() { return m_evalDisabledErrorMessage
; } |
854 ContentSecurityPolicy::ReflectedXSSDisposition reflectedXSSDisposition() con
st { return m_reflectedXSSDisposition; } | 851 ContentSecurityPolicy::ReflectedXSSDisposition reflectedXSSDisposition() con
st { return m_reflectedXSSDisposition; } |
855 bool isReportOnly() const { return m_reportOnly; } | 852 bool isReportOnly() const { return m_reportOnly; } |
856 const Vector<KURL>& reportURIs() const { return m_reportURIs; } | 853 const Vector<KURL>& reportURIs() const { return m_reportURIs; } |
857 | 854 |
858 private: | 855 private: |
859 CSPDirectiveList(ContentSecurityPolicy*, ContentSecurityPolicy::HeaderType); | 856 CSPDirectiveList(ContentSecurityPolicy*, ContentSecurityPolicy::HeaderType); |
860 | 857 |
861 void parse(const String&); | 858 void parse(const String&); |
862 | 859 |
863 bool parseDirective(const UChar* begin, const UChar* end, String& name, Stri
ng& value); | 860 bool parseDirective(const UChar* begin, const UChar* end, String& name, Stri
ng& value); |
864 void parseReportURI(const String& name, const String& value); | 861 void parseReportURI(const String& name, const String& value); |
865 void parseScriptNonce(const String& name, const String& value); | |
866 void parsePluginTypes(const String& name, const String& value); | 862 void parsePluginTypes(const String& name, const String& value); |
867 void parseReflectedXSS(const String& name, const String& value); | 863 void parseReflectedXSS(const String& name, const String& value); |
868 void addDirective(const String& name, const String& value); | 864 void addDirective(const String& name, const String& value); |
869 void applySandboxPolicy(const String& name, const String& sandboxPolicy); | 865 void applySandboxPolicy(const String& name, const String& sandboxPolicy); |
870 | 866 |
871 template <class CSPDirectiveType> | 867 template <class CSPDirectiveType> |
872 void setCSPDirective(const String& name, const String& value, OwnPtr<CSPDire
ctiveType>&); | 868 void setCSPDirective(const String& name, const String& value, OwnPtr<CSPDire
ctiveType>&); |
873 | 869 |
874 SourceListDirective* operativeDirective(SourceListDirective*) const; | 870 SourceListDirective* operativeDirective(SourceListDirective*) const; |
875 void reportViolation(const String& directiveText, const String& effectiveDir
ective, const String& consoleMessage, const KURL& blockedURL = KURL(), const Str
ing& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::Ordinal
Number::beforeFirst(), ScriptState* = 0) const; | 871 void reportViolation(const String& directiveText, const String& effectiveDir
ective, const String& consoleMessage, const KURL& blockedURL = KURL(), const Str
ing& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::Ordinal
Number::beforeFirst(), ScriptState* = 0) const; |
876 | 872 |
877 bool checkEval(SourceListDirective*) const; | 873 bool checkEval(SourceListDirective*) const; |
878 bool checkInline(SourceListDirective*) const; | 874 bool checkInline(SourceListDirective*) const; |
879 bool checkNonce(NonceDirective*, const String&) const; | 875 bool checkNonce(SourceListDirective*, const String&) const; |
880 bool checkSource(SourceListDirective*, const KURL&) const; | 876 bool checkSource(SourceListDirective*, const KURL&) const; |
881 bool checkMediaType(MediaListDirective*, const String& type, const String& t
ypeAttribute) const; | 877 bool checkMediaType(MediaListDirective*, const String& type, const String& t
ypeAttribute) const; |
882 | 878 |
883 void setEvalDisabledErrorMessage(const String& errorMessage) { m_evalDisable
dErrorMessage = errorMessage; } | 879 void setEvalDisabledErrorMessage(const String& errorMessage) { m_evalDisable
dErrorMessage = errorMessage; } |
884 | 880 |
885 bool checkEvalAndReportViolation(SourceListDirective*, const String& console
Message, const String& contextURL = String(), const WTF::OrdinalNumber& contextL
ine = WTF::OrdinalNumber::beforeFirst(), ScriptState* = 0) const; | 881 bool checkEvalAndReportViolation(SourceListDirective*, const String& console
Message, const String& contextURL = String(), const WTF::OrdinalNumber& contextL
ine = WTF::OrdinalNumber::beforeFirst(), ScriptState* = 0) const; |
886 bool checkInlineAndReportViolation(SourceListDirective*, const String& conso
leMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine, bool
isScript) const; | 882 bool checkInlineAndReportViolation(SourceListDirective*, const String& conso
leMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine, bool
isScript) const; |
887 bool checkNonceAndReportViolation(NonceDirective*, const String& nonce, cons
t String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& co
ntextLine) const; | |
888 | 883 |
889 bool checkSourceAndReportViolation(SourceListDirective*, const KURL&, const
String& effectiveDirective) const; | 884 bool checkSourceAndReportViolation(SourceListDirective*, const KURL&, const
String& effectiveDirective) const; |
890 bool checkMediaTypeAndReportViolation(MediaListDirective*, const String& typ
e, const String& typeAttribute, const String& consoleMessage) const; | 885 bool checkMediaTypeAndReportViolation(MediaListDirective*, const String& typ
e, const String& typeAttribute, const String& consoleMessage) const; |
891 | 886 |
892 bool denyIfEnforcingPolicy() const { return m_reportOnly; } | 887 bool denyIfEnforcingPolicy() const { return m_reportOnly; } |
893 | 888 |
894 ContentSecurityPolicy* m_policy; | 889 ContentSecurityPolicy* m_policy; |
895 | 890 |
896 String m_header; | 891 String m_header; |
897 ContentSecurityPolicy::HeaderType m_headerType; | 892 ContentSecurityPolicy::HeaderType m_headerType; |
898 | 893 |
899 bool m_reportOnly; | 894 bool m_reportOnly; |
900 bool m_haveSandboxPolicy; | 895 bool m_haveSandboxPolicy; |
901 ContentSecurityPolicy::ReflectedXSSDisposition m_reflectedXSSDisposition; | 896 ContentSecurityPolicy::ReflectedXSSDisposition m_reflectedXSSDisposition; |
902 | 897 |
903 OwnPtr<MediaListDirective> m_pluginTypes; | 898 OwnPtr<MediaListDirective> m_pluginTypes; |
904 OwnPtr<NonceDirective> m_scriptNonce; | |
905 OwnPtr<SourceListDirective> m_baseURI; | 899 OwnPtr<SourceListDirective> m_baseURI; |
906 OwnPtr<SourceListDirective> m_connectSrc; | 900 OwnPtr<SourceListDirective> m_connectSrc; |
907 OwnPtr<SourceListDirective> m_defaultSrc; | 901 OwnPtr<SourceListDirective> m_defaultSrc; |
908 OwnPtr<SourceListDirective> m_fontSrc; | 902 OwnPtr<SourceListDirective> m_fontSrc; |
909 OwnPtr<SourceListDirective> m_formAction; | 903 OwnPtr<SourceListDirective> m_formAction; |
910 OwnPtr<SourceListDirective> m_frameSrc; | 904 OwnPtr<SourceListDirective> m_frameSrc; |
911 OwnPtr<SourceListDirective> m_imgSrc; | 905 OwnPtr<SourceListDirective> m_imgSrc; |
912 OwnPtr<SourceListDirective> m_mediaSrc; | 906 OwnPtr<SourceListDirective> m_mediaSrc; |
913 OwnPtr<SourceListDirective> m_objectSrc; | 907 OwnPtr<SourceListDirective> m_objectSrc; |
914 OwnPtr<SourceListDirective> m_scriptSrc; | 908 OwnPtr<SourceListDirective> m_scriptSrc; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 bool CSPDirectiveList::checkEval(SourceListDirective* directive) const | 948 bool CSPDirectiveList::checkEval(SourceListDirective* directive) const |
955 { | 949 { |
956 return !directive || directive->allowEval(); | 950 return !directive || directive->allowEval(); |
957 } | 951 } |
958 | 952 |
959 bool CSPDirectiveList::checkInline(SourceListDirective* directive) const | 953 bool CSPDirectiveList::checkInline(SourceListDirective* directive) const |
960 { | 954 { |
961 return !directive || directive->allowInline(); | 955 return !directive || directive->allowInline(); |
962 } | 956 } |
963 | 957 |
964 bool CSPDirectiveList::checkNonce(NonceDirective* directive, const String& nonce
) const | 958 bool CSPDirectiveList::checkNonce(SourceListDirective* directive, const String&
nonce) const |
965 { | 959 { |
966 return !directive || directive->allows(nonce); | 960 return !directive || directive->allowNonce(nonce); |
967 } | 961 } |
968 | 962 |
969 bool CSPDirectiveList::checkSource(SourceListDirective* directive, const KURL& u
rl) const | 963 bool CSPDirectiveList::checkSource(SourceListDirective* directive, const KURL& u
rl) const |
970 { | 964 { |
971 return !directive || directive->allows(url); | 965 return !directive || directive->allows(url); |
972 } | 966 } |
973 | 967 |
974 bool CSPDirectiveList::checkMediaType(MediaListDirective* directive, const Strin
g& type, const String& typeAttribute) const | 968 bool CSPDirectiveList::checkMediaType(MediaListDirective* directive, const Strin
g& type, const String& typeAttribute) const |
975 { | 969 { |
976 if (!directive) | 970 if (!directive) |
(...skipping 18 matching lines...) Expand all Loading... |
995 suffix = " Note that 'script-src' was not explicitly set, so 'default-sr
c' is used as a fallback."; | 989 suffix = " Note that 'script-src' was not explicitly set, so 'default-sr
c' is used as a fallback."; |
996 | 990 |
997 reportViolation(directive->text(), scriptSrc, consoleMessage + "\"" + direct
ive->text() + "\"." + suffix + "\n", KURL(), contextURL, contextLine, state); | 991 reportViolation(directive->text(), scriptSrc, consoleMessage + "\"" + direct
ive->text() + "\"." + suffix + "\n", KURL(), contextURL, contextLine, state); |
998 if (!m_reportOnly) { | 992 if (!m_reportOnly) { |
999 m_policy->reportBlockedScriptExecutionToInspector(directive->text()); | 993 m_policy->reportBlockedScriptExecutionToInspector(directive->text()); |
1000 return false; | 994 return false; |
1001 } | 995 } |
1002 return true; | 996 return true; |
1003 } | 997 } |
1004 | 998 |
1005 bool CSPDirectiveList::checkNonceAndReportViolation(NonceDirective* directive, c
onst String& nonce, const String& consoleMessage, const String& contextURL, cons
t WTF::OrdinalNumber& contextLine) const | |
1006 { | |
1007 if (checkNonce(directive, nonce)) | |
1008 return true; | |
1009 reportViolation(directive->text(), scriptNonce, consoleMessage + "\"" + dire
ctive->text() + "\".\n", KURL(), contextURL, contextLine); | |
1010 return denyIfEnforcingPolicy(); | |
1011 } | |
1012 | |
1013 bool CSPDirectiveList::checkMediaTypeAndReportViolation(MediaListDirective* dire
ctive, const String& type, const String& typeAttribute, const String& consoleMes
sage) const | 999 bool CSPDirectiveList::checkMediaTypeAndReportViolation(MediaListDirective* dire
ctive, const String& type, const String& typeAttribute, const String& consoleMes
sage) const |
1014 { | 1000 { |
1015 if (checkMediaType(directive, type, typeAttribute)) | 1001 if (checkMediaType(directive, type, typeAttribute)) |
1016 return true; | 1002 return true; |
1017 | 1003 |
1018 String message = makeString(consoleMessage, "\'", directive->text(), "\'."); | 1004 String message = makeString(consoleMessage, "\'", directive->text(), "\'."); |
1019 if (typeAttribute.isEmpty()) | 1005 if (typeAttribute.isEmpty()) |
1020 message = message + " When enforcing the 'plugin-types' directive, the p
lugin's media type must be explicitly declared with a 'type' attribute on the co
ntaining element (e.g. '<object type=\"[TYPE GOES HERE]\" ...>')."; | 1006 message = message + " When enforcing the 'plugin-types' directive, the p
lugin's media type must be explicitly declared with a 'type' attribute on the co
ntaining element (e.g. '<object type=\"[TYPE GOES HERE]\" ...>')."; |
1021 | 1007 |
1022 reportViolation(directive->text(), pluginTypes, message + "\n", KURL()); | 1008 reportViolation(directive->text(), pluginTypes, message + "\n", KURL()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 suffix = " Note that '" + effectiveDirective + "' was not explicitly set
, so 'default-src' is used as a fallback."; | 1060 suffix = " Note that '" + effectiveDirective + "' was not explicitly set
, so 'default-src' is used as a fallback."; |
1075 | 1061 |
1076 reportViolation(directive->text(), effectiveDirective, prefix + url.elidedSt
ring() + "' because it violates the following Content Security Policy directive:
\"" + directive->text() + "\"." + suffix + "\n", url); | 1062 reportViolation(directive->text(), effectiveDirective, prefix + url.elidedSt
ring() + "' because it violates the following Content Security Policy directive:
\"" + directive->text() + "\"." + suffix + "\n", url); |
1077 return denyIfEnforcingPolicy(); | 1063 return denyIfEnforcingPolicy(); |
1078 } | 1064 } |
1079 | 1065 |
1080 bool CSPDirectiveList::allowJavaScriptURLs(const String& contextURL, const WTF::
OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStat
us) const | 1066 bool CSPDirectiveList::allowJavaScriptURLs(const String& contextURL, const WTF::
OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStat
us) const |
1081 { | 1067 { |
1082 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to execut
e JavaScript URL because it violates the following Content Security Policy direc
tive: "))); | 1068 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to execut
e JavaScript URL because it violates the following Content Security Policy direc
tive: "))); |
1083 if (reportingStatus == ContentSecurityPolicy::SendReport) { | 1069 if (reportingStatus == ContentSecurityPolicy::SendReport) { |
1084 return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get
()), consoleMessage, contextURL, contextLine, true) | 1070 return checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get(
)), consoleMessage, contextURL, contextLine, true); |
1085 && checkNonceAndReportViolation(m_scriptNonce.get(), String(), c
onsoleMessage, contextURL, contextLine)); | |
1086 } else { | 1071 } else { |
1087 return (checkInline(operativeDirective(m_scriptSrc.get())) | 1072 return checkInline(operativeDirective(m_scriptSrc.get())); |
1088 && checkNonce(m_scriptNonce.get(), String())); | |
1089 } | 1073 } |
1090 } | 1074 } |
1091 | 1075 |
1092 bool CSPDirectiveList::allowInlineEventHandlers(const String& contextURL, const
WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportin
gStatus) const | 1076 bool CSPDirectiveList::allowInlineEventHandlers(const String& contextURL, const
WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportin
gStatus) const |
1093 { | 1077 { |
1094 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to execut
e inline event handler because it violates the following Content Security Policy
directive: "))); | 1078 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to execut
e inline event handler because it violates the following Content Security Policy
directive: "))); |
1095 if (reportingStatus == ContentSecurityPolicy::SendReport) { | 1079 if (reportingStatus == ContentSecurityPolicy::SendReport) { |
1096 return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get
()), consoleMessage, contextURL, contextLine, true) | 1080 return checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get(
)), consoleMessage, contextURL, contextLine, true); |
1097 && checkNonceAndReportViolation(m_scriptNonce.get(), String(), c
onsoleMessage, contextURL, contextLine)); | |
1098 } else { | 1081 } else { |
1099 return (checkInline(operativeDirective(m_scriptSrc.get())) | 1082 return checkInline(operativeDirective(m_scriptSrc.get())); |
1100 && checkNonce(m_scriptNonce.get(), String())); | |
1101 } | 1083 } |
1102 } | 1084 } |
1103 | 1085 |
1104 bool CSPDirectiveList::allowInlineScript(const String& contextURL, const WTF::Or
dinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus
) const | 1086 bool CSPDirectiveList::allowInlineScript(const String& contextURL, const WTF::Or
dinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus
) const |
1105 { | 1087 { |
1106 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to execut
e inline script because it violates the following Content Security Policy direct
ive: "))); | 1088 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to execut
e inline script because it violates the following Content Security Policy direct
ive: "))); |
1107 return reportingStatus == ContentSecurityPolicy::SendReport ? | 1089 return reportingStatus == ContentSecurityPolicy::SendReport ? |
1108 checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), con
soleMessage, contextURL, contextLine, true) : | 1090 checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), con
soleMessage, contextURL, contextLine, true) : |
1109 checkInline(operativeDirective(m_scriptSrc.get())); | 1091 checkInline(operativeDirective(m_scriptSrc.get())); |
1110 } | 1092 } |
1111 | 1093 |
1112 bool CSPDirectiveList::allowInlineStyle(const String& contextURL, const WTF::Ord
inalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus)
const | 1094 bool CSPDirectiveList::allowInlineStyle(const String& contextURL, const WTF::Ord
inalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus)
const |
1113 { | 1095 { |
1114 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to apply
inline style because it violates the following Content Security Policy directive
: "))); | 1096 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to apply
inline style because it violates the following Content Security Policy directive
: "))); |
1115 return reportingStatus == ContentSecurityPolicy::SendReport ? | 1097 return reportingStatus == ContentSecurityPolicy::SendReport ? |
1116 checkInlineAndReportViolation(operativeDirective(m_styleSrc.get()), cons
oleMessage, contextURL, contextLine, false) : | 1098 checkInlineAndReportViolation(operativeDirective(m_styleSrc.get()), cons
oleMessage, contextURL, contextLine, false) : |
1117 checkInline(operativeDirective(m_styleSrc.get())); | 1099 checkInline(operativeDirective(m_styleSrc.get())); |
1118 } | 1100 } |
1119 | 1101 |
1120 bool CSPDirectiveList::allowEval(ScriptState* state, ContentSecurityPolicy::Repo
rtingStatus reportingStatus) const | 1102 bool CSPDirectiveList::allowEval(ScriptState* state, ContentSecurityPolicy::Repo
rtingStatus reportingStatus) const |
1121 { | 1103 { |
1122 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to evalua
te script because it violates the following Content Security Policy directive: "
))); | 1104 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to evalua
te script because it violates the following Content Security Policy directive: "
))); |
1123 return reportingStatus == ContentSecurityPolicy::SendReport ? | 1105 return reportingStatus == ContentSecurityPolicy::SendReport ? |
1124 checkEvalAndReportViolation(operativeDirective(m_scriptSrc.get()), conso
leMessage, String(), WTF::OrdinalNumber::beforeFirst(), state) : | 1106 checkEvalAndReportViolation(operativeDirective(m_scriptSrc.get()), conso
leMessage, String(), WTF::OrdinalNumber::beforeFirst(), state) : |
1125 checkEval(operativeDirective(m_scriptSrc.get())); | 1107 checkEval(operativeDirective(m_scriptSrc.get())); |
1126 } | 1108 } |
1127 | 1109 |
1128 bool CSPDirectiveList::allowScriptNonce(const String& nonce, const String& conte
xtURL, const WTF::OrdinalNumber& contextLine, const KURL& url) const | |
1129 { | |
1130 DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Refused to execut
e script because it violates the following Content Security Policy directive: ")
)); | |
1131 if (url.isEmpty()) | |
1132 return checkNonceAndReportViolation(m_scriptNonce.get(), nonce, consoleM
essage, contextURL, contextLine); | |
1133 return checkNonceAndReportViolation(m_scriptNonce.get(), nonce, "Refused to
load '" + url.elidedString() + "' because it violates the following Content Secu
rity Policy directive: ", contextURL, contextLine); | |
1134 } | |
1135 | |
1136 bool CSPDirectiveList::allowPluginType(const String& type, const String& typeAtt
ribute, const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus)
const | 1110 bool CSPDirectiveList::allowPluginType(const String& type, const String& typeAtt
ribute, const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus)
const |
1137 { | 1111 { |
1138 return reportingStatus == ContentSecurityPolicy::SendReport ? | 1112 return reportingStatus == ContentSecurityPolicy::SendReport ? |
1139 checkMediaTypeAndReportViolation(m_pluginTypes.get(), type, typeAttribut
e, "Refused to load '" + url.elidedString() + "' (MIME type '" + typeAttribute +
"') because it violates the following Content Security Policy Directive: ") : | 1113 checkMediaTypeAndReportViolation(m_pluginTypes.get(), type, typeAttribut
e, "Refused to load '" + url.elidedString() + "' (MIME type '" + typeAttribute +
"') because it violates the following Content Security Policy Directive: ") : |
1140 checkMediaType(m_pluginTypes.get(), type, typeAttribute); | 1114 checkMediaType(m_pluginTypes.get(), type, typeAttribute); |
1141 } | 1115 } |
1142 | 1116 |
1143 bool CSPDirectiveList::allowScriptFromSource(const KURL& url, ContentSecurityPol
icy::ReportingStatus reportingStatus) const | 1117 bool CSPDirectiveList::allowScriptFromSource(const KURL& url, ContentSecurityPol
icy::ReportingStatus reportingStatus) const |
1144 { | 1118 { |
1145 return reportingStatus == ContentSecurityPolicy::SendReport ? | 1119 return reportingStatus == ContentSecurityPolicy::SendReport ? |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 checkSource(m_formAction.get(), url); | 1187 checkSource(m_formAction.get(), url); |
1214 } | 1188 } |
1215 | 1189 |
1216 bool CSPDirectiveList::allowBaseURI(const KURL& url, ContentSecurityPolicy::Repo
rtingStatus reportingStatus) const | 1190 bool CSPDirectiveList::allowBaseURI(const KURL& url, ContentSecurityPolicy::Repo
rtingStatus reportingStatus) const |
1217 { | 1191 { |
1218 return reportingStatus == ContentSecurityPolicy::SendReport ? | 1192 return reportingStatus == ContentSecurityPolicy::SendReport ? |
1219 checkSourceAndReportViolation(m_baseURI.get(), url, baseURI) : | 1193 checkSourceAndReportViolation(m_baseURI.get(), url, baseURI) : |
1220 checkSource(m_baseURI.get(), url); | 1194 checkSource(m_baseURI.get(), url); |
1221 } | 1195 } |
1222 | 1196 |
| 1197 bool CSPDirectiveList::allowNonce(const String& nonce) const |
| 1198 { |
| 1199 return checkNonce(operativeDirective(m_scriptSrc.get()), nonce); |
| 1200 } |
| 1201 |
1223 // policy = directive-list | 1202 // policy = directive-list |
1224 // directive-list = [ directive *( ";" [ directive ] ) ] | 1203 // directive-list = [ directive *( ";" [ directive ] ) ] |
1225 // | 1204 // |
1226 void CSPDirectiveList::parse(const String& policy) | 1205 void CSPDirectiveList::parse(const String& policy) |
1227 { | 1206 { |
1228 m_header = policy; | 1207 m_header = policy; |
1229 if (policy.isEmpty()) | 1208 if (policy.isEmpty()) |
1230 return; | 1209 return; |
1231 | 1210 |
1232 const UChar* position = policy.characters(); | 1211 const UChar* position = policy.characters(); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 applySandboxPolicy(name, value); | 1398 applySandboxPolicy(name, value); |
1420 else if (equalIgnoringCase(name, reportURI)) | 1399 else if (equalIgnoringCase(name, reportURI)) |
1421 parseReportURI(name, value); | 1400 parseReportURI(name, value); |
1422 else if (m_policy->experimentalFeaturesEnabled()) { | 1401 else if (m_policy->experimentalFeaturesEnabled()) { |
1423 if (equalIgnoringCase(name, baseURI)) | 1402 if (equalIgnoringCase(name, baseURI)) |
1424 setCSPDirective<SourceListDirective>(name, value, m_baseURI); | 1403 setCSPDirective<SourceListDirective>(name, value, m_baseURI); |
1425 else if (equalIgnoringCase(name, formAction)) | 1404 else if (equalIgnoringCase(name, formAction)) |
1426 setCSPDirective<SourceListDirective>(name, value, m_formAction); | 1405 setCSPDirective<SourceListDirective>(name, value, m_formAction); |
1427 else if (equalIgnoringCase(name, pluginTypes)) | 1406 else if (equalIgnoringCase(name, pluginTypes)) |
1428 setCSPDirective<MediaListDirective>(name, value, m_pluginTypes); | 1407 setCSPDirective<MediaListDirective>(name, value, m_pluginTypes); |
1429 else if (equalIgnoringCase(name, scriptNonce)) | |
1430 setCSPDirective<NonceDirective>(name, value, m_scriptNonce); | |
1431 else if (equalIgnoringCase(name, reflectedXSS)) | 1408 else if (equalIgnoringCase(name, reflectedXSS)) |
1432 parseReflectedXSS(name, value); | 1409 parseReflectedXSS(name, value); |
1433 else | 1410 else |
1434 m_policy->reportUnsupportedDirective(name); | 1411 m_policy->reportUnsupportedDirective(name); |
1435 } | 1412 } |
1436 else | 1413 else |
1437 m_policy->reportUnsupportedDirective(name); | 1414 m_policy->reportUnsupportedDirective(name); |
1438 } | 1415 } |
1439 | 1416 |
1440 ContentSecurityPolicy::ContentSecurityPolicy(ScriptExecutionContext* scriptExecu
tionContext) | 1417 ContentSecurityPolicy::ContentSecurityPolicy(ScriptExecutionContext* scriptExecu
tionContext) |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 template<bool (CSPDirectiveList::*allowed)(const String&, const WTF::OrdinalNumb
er&, ContentSecurityPolicy::ReportingStatus) const> | 1503 template<bool (CSPDirectiveList::*allowed)(const String&, const WTF::OrdinalNumb
er&, ContentSecurityPolicy::ReportingStatus) const> |
1527 bool isAllowedByAllWithContext(const CSPDirectiveListVector& policies, const Str
ing& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::R
eportingStatus reportingStatus) | 1504 bool isAllowedByAllWithContext(const CSPDirectiveListVector& policies, const Str
ing& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::R
eportingStatus reportingStatus) |
1528 { | 1505 { |
1529 for (size_t i = 0; i < policies.size(); ++i) { | 1506 for (size_t i = 0; i < policies.size(); ++i) { |
1530 if (!(policies[i].get()->*allowed)(contextURL, contextLine, reportingSta
tus)) | 1507 if (!(policies[i].get()->*allowed)(contextURL, contextLine, reportingSta
tus)) |
1531 return false; | 1508 return false; |
1532 } | 1509 } |
1533 return true; | 1510 return true; |
1534 } | 1511 } |
1535 | 1512 |
1536 template<bool (CSPDirectiveList::*allowed)(const String&, const String&, const W
TF::OrdinalNumber&, const KURL&) const> | 1513 template<bool (CSPDirectiveList::*allowed)(const String&) const> |
1537 bool isAllowedByAllWithNonce(const CSPDirectiveListVector& policies, const Strin
g& nonce, const String& contextURL, const WTF::OrdinalNumber& contextLine, const
KURL& url) | 1514 bool isAllowedByAllWithNonce(const CSPDirectiveListVector& policies, const Strin
g& nonce) |
1538 { | 1515 { |
1539 for (size_t i = 0; i < policies.size(); ++i) { | 1516 for (size_t i = 0; i < policies.size(); ++i) { |
1540 if (!(policies[i].get()->*allowed)(nonce, contextURL, contextLine, url)) | 1517 if (!(policies[i].get()->*allowed)(nonce)) |
1541 return false; | 1518 return false; |
1542 } | 1519 } |
1543 return true; | 1520 return true; |
1544 } | 1521 } |
1545 | |
1546 template<bool (CSPDirectiveList::*allowFromURL)(const KURL&, ContentSecurityPoli
cy::ReportingStatus) const> | 1522 template<bool (CSPDirectiveList::*allowFromURL)(const KURL&, ContentSecurityPoli
cy::ReportingStatus) const> |
1547 bool isAllowedByAllWithURL(const CSPDirectiveListVector& policies, const KURL& u
rl, ContentSecurityPolicy::ReportingStatus reportingStatus) | 1523 bool isAllowedByAllWithURL(const CSPDirectiveListVector& policies, const KURL& u
rl, ContentSecurityPolicy::ReportingStatus reportingStatus) |
1548 { | 1524 { |
1549 if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol())) | 1525 if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol())) |
1550 return true; | 1526 return true; |
1551 | 1527 |
1552 for (size_t i = 0; i < policies.size(); ++i) { | 1528 for (size_t i = 0; i < policies.size(); ++i) { |
1553 if (!(policies[i].get()->*allowFromURL)(url, reportingStatus)) | 1529 if (!(policies[i].get()->*allowFromURL)(url, reportingStatus)) |
1554 return false; | 1530 return false; |
1555 } | 1531 } |
1556 return true; | 1532 return true; |
1557 } | 1533 } |
1558 | 1534 |
1559 bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const
WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportin
gStatus) const | 1535 bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const
WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportin
gStatus) const |
1560 { | 1536 { |
1561 return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_p
olicies, contextURL, contextLine, reportingStatus); | 1537 return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_p
olicies, contextURL, contextLine, reportingStatus); |
1562 } | 1538 } |
1563 | 1539 |
1564 bool ContentSecurityPolicy::allowInlineEventHandlers(const String& contextURL, c
onst WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus rep
ortingStatus) const | 1540 bool ContentSecurityPolicy::allowInlineEventHandlers(const String& contextURL, c
onst WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus rep
ortingStatus) const |
1565 { | 1541 { |
1566 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineEventHandlers
>(m_policies, contextURL, contextLine, reportingStatus); | 1542 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineEventHandlers
>(m_policies, contextURL, contextLine, reportingStatus); |
1567 } | 1543 } |
1568 | 1544 |
1569 bool ContentSecurityPolicy::allowInlineScript(const String& contextURL, const WT
F::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingS
tatus) const | 1545 bool ContentSecurityPolicy::allowInlineScript(const String& nonce, const String&
contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::Repor
tingStatus reportingStatus) const |
1570 { | 1546 { |
1571 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineScript>(m_pol
icies, contextURL, contextLine, reportingStatus); | 1547 bool nonceAllowed = isAllowedByAllWithNonce<&CSPDirectiveList::allowNonce>(m
_policies, nonce); |
| 1548 return nonceAllowed || isAllowedByAllWithContext<&CSPDirectiveList::allowInl
ineScript>(m_policies, contextURL, contextLine, reportingStatus); |
1572 } | 1549 } |
1573 | 1550 |
1574 bool ContentSecurityPolicy::allowInlineStyle(const String& contextURL, const WTF
::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingSt
atus) const | 1551 bool ContentSecurityPolicy::allowInlineStyle(const String& contextURL, const WTF
::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingSt
atus) const |
1575 { | 1552 { |
1576 if (m_overrideInlineStyleAllowed) | 1553 if (m_overrideInlineStyleAllowed) |
1577 return true; | 1554 return true; |
1578 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineStyle>(m_poli
cies, contextURL, contextLine, reportingStatus); | 1555 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineStyle>(m_poli
cies, contextURL, contextLine, reportingStatus); |
1579 } | 1556 } |
1580 | 1557 |
1581 bool ContentSecurityPolicy::allowEval(ScriptState* state, ContentSecurityPolicy:
:ReportingStatus reportingStatus) const | 1558 bool ContentSecurityPolicy::allowEval(ScriptState* state, ContentSecurityPolicy:
:ReportingStatus reportingStatus) const |
1582 { | 1559 { |
1583 return isAllowedByAllWithState<&CSPDirectiveList::allowEval>(m_policies, sta
te, reportingStatus); | 1560 return isAllowedByAllWithState<&CSPDirectiveList::allowEval>(m_policies, sta
te, reportingStatus); |
1584 } | 1561 } |
1585 | 1562 |
1586 String ContentSecurityPolicy::evalDisabledErrorMessage() const | 1563 String ContentSecurityPolicy::evalDisabledErrorMessage() const |
1587 { | 1564 { |
1588 for (size_t i = 0; i < m_policies.size(); ++i) { | 1565 for (size_t i = 0; i < m_policies.size(); ++i) { |
1589 if (!m_policies[i]->allowEval(0, SuppressReport)) | 1566 if (!m_policies[i]->allowEval(0, SuppressReport)) |
1590 return m_policies[i]->evalDisabledErrorMessage(); | 1567 return m_policies[i]->evalDisabledErrorMessage(); |
1591 } | 1568 } |
1592 return String(); | 1569 return String(); |
1593 } | 1570 } |
1594 | 1571 |
1595 bool ContentSecurityPolicy::allowScriptNonce(const String& nonce, const String&
contextURL, const WTF::OrdinalNumber& contextLine, const KURL& url) const | |
1596 { | |
1597 return isAllowedByAllWithNonce<&CSPDirectiveList::allowScriptNonce>(m_polici
es, nonce, contextURL, contextLine, url); | |
1598 } | |
1599 | |
1600 bool ContentSecurityPolicy::allowPluginType(const String& type, const String& ty
peAttribute, const KURL& url, ContentSecurityPolicy::ReportingStatus reportingSt
atus) const | 1572 bool ContentSecurityPolicy::allowPluginType(const String& type, const String& ty
peAttribute, const KURL& url, ContentSecurityPolicy::ReportingStatus reportingSt
atus) const |
1601 { | 1573 { |
1602 for (size_t i = 0; i < m_policies.size(); ++i) { | 1574 for (size_t i = 0; i < m_policies.size(); ++i) { |
1603 if (!m_policies[i]->allowPluginType(type, typeAttribute, url, reportingS
tatus)) | 1575 if (!m_policies[i]->allowPluginType(type, typeAttribute, url, reportingS
tatus)) |
1604 return false; | 1576 return false; |
1605 } | 1577 } |
1606 return true; | 1578 return true; |
1607 } | 1579 } |
1608 | 1580 |
1609 bool ContentSecurityPolicy::allowScriptFromSource(const KURL& url, ContentSecuri
tyPolicy::ReportingStatus reportingStatus) const | 1581 bool ContentSecurityPolicy::allowScriptFromSource(const KURL& url, const String&
nonce, ContentSecurityPolicy::ReportingStatus reportingStatus) const |
1610 { | 1582 { |
1611 return isAllowedByAllWithURL<&CSPDirectiveList::allowScriptFromSource>(m_pol
icies, url, reportingStatus); | 1583 bool nonceAllowed = isAllowedByAllWithNonce<&CSPDirectiveList::allowNonce>(m
_policies, nonce); |
| 1584 return nonceAllowed || isAllowedByAllWithURL<&CSPDirectiveList::allowScriptF
romSource>(m_policies, url, reportingStatus); |
1612 } | 1585 } |
1613 | 1586 |
1614 bool ContentSecurityPolicy::allowObjectFromSource(const KURL& url, ContentSecuri
tyPolicy::ReportingStatus reportingStatus) const | 1587 bool ContentSecurityPolicy::allowObjectFromSource(const KURL& url, ContentSecuri
tyPolicy::ReportingStatus reportingStatus) const |
1615 { | 1588 { |
1616 return isAllowedByAllWithURL<&CSPDirectiveList::allowObjectFromSource>(m_pol
icies, url, reportingStatus); | 1589 return isAllowedByAllWithURL<&CSPDirectiveList::allowObjectFromSource>(m_pol
icies, url, reportingStatus); |
1617 } | 1590 } |
1618 | 1591 |
1619 bool ContentSecurityPolicy::allowChildFrameFromSource(const KURL& url, ContentSe
curityPolicy::ReportingStatus reportingStatus) const | 1592 bool ContentSecurityPolicy::allowChildFrameFromSource(const KURL& url, ContentSe
curityPolicy::ReportingStatus reportingStatus) const |
1620 { | 1593 { |
1621 return isAllowedByAllWithURL<&CSPDirectiveList::allowChildFrameFromSource>(m
_policies, url, reportingStatus); | 1594 return isAllowedByAllWithURL<&CSPDirectiveList::allowChildFrameFromSource>(m
_policies, url, reportingStatus); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1884 { | 1857 { |
1885 InspectorInstrumentation::scriptExecutionBlockedByCSP(m_scriptExecutionConte
xt, directiveText); | 1858 InspectorInstrumentation::scriptExecutionBlockedByCSP(m_scriptExecutionConte
xt, directiveText); |
1886 } | 1859 } |
1887 | 1860 |
1888 bool ContentSecurityPolicy::experimentalFeaturesEnabled() const | 1861 bool ContentSecurityPolicy::experimentalFeaturesEnabled() const |
1889 { | 1862 { |
1890 return RuntimeEnabledFeatures::experimentalContentSecurityPolicyFeaturesEnab
led(); | 1863 return RuntimeEnabledFeatures::experimentalContentSecurityPolicyFeaturesEnab
led(); |
1891 } | 1864 } |
1892 | 1865 |
1893 } | 1866 } |
OLD | NEW |