[JSC] WTF::TemporaryChange with WTF::SetForScope
[WebKit-https.git] / Source / WebCore / page / csp / ContentSecurityPolicy.cpp
1 /*
2  * Copyright (C) 2011 Google, Inc. All rights reserved.
3  * Copyright (C) 2013, 2016 Apple Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include "config.h"
28 #include "ContentSecurityPolicy.h"
29
30 #include "ContentSecurityPolicyDirective.h"
31 #include "ContentSecurityPolicyDirectiveList.h"
32 #include "ContentSecurityPolicyDirectiveNames.h"
33 #include "ContentSecurityPolicyHash.h"
34 #include "ContentSecurityPolicySource.h"
35 #include "ContentSecurityPolicySourceList.h"
36 #include "CryptoDigest.h"
37 #include "DOMStringList.h"
38 #include "Document.h"
39 #include "DocumentLoader.h"
40 #include "EventNames.h"
41 #include "FormData.h"
42 #include "FormDataList.h"
43 #include "Frame.h"
44 #include "HTMLParserIdioms.h"
45 #include "InspectorInstrumentation.h"
46 #include "JSDOMWindowShell.h"
47 #include "JSMainThreadExecState.h"
48 #include "ParsingUtilities.h"
49 #include "PingLoader.h"
50 #include "ResourceRequest.h"
51 #include "RuntimeEnabledFeatures.h"
52 #include "SchemeRegistry.h"
53 #include "SecurityOrigin.h"
54 #include "SecurityPolicyViolationEvent.h"
55 #include "Settings.h"
56 #include "TextEncoding.h"
57 #include <inspector/InspectorValues.h>
58 #include <inspector/ScriptCallStack.h>
59 #include <inspector/ScriptCallStackFactory.h>
60 #include <wtf/SetForScope.h>
61 #include <wtf/text/StringBuilder.h>
62 #include <wtf/text/TextPosition.h>
63
64 using namespace Inspector;
65
66 namespace WebCore {
67
68 static String consoleMessageForViolation(const char* effectiveViolatedDirective, const ContentSecurityPolicyDirective& violatedDirective, const URL& blockedURL, const char* prefix, const char* subject = "it")
69 {
70     StringBuilder result;
71     if (violatedDirective.directiveList().isReportOnly())
72         result.appendLiteral("[Report Only] ");
73     result.append(prefix);
74     if (!blockedURL.isEmpty()) {
75         result.append(' ');
76         result.append(blockedURL.stringCenterEllipsizedToLength());
77     }
78     result.appendLiteral(" because ");
79     result.append(subject);
80     if (violatedDirective.isDefaultSrc()) {
81         result.appendLiteral(" appears in neither the ");
82         result.append(effectiveViolatedDirective);
83         result.appendLiteral(" directive nor the default-src directive of the Content Security Policy.");
84     } else {
85         result.appendLiteral(" does not appear in the ");
86         result.append(effectiveViolatedDirective);
87         result.appendLiteral(" directive of the Content Security Policy.");
88     }
89     return result.toString();
90 }
91
92 ContentSecurityPolicy::ContentSecurityPolicy(ScriptExecutionContext& scriptExecutionContext)
93     : m_scriptExecutionContext(&scriptExecutionContext)
94     , m_sandboxFlags(SandboxNone)
95 {
96     ASSERT(scriptExecutionContext.securityOrigin());
97     updateSourceSelf(*scriptExecutionContext.securityOrigin());
98 }
99
100 ContentSecurityPolicy::ContentSecurityPolicy(const SecurityOrigin& securityOrigin, const Frame* frame)
101     : m_frame(frame)
102     , m_sandboxFlags(SandboxNone)
103 {
104     updateSourceSelf(securityOrigin);
105 }
106
107 ContentSecurityPolicy::~ContentSecurityPolicy()
108 {
109 }
110
111 void ContentSecurityPolicy::copyStateFrom(const ContentSecurityPolicy* other) 
112 {
113     ASSERT(m_policies.isEmpty());
114     for (auto& policy : other->m_policies)
115         didReceiveHeader(policy->header(), policy->headerType(), ContentSecurityPolicy::PolicyFrom::Inherited);
116
117     copyUpgradeInsecureRequestStateFrom(*other);
118 }
119
120 void ContentSecurityPolicy::copyUpgradeInsecureRequestStateFrom(const ContentSecurityPolicy& other)
121 {
122     m_upgradeInsecureRequests = other.m_upgradeInsecureRequests;
123     m_insecureNavigationRequestsToUpgrade.add(other.m_insecureNavigationRequestsToUpgrade.begin(), other.m_insecureNavigationRequestsToUpgrade.end());
124 }
125
126 void ContentSecurityPolicy::didCreateWindowShell(JSDOMWindowShell& windowShell) const
127 {
128     JSDOMWindow* window = windowShell.window();
129     ASSERT(window);
130     ASSERT(window->scriptExecutionContext());
131     ASSERT(window->scriptExecutionContext()->contentSecurityPolicy() == this);
132     if (!windowShell.world().isNormal()) {
133         window->setEvalEnabled(true);
134         return;
135     }
136     window->setEvalEnabled(m_lastPolicyEvalDisabledErrorMessage.isNull(), m_lastPolicyEvalDisabledErrorMessage);
137 }
138
139 ContentSecurityPolicyResponseHeaders ContentSecurityPolicy::responseHeaders() const
140 {
141     ContentSecurityPolicyResponseHeaders result;
142     result.m_headers.reserveInitialCapacity(m_policies.size());
143     for (auto& policy : m_policies)
144         result.m_headers.uncheckedAppend({ policy->header(), policy->headerType() });
145     return result;
146 }
147
148 void ContentSecurityPolicy::didReceiveHeaders(const ContentSecurityPolicyResponseHeaders& headers, ReportParsingErrors reportParsingErrors)
149 {
150     SetForScope<bool> isReportingEnabled(m_isReportingEnabled, reportParsingErrors == ReportParsingErrors::Yes);
151     for (auto& header : headers.m_headers)
152         didReceiveHeader(header.first, header.second, ContentSecurityPolicy::PolicyFrom::HTTPHeader);
153 }
154
155 void ContentSecurityPolicy::didReceiveHeader(const String& header, ContentSecurityPolicyHeaderType type, ContentSecurityPolicy::PolicyFrom policyFrom)
156 {
157     // RFC2616, section 4.2 specifies that headers appearing multiple times can
158     // be combined with a comma. Walk the header string, and parse each comma
159     // separated chunk as a separate header.
160     auto characters = StringView(header).upconvertedCharacters();
161     const UChar* begin = characters;
162     const UChar* position = begin;
163     const UChar* end = begin + header.length();
164     while (position < end) {
165         skipUntil<UChar>(position, end, ',');
166
167         // header1,header2 OR header1
168         //        ^                  ^
169         std::unique_ptr<ContentSecurityPolicyDirectiveList> policy = ContentSecurityPolicyDirectiveList::create(*this, String(begin, position - begin), type, policyFrom);
170         const ContentSecurityPolicyDirective* violatedDirective = policy->violatedDirectiveForUnsafeEval();
171         if (violatedDirective && !violatedDirective->directiveList().isReportOnly())
172             m_lastPolicyEvalDisabledErrorMessage = policy->evalDisabledErrorMessage();
173
174         m_policies.append(policy.release());
175
176         // Skip the comma, and begin the next header from the current position.
177         ASSERT(position == end || *position == ',');
178         skipExactly<UChar>(position, end, ',');
179         begin = position;
180     }
181
182     if (m_scriptExecutionContext)
183         applyPolicyToScriptExecutionContext();
184 }
185
186 void ContentSecurityPolicy::updateSourceSelf(const SecurityOrigin& securityOrigin)
187 {
188     m_selfSourceProtocol = securityOrigin.protocol();
189     m_selfSource = std::make_unique<ContentSecurityPolicySource>(*this, m_selfSourceProtocol, securityOrigin.host(), securityOrigin.port(), emptyString(), false, false);
190 }
191
192 void ContentSecurityPolicy::applyPolicyToScriptExecutionContext()
193 {
194     ASSERT(m_scriptExecutionContext);
195
196     // Update source self as the security origin may have changed between the time we were created and now.
197     // For instance, we may have been initially created for an about:blank iframe that later inherited the
198     // security origin of its owner document.
199     ASSERT(m_scriptExecutionContext->securityOrigin());
200     updateSourceSelf(*m_scriptExecutionContext->securityOrigin());
201
202     if (!m_lastPolicyEvalDisabledErrorMessage.isNull())
203         m_scriptExecutionContext->disableEval(m_lastPolicyEvalDisabledErrorMessage);
204     if (m_sandboxFlags != SandboxNone && is<Document>(m_scriptExecutionContext))
205         m_scriptExecutionContext->enforceSandboxFlags(m_sandboxFlags);
206 }
207
208 void ContentSecurityPolicy::setOverrideAllowInlineStyle(bool value)
209 {
210     m_overrideInlineStyleAllowed = value;
211 }
212
213 bool ContentSecurityPolicy::urlMatchesSelf(const URL& url) const
214 {
215     return m_selfSource->matches(url);
216 }
217
218 bool ContentSecurityPolicy::allowContentSecurityPolicySourceStarToMatchAnyProtocol() const
219 {
220     if (Settings* settings = is<Document>(m_scriptExecutionContext) ? downcast<Document>(*m_scriptExecutionContext).settings() : nullptr)
221         return settings->allowContentSecurityPolicySourceStarToMatchAnyProtocol();
222     return false;
223 }
224
225 bool ContentSecurityPolicy::protocolMatchesSelf(const URL& url) const
226 {
227     if (equalLettersIgnoringASCIICase(m_selfSourceProtocol, "http"))
228         return url.protocolIsInHTTPFamily();
229     return equalIgnoringASCIICase(url.protocol(), m_selfSourceProtocol);
230 }
231
232 template<typename Predicate, typename... Args>
233 typename std::enable_if<!std::is_convertible<Predicate, ContentSecurityPolicy::ViolatedDirectiveCallback>::value, bool>::type ContentSecurityPolicy::allPoliciesWithDispositionAllow(Disposition disposition, Predicate&& predicate, Args&&... args) const
234 {
235     bool isReportOnly = disposition == ContentSecurityPolicy::Disposition::ReportOnly;
236     for (auto& policy : m_policies) {
237         if (policy->isReportOnly() != isReportOnly)
238             continue;
239         if ((policy.get()->*predicate)(std::forward<Args>(args)...))
240             return false;
241     }
242     return true;
243 }
244
245 template<typename Predicate, typename... Args>
246 bool ContentSecurityPolicy::allPoliciesWithDispositionAllow(Disposition disposition, ViolatedDirectiveCallback&& callback, Predicate&& predicate, Args&&... args) const
247 {
248     bool isReportOnly = disposition == ContentSecurityPolicy::Disposition::ReportOnly;
249     bool isAllowed = true;
250     for (auto& policy : m_policies) {
251         if (policy->isReportOnly() != isReportOnly)
252             continue;
253         if (const ContentSecurityPolicyDirective* violatedDirective = (policy.get()->*predicate)(std::forward<Args>(args)...)) {
254             isAllowed = false;
255             callback(*violatedDirective);
256         }
257     }
258     return isAllowed;
259 }
260
261 template<typename Predicate, typename... Args>
262 bool ContentSecurityPolicy::allPoliciesAllow(ViolatedDirectiveCallback&& callback, Predicate&& predicate, Args&&... args) const
263 {
264     bool isAllowed = true;
265     for (auto& policy : m_policies) {
266         if (const ContentSecurityPolicyDirective* violatedDirective = (policy.get()->*predicate)(std::forward<Args>(args)...)) {
267             if (!violatedDirective->directiveList().isReportOnly())
268                 isAllowed = false;
269             callback(*violatedDirective);
270         }
271     }
272     return isAllowed;
273 }
274
275 static CryptoDigest::Algorithm toCryptoDigestAlgorithm(ContentSecurityPolicyHashAlgorithm algorithm)
276 {
277     switch (algorithm) {
278     case ContentSecurityPolicyHashAlgorithm::SHA_256:
279         return CryptoDigest::Algorithm::SHA_256;
280     case ContentSecurityPolicyHashAlgorithm::SHA_384:
281         return CryptoDigest::Algorithm::SHA_384;
282     case ContentSecurityPolicyHashAlgorithm::SHA_512:
283         return CryptoDigest::Algorithm::SHA_512;
284     }
285     ASSERT_NOT_REACHED();
286     return CryptoDigest::Algorithm::SHA_512;
287 }
288
289 template<typename Predicate>
290 ContentSecurityPolicy::HashInEnforcedAndReportOnlyPoliciesPair ContentSecurityPolicy::findHashOfContentInPolicies(Predicate&& predicate, const String& content, OptionSet<ContentSecurityPolicyHashAlgorithm> algorithms) const
291 {
292     if (algorithms.isEmpty() || content.isEmpty())
293         return { false, false };
294
295     // FIXME: We should compute the document encoding once and cache it instead of computing it on each invocation.
296     TextEncoding documentEncoding;
297     if (is<Document>(m_scriptExecutionContext))
298         documentEncoding = downcast<Document>(*m_scriptExecutionContext).textEncoding();
299     const TextEncoding& encodingToUse = documentEncoding.isValid() ? documentEncoding : UTF8Encoding();
300
301     // FIXME: Compute the digest with respect to the raw bytes received from the page.
302     // See <https://bugs.webkit.org/show_bug.cgi?id=155184>.
303     CString contentCString = encodingToUse.encode(content, EntitiesForUnencodables);
304     bool foundHashInEnforcedPolicies = false;
305     bool foundHashInReportOnlyPolicies = false;
306     for (auto algorithm : algorithms) {
307         auto cryptoDigest = CryptoDigest::create(toCryptoDigestAlgorithm(algorithm));
308         cryptoDigest->addBytes(contentCString.data(), contentCString.length());
309         ContentSecurityPolicyHash hash = { algorithm, cryptoDigest->computeHash() };
310         if (!foundHashInEnforcedPolicies && allPoliciesWithDispositionAllow(ContentSecurityPolicy::Disposition::Enforce, std::forward<Predicate>(predicate), hash))
311             foundHashInEnforcedPolicies = true;
312         if (!foundHashInReportOnlyPolicies && allPoliciesWithDispositionAllow(ContentSecurityPolicy::Disposition::ReportOnly, std::forward<Predicate>(predicate), hash))
313             foundHashInReportOnlyPolicies = true;
314         if (foundHashInEnforcedPolicies && foundHashInReportOnlyPolicies)
315             break;
316     }
317     return { foundHashInEnforcedPolicies, foundHashInReportOnlyPolicies };
318 }
319
320 bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, bool overrideContentSecurityPolicy) const
321 {
322     if (overrideContentSecurityPolicy)
323         return true;
324     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
325         String consoleMessage = consoleMessageForViolation(ContentSecurityPolicyDirectiveNames::scriptSrc, violatedDirective, URL(), "Refused to execute a script", "its hash, its nonce, or 'unsafe-inline'");
326         reportViolation(ContentSecurityPolicyDirectiveNames::scriptSrc, violatedDirective, URL(), consoleMessage, contextURL, TextPosition(contextLine, WTF::OrdinalNumber()));
327         if (!violatedDirective.directiveList().isReportOnly())
328             reportBlockedScriptExecutionToInspector(violatedDirective.text());
329     };
330     return allPoliciesAllow(WTFMove(handleViolatedDirective), &ContentSecurityPolicyDirectiveList::violatedDirectiveForUnsafeInlineScript);
331 }
332
333 bool ContentSecurityPolicy::allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, bool overrideContentSecurityPolicy) const
334 {
335     if (overrideContentSecurityPolicy)
336         return true;
337     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
338         String consoleMessage = consoleMessageForViolation(ContentSecurityPolicyDirectiveNames::scriptSrc, violatedDirective, URL(), "Refused to execute a script for an inline event handler", "'unsafe-inline'");
339         reportViolation(ContentSecurityPolicyDirectiveNames::scriptSrc, violatedDirective, URL(), consoleMessage, contextURL, TextPosition(contextLine, WTF::OrdinalNumber()));
340         if (!violatedDirective.directiveList().isReportOnly())
341             reportBlockedScriptExecutionToInspector(violatedDirective.text());
342     };
343     return allPoliciesAllow(WTFMove(handleViolatedDirective), &ContentSecurityPolicyDirectiveList::violatedDirectiveForUnsafeInlineScript);
344 }
345
346 bool ContentSecurityPolicy::allowScriptWithNonce(const String& nonce, bool overrideContentSecurityPolicy) const
347 {
348     if (overrideContentSecurityPolicy)
349         return true;
350     String strippedNonce = stripLeadingAndTrailingHTMLSpaces(nonce);
351     if (strippedNonce.isEmpty())
352         return false;
353     // FIXME: We need to report violations in report-only policies. See <https://bugs.webkit.org/show_bug.cgi?id=159830>.
354     return allPoliciesWithDispositionAllow(ContentSecurityPolicy::Disposition::Enforce, &ContentSecurityPolicyDirectiveList::violatedDirectiveForScriptNonce, strippedNonce);
355 }
356
357 bool ContentSecurityPolicy::allowStyleWithNonce(const String& nonce, bool overrideContentSecurityPolicy) const
358 {
359     if (overrideContentSecurityPolicy)
360         return true;
361     String strippedNonce = stripLeadingAndTrailingHTMLSpaces(nonce);
362     if (strippedNonce.isEmpty())
363         return false;
364     // FIXME: We need to report violations in report-only policies. See <https://bugs.webkit.org/show_bug.cgi?id=159830>.
365     return allPoliciesWithDispositionAllow(ContentSecurityPolicy::Disposition::Enforce, &ContentSecurityPolicyDirectiveList::violatedDirectiveForStyleNonce, strippedNonce);
366 }
367
368 bool ContentSecurityPolicy::allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine, const String& scriptContent, bool overrideContentSecurityPolicy) const
369 {
370     if (overrideContentSecurityPolicy)
371         return true;
372     bool foundHashInEnforcedPolicies;
373     bool foundHashInReportOnlyPolicies;
374     std::tie(foundHashInEnforcedPolicies, foundHashInReportOnlyPolicies) = findHashOfContentInPolicies(&ContentSecurityPolicyDirectiveList::violatedDirectiveForScriptHash, scriptContent, m_hashAlgorithmsForInlineScripts);
375     if (foundHashInEnforcedPolicies && foundHashInReportOnlyPolicies)
376         return true;
377     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
378         String consoleMessage = consoleMessageForViolation(ContentSecurityPolicyDirectiveNames::scriptSrc, violatedDirective, URL(), "Refused to execute a script", "its hash, its nonce, or 'unsafe-inline'");
379         reportViolation(ContentSecurityPolicyDirectiveNames::scriptSrc, violatedDirective, URL(), consoleMessage, contextURL, TextPosition(contextLine, WTF::OrdinalNumber()));
380         if (!violatedDirective.directiveList().isReportOnly())
381             reportBlockedScriptExecutionToInspector(violatedDirective.text());
382     };
383     // FIXME: We should not report that the inline script violated a policy when its hash matched a source
384     // expression in the policy and the page has more than one policy. See <https://bugs.webkit.org/show_bug.cgi?id=159832>.
385     if (!foundHashInReportOnlyPolicies)
386         allPoliciesWithDispositionAllow(ContentSecurityPolicy::Disposition::ReportOnly, handleViolatedDirective, &ContentSecurityPolicyDirectiveList::violatedDirectiveForUnsafeInlineScript);
387     return foundHashInEnforcedPolicies || allPoliciesWithDispositionAllow(ContentSecurityPolicy::Disposition::Enforce, handleViolatedDirective, &ContentSecurityPolicyDirectiveList::violatedDirectiveForUnsafeInlineScript);
388 }
389
390 bool ContentSecurityPolicy::allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, const String& styleContent, bool overrideContentSecurityPolicy) const
391 {
392     if (overrideContentSecurityPolicy)
393         return true;
394     if (m_overrideInlineStyleAllowed)
395         return true;
396     bool foundHashInEnforcedPolicies;
397     bool foundHashInReportOnlyPolicies;
398     std::tie(foundHashInEnforcedPolicies, foundHashInReportOnlyPolicies) = findHashOfContentInPolicies(&ContentSecurityPolicyDirectiveList::violatedDirectiveForStyleHash, styleContent, m_hashAlgorithmsForInlineStylesheets);
399     if (foundHashInEnforcedPolicies && foundHashInReportOnlyPolicies)
400         return true;
401     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
402         String consoleMessage = consoleMessageForViolation(ContentSecurityPolicyDirectiveNames::styleSrc, violatedDirective, URL(), "Refused to apply a stylesheet", "its hash, its nonce, or 'unsafe-inline'");
403         reportViolation(ContentSecurityPolicyDirectiveNames::styleSrc, violatedDirective, URL(), consoleMessage, contextURL, TextPosition(contextLine, WTF::OrdinalNumber()));
404     };
405     // FIXME: We should not report that the inline stylesheet violated a policy when its hash matched a source
406     // expression in the policy and the page has more than one policy. See <https://bugs.webkit.org/show_bug.cgi?id=159832>.
407     if (!foundHashInReportOnlyPolicies)
408         allPoliciesWithDispositionAllow(ContentSecurityPolicy::Disposition::ReportOnly, handleViolatedDirective, &ContentSecurityPolicyDirectiveList::violatedDirectiveForUnsafeInlineStyle);
409     return foundHashInEnforcedPolicies || allPoliciesWithDispositionAllow(ContentSecurityPolicy::Disposition::Enforce, handleViolatedDirective, &ContentSecurityPolicyDirectiveList::violatedDirectiveForUnsafeInlineStyle);
410 }
411
412 bool ContentSecurityPolicy::allowEval(JSC::ExecState* state, bool overrideContentSecurityPolicy) const
413 {
414     if (overrideContentSecurityPolicy)
415         return true;
416     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
417         String consoleMessage = consoleMessageForViolation(ContentSecurityPolicyDirectiveNames::scriptSrc, violatedDirective, URL(), "Refused to execute a script", "'unsafe-eval'");
418         reportViolation(ContentSecurityPolicyDirectiveNames::scriptSrc, violatedDirective, URL(), consoleMessage, state);
419         if (!violatedDirective.directiveList().isReportOnly())
420             reportBlockedScriptExecutionToInspector(violatedDirective.text());
421     };
422     return allPoliciesAllow(WTFMove(handleViolatedDirective), &ContentSecurityPolicyDirectiveList::violatedDirectiveForUnsafeEval);
423 }
424
425 bool ContentSecurityPolicy::allowFrameAncestors(const Frame& frame, const URL& url, bool overrideContentSecurityPolicy) const
426 {
427     if (overrideContentSecurityPolicy)
428         return true;
429     Frame& topFrame = frame.tree().top();
430     if (&frame == &topFrame)
431         return true;
432     String sourceURL;
433     TextPosition sourcePosition(WTF::OrdinalNumber::beforeFirst(), WTF::OrdinalNumber());
434     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
435         String consoleMessage = consoleMessageForViolation(ContentSecurityPolicyDirectiveNames::frameAncestors, violatedDirective, url, "Refused to load");
436         reportViolation(ContentSecurityPolicyDirectiveNames::frameAncestors, violatedDirective, url, consoleMessage, sourceURL, sourcePosition);
437     };
438     return allPoliciesAllow(WTFMove(handleViolatedDirective), &ContentSecurityPolicyDirectiveList::violatedDirectiveForFrameAncestor, frame);
439 }
440
441 bool ContentSecurityPolicy::allowPluginType(const String& type, const String& typeAttribute, const URL& url, bool overrideContentSecurityPolicy) const
442 {
443     if (overrideContentSecurityPolicy)
444         return true;
445     String sourceURL;
446     TextPosition sourcePosition(WTF::OrdinalNumber::beforeFirst(), WTF::OrdinalNumber());
447     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
448         String consoleMessage = consoleMessageForViolation(ContentSecurityPolicyDirectiveNames::pluginTypes, violatedDirective, url, "Refused to load", "its MIME type");
449         reportViolation(ContentSecurityPolicyDirectiveNames::pluginTypes, violatedDirective, url, consoleMessage, sourceURL, sourcePosition);
450     };
451     return allPoliciesAllow(WTFMove(handleViolatedDirective), &ContentSecurityPolicyDirectiveList::violatedDirectiveForPluginType, type, typeAttribute);
452 }
453
454 bool ContentSecurityPolicy::allowObjectFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived) const
455 {
456     if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol().toStringWithoutCopying()))
457         return true;
458     // As per section object-src of the Content Security Policy Level 3 spec., <http://w3c.github.io/webappsec-csp> (Editor's Draft, 29 February 2016),
459     // "If plugin content is loaded without an associated URL (perhaps an object element lacks a data attribute, but loads some default plugin based
460     // on the specified type), it MUST be blocked if object-src's value is 'none', but will otherwise be allowed".
461     String sourceURL;
462     TextPosition sourcePosition(WTF::OrdinalNumber::beforeFirst(), WTF::OrdinalNumber());
463     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
464         String consoleMessage = consoleMessageForViolation(ContentSecurityPolicyDirectiveNames::objectSrc, violatedDirective, url, "Refused to load");
465         reportViolation(ContentSecurityPolicyDirectiveNames::objectSrc, violatedDirective, url, consoleMessage, sourceURL, sourcePosition);
466     };
467     return allPoliciesAllow(WTFMove(handleViolatedDirective), &ContentSecurityPolicyDirectiveList::violatedDirectiveForObjectSource, url, redirectResponseReceived == RedirectResponseReceived::Yes, ContentSecurityPolicySourceListDirective::ShouldAllowEmptyURLIfSourceListIsNotNone::Yes);
468 }
469
470 bool ContentSecurityPolicy::allowChildFrameFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived) const
471 {
472     if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol().toStringWithoutCopying()))
473         return true;
474     String sourceURL;
475     TextPosition sourcePosition(WTF::OrdinalNumber::beforeFirst(), WTF::OrdinalNumber());
476     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
477         const char* effectiveViolatedDirective = violatedDirective.name() == ContentSecurityPolicyDirectiveNames::frameSrc ? ContentSecurityPolicyDirectiveNames::frameSrc : ContentSecurityPolicyDirectiveNames::childSrc;
478         String consoleMessage = consoleMessageForViolation(effectiveViolatedDirective, violatedDirective, url, "Refused to load");
479         reportViolation(effectiveViolatedDirective, violatedDirective, url, consoleMessage, sourceURL, sourcePosition);
480     };
481     return allPoliciesAllow(WTFMove(handleViolatedDirective), &ContentSecurityPolicyDirectiveList::violatedDirectiveForFrame, url, redirectResponseReceived == RedirectResponseReceived::Yes);
482 }
483
484 bool ContentSecurityPolicy::allowResourceFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived, const char* name, ResourcePredicate resourcePredicate) const
485 {
486     if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol().toStringWithoutCopying()))
487         return true;
488     String sourceURL;
489     TextPosition sourcePosition(WTF::OrdinalNumber::beforeFirst(), WTF::OrdinalNumber());
490     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
491         String consoleMessage = consoleMessageForViolation(name, violatedDirective, url, "Refused to load");
492         reportViolation(name, violatedDirective, url, consoleMessage, sourceURL, sourcePosition);
493     };
494     return allPoliciesAllow(WTFMove(handleViolatedDirective), resourcePredicate, url, redirectResponseReceived == RedirectResponseReceived::Yes);
495 }
496
497 bool ContentSecurityPolicy::allowChildContextFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived) const
498 {
499     return allowResourceFromSource(url, redirectResponseReceived, ContentSecurityPolicyDirectiveNames::childSrc, &ContentSecurityPolicyDirectiveList::violatedDirectiveForChildContext);
500 }
501
502 bool ContentSecurityPolicy::allowScriptFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived) const
503 {
504     return allowResourceFromSource(url, redirectResponseReceived, ContentSecurityPolicyDirectiveNames::scriptSrc, &ContentSecurityPolicyDirectiveList::violatedDirectiveForScript);
505 }
506
507 bool ContentSecurityPolicy::allowImageFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived) const
508 {
509     return allowResourceFromSource(url, redirectResponseReceived, ContentSecurityPolicyDirectiveNames::imgSrc, &ContentSecurityPolicyDirectiveList::violatedDirectiveForImage);
510 }
511
512 bool ContentSecurityPolicy::allowStyleFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived) const
513 {
514     return allowResourceFromSource(url, redirectResponseReceived, ContentSecurityPolicyDirectiveNames::styleSrc, &ContentSecurityPolicyDirectiveList::violatedDirectiveForStyle);
515 }
516
517 bool ContentSecurityPolicy::allowFontFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived) const
518 {
519     return allowResourceFromSource(url, redirectResponseReceived, ContentSecurityPolicyDirectiveNames::fontSrc, &ContentSecurityPolicyDirectiveList::violatedDirectiveForFont);
520 }
521
522 bool ContentSecurityPolicy::allowMediaFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived) const
523 {
524     return allowResourceFromSource(url, redirectResponseReceived, ContentSecurityPolicyDirectiveNames::mediaSrc, &ContentSecurityPolicyDirectiveList::violatedDirectiveForMedia);
525 }
526
527 bool ContentSecurityPolicy::allowConnectToSource(const URL& url, RedirectResponseReceived redirectResponseReceived) const
528 {
529     if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol().toStringWithoutCopying()))
530         return true;
531     String sourceURL;
532     TextPosition sourcePosition(WTF::OrdinalNumber::beforeFirst(), WTF::OrdinalNumber());
533     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
534         String consoleMessage = consoleMessageForViolation(ContentSecurityPolicyDirectiveNames::connectSrc, violatedDirective, url, "Refused to connect to");
535         reportViolation(ContentSecurityPolicyDirectiveNames::connectSrc, violatedDirective, url, consoleMessage, sourceURL, sourcePosition);
536     };
537     return allPoliciesAllow(WTFMove(handleViolatedDirective), &ContentSecurityPolicyDirectiveList::violatedDirectiveForConnectSource, url, redirectResponseReceived == RedirectResponseReceived::Yes);
538 }
539
540 bool ContentSecurityPolicy::allowFormAction(const URL& url, RedirectResponseReceived redirectResponseReceived) const
541 {
542     return allowResourceFromSource(url, redirectResponseReceived, ContentSecurityPolicyDirectiveNames::formAction, &ContentSecurityPolicyDirectiveList::violatedDirectiveForFormAction);
543 }
544
545 bool ContentSecurityPolicy::allowBaseURI(const URL& url, bool overrideContentSecurityPolicy) const
546 {
547     if (overrideContentSecurityPolicy)
548         return true;
549     if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol().toStringWithoutCopying()))
550         return true;
551     String sourceURL;
552     TextPosition sourcePosition(WTF::OrdinalNumber::beforeFirst(), WTF::OrdinalNumber());
553     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
554         String consoleMessage = consoleMessageForViolation(ContentSecurityPolicyDirectiveNames::baseURI, violatedDirective, url, "Refused to change the document base URL to");
555         reportViolation(ContentSecurityPolicyDirectiveNames::baseURI, violatedDirective, url, consoleMessage, sourceURL, sourcePosition);
556     };
557     return allPoliciesAllow(WTFMove(handleViolatedDirective), &ContentSecurityPolicyDirectiveList::violatedDirectiveForBaseURI, url);
558 }
559
560 static String stripURLForUseInReport(Document& document, const URL& url)
561 {
562     if (!url.isValid())
563         return String();
564     if (!url.isHierarchical() || url.protocolIs("file"))
565         return url.protocol().toString();
566     return document.securityOrigin()->canRequest(url) ? url.strippedForUseAsReferrer() : SecurityOrigin::create(url).get().toString();
567 }
568
569 void ContentSecurityPolicy::reportViolation(const String& violatedDirective, const ContentSecurityPolicyDirective& effectiveViolatedDirective, const URL& blockedURL, const String& consoleMessage, JSC::ExecState* state) const
570 {
571     // FIXME: Extract source file and source position from JSC::ExecState.
572     return reportViolation(violatedDirective, effectiveViolatedDirective, blockedURL, consoleMessage, String(), TextPosition(WTF::OrdinalNumber::beforeFirst(), WTF::OrdinalNumber::beforeFirst()), state);
573 }
574
575 void ContentSecurityPolicy::reportViolation(const String& effectiveViolatedDirective, const ContentSecurityPolicyDirective& violatedDirective, const URL& blockedURL, const String& consoleMessage, const String& sourceURL, const TextPosition& sourcePosition, JSC::ExecState* state) const
576 {
577     logToConsole(consoleMessage, sourceURL, sourcePosition.m_line, state);
578
579     if (!m_isReportingEnabled)
580         return;
581
582     // FIXME: Support sending reports from worker.
583     if (!is<Document>(m_scriptExecutionContext) && !m_frame)
584         return;
585
586     ASSERT(!m_frame || effectiveViolatedDirective == ContentSecurityPolicyDirectiveNames::frameAncestors);
587
588     Document& document = is<Document>(m_scriptExecutionContext) ? downcast<Document>(*m_scriptExecutionContext) : *m_frame->document();
589     Frame* frame = document.frame();
590     ASSERT(!m_frame || m_frame == frame);
591     if (!frame)
592         return;
593
594     String documentURI;
595     String blockedURI;
596     if (is<Document>(m_scriptExecutionContext)) {
597         documentURI = document.url().strippedForUseAsReferrer();
598         blockedURI = stripURLForUseInReport(document, blockedURL);
599     } else {
600         // The URL of |document| may not have been initialized (say, when reporting a frame-ancestors violation).
601         // So, we use the URL of the blocked document for the protected document URL.
602         documentURI = blockedURL;
603         blockedURI = blockedURL;
604     }
605     String violatedDirectiveText = violatedDirective.text();
606     String originalPolicy = violatedDirective.directiveList().header();
607     String referrer = document.referrer();
608     ASSERT(document.loader());
609     unsigned short statusCode = document.url().protocolIs("http") && document.loader() ? document.loader()->response().httpStatusCode() : 0;
610
611     String sourceFile;
612     int lineNumber = 0;
613     int columnNumber = 0;
614     RefPtr<ScriptCallStack> stack = createScriptCallStack(JSMainThreadExecState::currentState(), 2);
615     const ScriptCallFrame* callFrame = stack->firstNonNativeCallFrame();
616     if (callFrame && callFrame->lineNumber()) {
617         sourceFile = stripURLForUseInReport(document, URL(URL(), callFrame->sourceURL()));
618         lineNumber = callFrame->lineNumber();
619         columnNumber = callFrame->columnNumber();
620     }
621
622     // 1. Dispatch violation event.
623     bool canBubble = false;
624     bool cancelable = false;
625     document.enqueueDocumentEvent(SecurityPolicyViolationEvent::create(eventNames().securitypolicyviolationEvent, canBubble, cancelable, documentURI, referrer, blockedURI, violatedDirectiveText, effectiveViolatedDirective, originalPolicy, sourceFile, statusCode, lineNumber, columnNumber));
626
627     // 2. Send violation report (if applicable).
628     const Vector<String>& reportURIs = violatedDirective.directiveList().reportURIs();
629     if (reportURIs.isEmpty())
630         return;
631
632     // We need to be careful here when deciding what information to send to the
633     // report-uri. Currently, we send only the current document's URL and the
634     // directive that was violated. The document's URL is safe to send because
635     // it's the document itself that's requesting that it be sent. You could
636     // make an argument that we shouldn't send HTTPS document URLs to HTTP
637     // report-uris (for the same reasons that we suppress the Referer in that
638     // case), but the Referer is sent implicitly whereas this request is only
639     // sent explicitly. As for which directive was violated, that's pretty
640     // harmless information.
641
642     auto cspReport = InspectorObject::create();
643     cspReport->setString(ASCIILiteral("document-uri"), documentURI);
644     cspReport->setString(ASCIILiteral("referrer"), referrer);
645     cspReport->setString(ASCIILiteral("violated-directive"), violatedDirectiveText);
646     cspReport->setString(ASCIILiteral("effective-directive"), effectiveViolatedDirective);
647     cspReport->setString(ASCIILiteral("original-policy"), originalPolicy);
648     cspReport->setString(ASCIILiteral("blocked-uri"), blockedURI);
649     cspReport->setInteger(ASCIILiteral("status-code"), statusCode);
650     if (!sourceFile.isNull()) {
651         cspReport->setString(ASCIILiteral("source-file"), sourceFile);
652         cspReport->setInteger(ASCIILiteral("line-number"), lineNumber);
653         cspReport->setInteger(ASCIILiteral("column-number"), columnNumber);
654     }
655
656     RefPtr<InspectorObject> reportObject = InspectorObject::create();
657     reportObject->setObject(ASCIILiteral("csp-report"), WTFMove(cspReport));
658
659     RefPtr<FormData> report = FormData::create(reportObject->toJSONString().utf8());
660     for (const auto& url : reportURIs)
661         PingLoader::sendViolationReport(*frame, is<Document>(m_scriptExecutionContext) ? document.completeURL(url) : document.completeURL(url, blockedURL), report.copyRef(), ViolationReportType::ContentSecurityPolicy);
662 }
663
664 void ContentSecurityPolicy::reportUnsupportedDirective(const String& name) const
665 {
666     String message;
667     if (equalLettersIgnoringASCIICase(name, "allow"))
668         message = ASCIILiteral("The 'allow' directive has been replaced with 'default-src'. Please use that directive instead, as 'allow' has no effect.");
669     else if (equalLettersIgnoringASCIICase(name, "options"))
670         message = ASCIILiteral("The 'options' directive has been replaced with 'unsafe-inline' and 'unsafe-eval' source expressions for the 'script-src' and 'style-src' directives. Please use those directives instead, as 'options' has no effect.");
671     else if (equalLettersIgnoringASCIICase(name, "policy-uri"))
672         message = ASCIILiteral("The 'policy-uri' directive has been removed from the specification. Please specify a complete policy via the Content-Security-Policy header.");
673     else
674         message = makeString("Unrecognized Content-Security-Policy directive '", name, "'.\n"); // FIXME: Why does this include a newline?
675
676     logToConsole(message);
677 }
678
679 void ContentSecurityPolicy::reportDirectiveAsSourceExpression(const String& directiveName, const String& sourceExpression) const
680 {
681     logToConsole("The Content Security Policy directive '" + directiveName + "' contains '" + sourceExpression + "' as a source expression. Did you mean '" + directiveName + " ...; " + sourceExpression + "...' (note the semicolon)?");
682 }
683
684 void ContentSecurityPolicy::reportDuplicateDirective(const String& name) const
685 {
686     logToConsole(makeString("Ignoring duplicate Content-Security-Policy directive '", name, "'.\n"));
687 }
688
689 void ContentSecurityPolicy::reportInvalidPluginTypes(const String& pluginType) const
690 {
691     String message;
692     if (pluginType.isNull())
693         message = "'plugin-types' Content Security Policy directive is empty; all plugins will be blocked.\n";
694     else
695         message = makeString("Invalid plugin type in 'plugin-types' Content Security Policy directive: '", pluginType, "'.\n");
696     logToConsole(message);
697 }
698
699 void ContentSecurityPolicy::reportInvalidSandboxFlags(const String& invalidFlags) const
700 {
701     logToConsole("Error while parsing the 'sandbox' Content Security Policy directive: " + invalidFlags);
702 }
703
704 void ContentSecurityPolicy::reportInvalidDirectiveInReportOnlyMode(const String& directiveName) const
705 {
706     logToConsole("The Content Security Policy directive '" + directiveName + "' is ignored when delivered in a report-only policy.");
707 }
708
709 void ContentSecurityPolicy::reportInvalidDirectiveInHTTPEquivMeta(const String& directiveName) const
710 {
711     logToConsole("The Content Security Policy directive '" + directiveName + "' is ignored when delivered via an HTML meta element.");
712 }
713
714 void ContentSecurityPolicy::reportInvalidDirectiveValueCharacter(const String& directiveName, const String& value) const
715 {
716     String message = makeString("The value for Content Security Policy directive '", directiveName, "' contains an invalid character: '", value, "'. Non-whitespace characters outside ASCII 0x21-0x7E must be percent-encoded, as described in RFC 3986, section 2.1: http://tools.ietf.org/html/rfc3986#section-2.1.");
717     logToConsole(message);
718 }
719
720 void ContentSecurityPolicy::reportInvalidPathCharacter(const String& directiveName, const String& value, const char invalidChar) const
721 {
722     ASSERT(invalidChar == '#' || invalidChar == '?');
723
724     String ignoring;
725     if (invalidChar == '?')
726         ignoring = "The query component, including the '?', will be ignored.";
727     else
728         ignoring = "The fragment identifier, including the '#', will be ignored.";
729
730     String message = makeString("The source list for Content Security Policy directive '", directiveName, "' contains a source with an invalid path: '", value, "'. ", ignoring);
731     logToConsole(message);
732 }
733
734 void ContentSecurityPolicy::reportInvalidSourceExpression(const String& directiveName, const String& source) const
735 {
736     String message = makeString("The source list for Content Security Policy directive '", directiveName, "' contains an invalid source: '", source, "'. It will be ignored.");
737     if (equalLettersIgnoringASCIICase(source, "'none'"))
738         message = makeString(message, " Note that 'none' has no effect unless it is the only expression in the source list.");
739     logToConsole(message);
740 }
741
742 void ContentSecurityPolicy::reportMissingReportURI(const String& policy) const
743 {
744     logToConsole("The Content Security Policy '" + policy + "' was delivered in report-only mode, but does not specify a 'report-uri'; the policy will have no effect. Please either add a 'report-uri' directive, or deliver the policy via the 'Content-Security-Policy' header.");
745 }
746
747 void ContentSecurityPolicy::logToConsole(const String& message, const String& contextURL, const WTF::OrdinalNumber& contextLine, JSC::ExecState* state) const
748 {
749     if (!m_isReportingEnabled)
750         return;
751
752     // FIXME: <http://webkit.org/b/114317> ContentSecurityPolicy::logToConsole should include a column number
753     if (m_scriptExecutionContext)
754         m_scriptExecutionContext->addConsoleMessage(MessageSource::Security, MessageLevel::Error, message, contextURL, contextLine.oneBasedInt(), 0, state);
755     else if (m_frame && m_frame->document())
756         static_cast<ScriptExecutionContext*>(m_frame->document())->addConsoleMessage(MessageSource::Security, MessageLevel::Error, message, contextURL, contextLine.oneBasedInt(), 0, state);
757 }
758
759 void ContentSecurityPolicy::reportBlockedScriptExecutionToInspector(const String& directiveText) const
760 {
761     if (m_scriptExecutionContext)
762         InspectorInstrumentation::scriptExecutionBlockedByCSP(m_scriptExecutionContext, directiveText);
763 }
764
765 bool ContentSecurityPolicy::experimentalFeaturesEnabled() const
766 {
767 #if ENABLE(CSP_NEXT)
768     return RuntimeEnabledFeatures::sharedFeatures().experimentalContentSecurityPolicyFeaturesEnabled();
769 #else
770     return false;
771 #endif
772 }
773
774 void ContentSecurityPolicy::upgradeInsecureRequestIfNeeded(ResourceRequest& request, InsecureRequestType requestType) const
775 {
776     URL url = request.url();
777     upgradeInsecureRequestIfNeeded(url, requestType);
778     request.setURL(url);
779 }
780
781 void ContentSecurityPolicy::upgradeInsecureRequestIfNeeded(URL& url, InsecureRequestType requestType) const
782 {
783     if (!url.protocolIs("http") && !url.protocolIs("ws"))
784         return;
785
786     bool upgradeRequest = m_insecureNavigationRequestsToUpgrade.contains(SecurityOrigin::create(url));
787     if (requestType == InsecureRequestType::Load || requestType == InsecureRequestType::FormSubmission)
788         upgradeRequest |= m_upgradeInsecureRequests;
789     
790     if (!upgradeRequest)
791         return;
792
793     if (url.protocolIs("http"))
794         url.setProtocol("https");
795     else if (url.protocolIs("ws"))
796         url.setProtocol("wss");
797     else
798         return;
799     
800     if (url.port() && url.port().value() == 80)
801         url.setPort(443);
802 }
803
804 void ContentSecurityPolicy::setUpgradeInsecureRequests(bool upgradeInsecureRequests)
805 {
806     m_upgradeInsecureRequests = upgradeInsecureRequests;
807     if (!m_upgradeInsecureRequests)
808         return;
809
810     if (!m_scriptExecutionContext)
811         return;
812
813     // Store the upgrade domain as an 'insecure' protocol so we can quickly identify
814     // origins we should upgrade.
815     URL upgradeURL = m_scriptExecutionContext->url();
816     if (upgradeURL.protocolIs("https"))
817         upgradeURL.setProtocol("http");
818     else if (upgradeURL.protocolIs("wss"))
819         upgradeURL.setProtocol("ws");
820     
821     m_insecureNavigationRequestsToUpgrade.add(SecurityOrigin::create(upgradeURL));
822 }
823
824 void ContentSecurityPolicy::inheritInsecureNavigationRequestsToUpgradeFromOpener(const ContentSecurityPolicy& other)
825 {
826     m_insecureNavigationRequestsToUpgrade.add(other.m_insecureNavigationRequestsToUpgrade.begin(), other.m_insecureNavigationRequestsToUpgrade.end());
827 }
828
829 HashSet<RefPtr<SecurityOrigin>>&& ContentSecurityPolicy::takeNavigationRequestsToUpgrade()
830 {
831     return WTFMove(m_insecureNavigationRequestsToUpgrade);
832 }
833
834 void ContentSecurityPolicy::setInsecureNavigationRequestsToUpgrade(HashSet<RefPtr<SecurityOrigin>>&& insecureNavigationRequests)
835 {
836     m_insecureNavigationRequestsToUpgrade = WTFMove(insecureNavigationRequests);
837 }
838
839 }