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 11 matching lines...) Expand all Loading... | |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "core/frame/csp/ContentSecurityPolicy.h" | 26 #include "core/frame/csp/ContentSecurityPolicy.h" |
27 | 27 |
28 #include "bindings/core/v8/ScriptController.h" | 28 #include "bindings/core/v8/ScriptController.h" |
29 #include "bindings/core/v8/SourceLocation.h" | 29 #include "bindings/core/v8/SourceLocation.h" |
30 #include "core/dom/DOMStringList.h" | 30 #include "core/dom/DOMStringList.h" |
31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
32 #include "core/dom/Element.h" | |
32 #include "core/dom/SandboxFlags.h" | 33 #include "core/dom/SandboxFlags.h" |
33 #include "core/events/SecurityPolicyViolationEvent.h" | 34 #include "core/events/SecurityPolicyViolationEvent.h" |
34 #include "core/fetch/IntegrityMetadata.h" | 35 #include "core/fetch/IntegrityMetadata.h" |
35 #include "core/frame/FrameClient.h" | 36 #include "core/frame/FrameClient.h" |
36 #include "core/frame/LocalDOMWindow.h" | 37 #include "core/frame/LocalDOMWindow.h" |
37 #include "core/frame/LocalFrame.h" | 38 #include "core/frame/LocalFrame.h" |
38 #include "core/frame/UseCounter.h" | 39 #include "core/frame/UseCounter.h" |
39 #include "core/frame/csp/CSPDirectiveList.h" | 40 #include "core/frame/csp/CSPDirectiveList.h" |
40 #include "core/frame/csp/CSPSource.h" | 41 #include "core/frame/csp/CSPSource.h" |
41 #include "core/frame/csp/CSPSourceList.h" | 42 #include "core/frame/csp/CSPSourceList.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
53 #include "platform/network/EncodedFormData.h" | 54 #include "platform/network/EncodedFormData.h" |
54 #include "platform/network/ResourceRequest.h" | 55 #include "platform/network/ResourceRequest.h" |
55 #include "platform/network/ResourceResponse.h" | 56 #include "platform/network/ResourceResponse.h" |
56 #include "platform/weborigin/KURL.h" | 57 #include "platform/weborigin/KURL.h" |
57 #include "platform/weborigin/KnownPorts.h" | 58 #include "platform/weborigin/KnownPorts.h" |
58 #include "platform/weborigin/SchemeRegistry.h" | 59 #include "platform/weborigin/SchemeRegistry.h" |
59 #include "platform/weborigin/SecurityOrigin.h" | 60 #include "platform/weborigin/SecurityOrigin.h" |
60 #include "public/platform/Platform.h" | 61 #include "public/platform/Platform.h" |
61 #include "public/platform/WebAddressSpace.h" | 62 #include "public/platform/WebAddressSpace.h" |
62 #include "public/platform/WebURLRequest.h" | 63 #include "public/platform/WebURLRequest.h" |
64 #include "wtf/NotFound.h" | |
63 #include "wtf/PtrUtil.h" | 65 #include "wtf/PtrUtil.h" |
64 #include "wtf/StringHasher.h" | 66 #include "wtf/StringHasher.h" |
65 #include "wtf/text/ParsingUtilities.h" | 67 #include "wtf/text/ParsingUtilities.h" |
66 #include "wtf/text/StringBuilder.h" | 68 #include "wtf/text/StringBuilder.h" |
67 #include "wtf/text/StringUTF8Adaptor.h" | 69 #include "wtf/text/StringUTF8Adaptor.h" |
68 #include <memory> | 70 #include <memory> |
69 | 71 |
70 namespace blink { | 72 namespace blink { |
71 | 73 |
72 // CSP Level 1 Directives | 74 // CSP Level 1 Directives |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 || equalIgnoringCase(name, PluginTypes) | 130 || equalIgnoringCase(name, PluginTypes) |
129 || equalIgnoringCase(name, ReflectedXSS) | 131 || equalIgnoringCase(name, ReflectedXSS) |
130 || equalIgnoringCase(name, Referrer) | 132 || equalIgnoringCase(name, Referrer) |
131 || equalIgnoringCase(name, ManifestSrc) | 133 || equalIgnoringCase(name, ManifestSrc) |
132 || equalIgnoringCase(name, BlockAllMixedContent) | 134 || equalIgnoringCase(name, BlockAllMixedContent) |
133 || equalIgnoringCase(name, UpgradeInsecureRequests) | 135 || equalIgnoringCase(name, UpgradeInsecureRequests) |
134 || equalIgnoringCase(name, TreatAsPublicAddress) | 136 || equalIgnoringCase(name, TreatAsPublicAddress) |
135 || equalIgnoringCase(name, RequireSRIFor)); | 137 || equalIgnoringCase(name, RequireSRIFor)); |
136 } | 138 } |
137 | 139 |
140 bool ContentSecurityPolicy::isNonceableElement(const Element* element) | |
141 { | |
142 if (!element->fastHasAttribute(HTMLNames::nonceAttr)) | |
143 return false; | |
144 | |
145 bool nonceable = true; | |
146 | |
147 DEFINE_STATIC_LOCAL(AtomicString, scriptString, ("<script")); | |
jww
2016/08/19 19:23:00
What about whitespace (e.g. "< script"), albeit pe
| |
148 for (const Attribute& attr : element->attributes()) { | |
149 if (attr.name().localName().findIgnoringASCIICase(scriptString) != WTF:: kNotFound | |
150 || attr.value().findIgnoringASCIICase(scriptString) != WTF::kNotFoun d) { | |
151 nonceable = false; | |
152 break; | |
153 } | |
154 } | |
155 | |
156 UseCounter::count(element->document(), nonceable ? UseCounter::CleanScriptEl ementWithNonce : UseCounter::PotentiallyInjectedScriptElementWithNonce); | |
157 return nonceable; | |
158 } | |
159 | |
138 static UseCounter::Feature getUseCounterType(ContentSecurityPolicyHeaderType typ e) | 160 static UseCounter::Feature getUseCounterType(ContentSecurityPolicyHeaderType typ e) |
139 { | 161 { |
140 switch (type) { | 162 switch (type) { |
141 case ContentSecurityPolicyHeaderTypeEnforce: | 163 case ContentSecurityPolicyHeaderTypeEnforce: |
142 return UseCounter::ContentSecurityPolicy; | 164 return UseCounter::ContentSecurityPolicy; |
143 case ContentSecurityPolicyHeaderTypeReport: | 165 case ContentSecurityPolicyHeaderTypeReport: |
144 return UseCounter::ContentSecurityPolicyReportOnly; | 166 return UseCounter::ContentSecurityPolicyReportOnly; |
145 } | 167 } |
146 ASSERT_NOT_REACHED(); | 168 ASSERT_NOT_REACHED(); |
147 return UseCounter::NumberOfFeatures; | 169 return UseCounter::NumberOfFeatures; |
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1130 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report. | 1152 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report. |
1131 return !m_violationReportsSent.contains(report.impl()->hash()); | 1153 return !m_violationReportsSent.contains(report.impl()->hash()); |
1132 } | 1154 } |
1133 | 1155 |
1134 void ContentSecurityPolicy::didSendViolationReport(const String& report) | 1156 void ContentSecurityPolicy::didSendViolationReport(const String& report) |
1135 { | 1157 { |
1136 m_violationReportsSent.add(report.impl()->hash()); | 1158 m_violationReportsSent.add(report.impl()->hash()); |
1137 } | 1159 } |
1138 | 1160 |
1139 } // namespace blink | 1161 } // namespace blink |
OLD | NEW |