<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[198613] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/198613">198613</a></dd>
<dt>Author</dt> <dd>dbates@webkit.org</dd>
<dt>Date</dt> <dd>2016-03-23 19:41:28 -0700 (Wed, 23 Mar 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>CSP: Simplify logic for checking policies
https://bugs.webkit.org/show_bug.cgi?id=155817
<rdar://problem/25326546>
Reviewed by Zalan Bujtas.
Consolidate the various static template functions into a single function called ContentSecurityPolicy::allPoliciesAllow()
that tests whether a resource request when evaluated with respect to a directive (given as a ContentSecurityPolicyDirectiveList
pointer-to-member function) violates any of the CSPs that were delivered with the document.
No functionality changed. So, no new tests.
* page/csp/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::allPoliciesAllowHashFromContent): Formerly name isAllowedByAllWithHash. Made it
a member function so that we query for the document encoding instead of taking it as an argument. Modified
it to take a predicate function to pass it to allPoliciesAllow().
(WebCore::ContentSecurityPolicy::allowJavaScriptURLs): Modified to use ContentSecurityPolicy::allPoliciesAllow().
(WebCore::ContentSecurityPolicy::allowInlineEventHandlers): Ditto.
(WebCore::ContentSecurityPolicy::allowScriptWithNonce): Ditto.
(WebCore::ContentSecurityPolicy::allowStyleWithNonce): Ditto.
(WebCore::ContentSecurityPolicy::allowInlineScript): Modified to use ContentSecurityPolicy::allPoliciesAllow() and
ContentSecurityPolicy::allPoliciesAllowHashFromContent().
(WebCore::ContentSecurityPolicy::allowInlineStyle): Ditto.
(WebCore::ContentSecurityPolicy::allowEval): Modified to use ContentSecurityPolicy::allPoliciesAllow().
(WebCore::ContentSecurityPolicy::allowFrameAncestors): Ditto.
(WebCore::ContentSecurityPolicy::allowPluginType): Ditto.
(WebCore::ContentSecurityPolicy::allowScriptFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowObjectFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowChildFrameFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowChildContextFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowImageFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowStyleFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowFontFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowMediaFromSource): Ditto.
(WebCore::ContentSecurityPolicy::allowConnectToSource): Ditto.
(WebCore::ContentSecurityPolicy::allowFormAction): Ditto.
(WebCore::ContentSecurityPolicy::allowBaseURI): Ditto.
(WebCore::isAllowedByAllWithFrame): Deleted.
(WebCore::isAllowedByAll): Deleted.
(WebCore::isAllowedByAllWithState): Deleted.
(WebCore::isAllowedByAllWithContext): Deleted.
(WebCore::isAllowedByAllWithNonce): Deleted.
(WebCore::isAllowedByAllWithHash): Deleted.
(WebCore::isAllowedByAllWithHashFromContent): Deleted.
(WebCore::isAllowedByAllWithURL): Deleted.
(WebCore::ContentSecurityPolicy::documentEncoding): Deleted. Incorporated its functionality into ContentSecurityPolicy::allPoliciesAllowHashFromContent().
(WebCore::ContentSecurityPolicy::isActive): Deleted. This function has been unused since the removal of the CSP script
interface in <http://trac.webkit.org/changeset/197142>.
* page/csp/ContentSecurityPolicy.h:
(WebCore::ContentSecurityPolicy::allPoliciesAllow): Added. Returns whether the predicate function evaluates to true
for all CSP policies.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepagecspContentSecurityPolicycpp">trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp</a></li>
<li><a href="#trunkSourceWebCorepagecspContentSecurityPolicyh">trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (198612 => 198613)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-24 02:40:36 UTC (rev 198612)
+++ trunk/Source/WebCore/ChangeLog        2016-03-24 02:41:28 UTC (rev 198613)
</span><span class="lines">@@ -1,3 +1,57 @@
</span><ins>+2016-03-23 Daniel Bates <dabates@apple.com>
+
+ CSP: Simplify logic for checking policies
+ https://bugs.webkit.org/show_bug.cgi?id=155817
+ <rdar://problem/25326546>
+
+ Reviewed by Zalan Bujtas.
+
+ Consolidate the various static template functions into a single function called ContentSecurityPolicy::allPoliciesAllow()
+ that tests whether a resource request when evaluated with respect to a directive (given as a ContentSecurityPolicyDirectiveList
+ pointer-to-member function) violates any of the CSPs that were delivered with the document.
+
+ No functionality changed. So, no new tests.
+
+ * page/csp/ContentSecurityPolicy.cpp:
+ (WebCore::ContentSecurityPolicy::allPoliciesAllowHashFromContent): Formerly name isAllowedByAllWithHash. Made it
+ a member function so that we query for the document encoding instead of taking it as an argument. Modified
+ it to take a predicate function to pass it to allPoliciesAllow().
+ (WebCore::ContentSecurityPolicy::allowJavaScriptURLs): Modified to use ContentSecurityPolicy::allPoliciesAllow().
+ (WebCore::ContentSecurityPolicy::allowInlineEventHandlers): Ditto.
+ (WebCore::ContentSecurityPolicy::allowScriptWithNonce): Ditto.
+ (WebCore::ContentSecurityPolicy::allowStyleWithNonce): Ditto.
+ (WebCore::ContentSecurityPolicy::allowInlineScript): Modified to use ContentSecurityPolicy::allPoliciesAllow() and
+ ContentSecurityPolicy::allPoliciesAllowHashFromContent().
+ (WebCore::ContentSecurityPolicy::allowInlineStyle): Ditto.
+ (WebCore::ContentSecurityPolicy::allowEval): Modified to use ContentSecurityPolicy::allPoliciesAllow().
+ (WebCore::ContentSecurityPolicy::allowFrameAncestors): Ditto.
+ (WebCore::ContentSecurityPolicy::allowPluginType): Ditto.
+ (WebCore::ContentSecurityPolicy::allowScriptFromSource): Ditto.
+ (WebCore::ContentSecurityPolicy::allowObjectFromSource): Ditto.
+ (WebCore::ContentSecurityPolicy::allowChildFrameFromSource): Ditto.
+ (WebCore::ContentSecurityPolicy::allowChildContextFromSource): Ditto.
+ (WebCore::ContentSecurityPolicy::allowImageFromSource): Ditto.
+ (WebCore::ContentSecurityPolicy::allowStyleFromSource): Ditto.
+ (WebCore::ContentSecurityPolicy::allowFontFromSource): Ditto.
+ (WebCore::ContentSecurityPolicy::allowMediaFromSource): Ditto.
+ (WebCore::ContentSecurityPolicy::allowConnectToSource): Ditto.
+ (WebCore::ContentSecurityPolicy::allowFormAction): Ditto.
+ (WebCore::ContentSecurityPolicy::allowBaseURI): Ditto.
+ (WebCore::isAllowedByAllWithFrame): Deleted.
+ (WebCore::isAllowedByAll): Deleted.
+ (WebCore::isAllowedByAllWithState): Deleted.
+ (WebCore::isAllowedByAllWithContext): Deleted.
+ (WebCore::isAllowedByAllWithNonce): Deleted.
+ (WebCore::isAllowedByAllWithHash): Deleted.
+ (WebCore::isAllowedByAllWithHashFromContent): Deleted.
+ (WebCore::isAllowedByAllWithURL): Deleted.
+ (WebCore::ContentSecurityPolicy::documentEncoding): Deleted. Incorporated its functionality into ContentSecurityPolicy::allPoliciesAllowHashFromContent().
+ (WebCore::ContentSecurityPolicy::isActive): Deleted. This function has been unused since the removal of the CSP script
+ interface in <http://trac.webkit.org/changeset/197142>.
+ * page/csp/ContentSecurityPolicy.h:
+ (WebCore::ContentSecurityPolicy::allPoliciesAllow): Added. Returns whether the predicate function evaluates to true
+ for all CSP policies.
+
</ins><span class="cx"> 2016-03-23 Jer Noble <jer.noble@apple.com>
</span><span class="cx">
</span><span class="cx"> Media elements allowed to play without a user gesture, but requiring fullscreen playback, should not be allowed to autoplay.
</span></span></pre></div>
<a id="trunkSourceWebCorepagecspContentSecurityPolicycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp (198612 => 198613)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp        2016-03-24 02:40:36 UTC (rev 198612)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp        2016-03-24 02:41:28 UTC (rev 198613)
</span><span class="lines">@@ -174,56 +174,6 @@
</span><span class="cx"> return equalIgnoringASCIICase(url.protocol(), m_selfSourceProtocol);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-template<bool (ContentSecurityPolicyDirectiveList::*allowed)(const Frame&, const URL&, ContentSecurityPolicyDirectiveList::ReportingStatus) const>
-static bool isAllowedByAllWithFrame(const CSPDirectiveListVector& policies, const Frame& frame, const URL& url, ContentSecurityPolicyDirectiveList::ReportingStatus reportingStatus)
-{
- for (auto& policy : policies) {
- if (!(policy.get()->*allowed)(frame, url, reportingStatus))
- return false;
- }
- return true;
-}
-
-template<bool (ContentSecurityPolicyDirectiveList::*allowed)(ContentSecurityPolicyDirectiveList::ReportingStatus) const>
-static bool isAllowedByAll(const CSPDirectiveListVector& policies, ContentSecurityPolicyDirectiveList::ReportingStatus reportingStatus)
-{
- for (auto& policy : policies) {
- if (!(policy.get()->*allowed)(reportingStatus))
- return false;
- }
- return true;
-}
-
-template<bool (ContentSecurityPolicyDirectiveList::*allowed)(JSC::ExecState* state, ContentSecurityPolicyDirectiveList::ReportingStatus) const>
-static bool isAllowedByAllWithState(const CSPDirectiveListVector& policies, JSC::ExecState* state, ContentSecurityPolicyDirectiveList::ReportingStatus reportingStatus)
-{
- for (auto& policy : policies) {
- if (!(policy.get()->*allowed)(state, reportingStatus))
- return false;
- }
- return true;
-}
-
-template<bool (ContentSecurityPolicyDirectiveList::*allowed)(const String&, const WTF::OrdinalNumber&, ContentSecurityPolicyDirectiveList::ReportingStatus) const>
-static bool isAllowedByAllWithContext(const CSPDirectiveListVector& policies, const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus reportingStatus)
-{
- for (auto& policy : policies) {
- if (!(policy.get()->*allowed)(contextURL, contextLine, reportingStatus))
- return false;
- }
- return true;
-}
-
-template<bool (ContentSecurityPolicyDirectiveList::*allowed)(const String& nonce) const>
-static bool isAllowedByAllWithNonce(const CSPDirectiveListVector& policies, const String& nonce)
-{
- for (auto& policy : policies) {
- if (!(policy.get()->*allowed)(nonce))
- return false;
- }
- return true;
-}
-
</del><span class="cx"> static CryptoDigest::Algorithm toCryptoDigestAlgorithm(ContentSecurityPolicyHashAlgorithm algorithm)
</span><span class="cx"> {
</span><span class="cx"> switch (algorithm) {
</span><span class="lines">@@ -238,66 +188,42 @@
</span><span class="cx"> return CryptoDigest::Algorithm::SHA_512;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-template<bool (ContentSecurityPolicyDirectiveList::*allowed)(const ContentSecurityPolicyHash&) const>
-static bool isAllowedByAllWithHash(const CSPDirectiveListVector& policies, const ContentSecurityPolicyHash& hash)
</del><ins>+template<typename Predicate>
+bool ContentSecurityPolicy::allPoliciesAllowHashFromContent(Predicate&& predicate, const String& content, OptionSet<ContentSecurityPolicyHashAlgorithm> algorithms) const
</ins><span class="cx"> {
</span><del>- for (auto& policy : policies) {
- if (!(policy.get()->*allowed)(hash))
- return false;
- }
- return true;
-}
</del><ins>+ // FIXME: We should compute the document encoding once and cache it instead of computing it on each invocation.
+ TextEncoding documentEncoding;
+ if (is<Document>(m_scriptExecutionContext))
+ documentEncoding = downcast<Document>(*m_scriptExecutionContext).textEncoding();
+ const TextEncoding& encodingToUse = documentEncoding.isValid() ? documentEncoding : UTF8Encoding();
</ins><span class="cx">
</span><del>-template<bool (ContentSecurityPolicyDirectiveList::*allowed)(const ContentSecurityPolicyHash&) const>
-static bool isAllowedByAllWithHashFromContent(const CSPDirectiveListVector& policies, const String& content, const TextEncoding& encoding, OptionSet<ContentSecurityPolicyHashAlgorithm> algorithms)
-{
</del><span class="cx"> // FIXME: Compute the digest with respect to the raw bytes received from the page.
</span><span class="cx"> // See <https://bugs.webkit.org/show_bug.cgi?id=155184>.
</span><del>- CString contentCString = encoding.encode(content, EntitiesForUnencodables);
</del><ins>+ CString contentCString = encodingToUse.encode(content, EntitiesForUnencodables);
</ins><span class="cx"> for (auto algorithm : algorithms) {
</span><span class="cx"> auto cryptoDigest = CryptoDigest::create(toCryptoDigestAlgorithm(algorithm));
</span><span class="cx"> cryptoDigest->addBytes(contentCString.data(), contentCString.length());
</span><span class="cx"> Vector<uint8_t> digest = cryptoDigest->computeHash();
</span><del>- if (isAllowedByAllWithHash<allowed>(policies, { algorithm, digest }))
</del><ins>+ if (allPoliciesAllow(std::forward<Predicate>(predicate), std::make_pair(algorithm, digest)))
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-template<bool (ContentSecurityPolicyDirectiveList::*allowFromURL)(const URL&, ContentSecurityPolicyDirectiveList::ReportingStatus) const>
-static bool isAllowedByAllWithURL(const CSPDirectiveListVector& policies, const URL& url, ContentSecurityPolicyDirectiveList::ReportingStatus reportingStatus)
</del><ins>+bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, bool overrideContentSecurityPolicy) const
</ins><span class="cx"> {
</span><del>- if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
</del><ins>+ if (overrideContentSecurityPolicy)
</ins><span class="cx"> return true;
</span><del>-
- for (auto& policy : policies) {
- if (!(policy.get()->*allowFromURL)(url, reportingStatus))
- return false;
- }
- return true;
</del><ins>+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowJavaScriptURLs, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, bool overrideContentSecurityPolicy) const
-{
- return overrideContentSecurityPolicy || isAllowedByAllWithContext<&ContentSecurityPolicyDirectiveList::allowJavaScriptURLs>(m_policies, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
-}
-
</del><span class="cx"> bool ContentSecurityPolicy::allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithContext<&ContentSecurityPolicyDirectiveList::allowInlineEventHandlers>(m_policies, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowInlineEventHandlers, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-// FIXME: We should compute the document encoding once and cache it instead of computing it on each invocation.
-const TextEncoding& ContentSecurityPolicy::documentEncoding() const
-{
- if (!is<Document>(m_scriptExecutionContext))
- return UTF8Encoding();
- Document& document = downcast<Document>(*m_scriptExecutionContext);
- if (TextResourceDecoder* decoder = document.decoder())
- return decoder->encoding();
- return UTF8Encoding();
-}
-
</del><span class="cx"> bool ContentSecurityPolicy::allowScriptWithNonce(const String& nonce, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><span class="cx"> if (overrideContentSecurityPolicy)
</span><span class="lines">@@ -305,7 +231,7 @@
</span><span class="cx"> String strippedNonce = stripLeadingAndTrailingHTMLSpaces(nonce);
</span><span class="cx"> if (strippedNonce.isEmpty())
</span><span class="cx"> return false;
</span><del>- if (isAllowedByAllWithNonce<&ContentSecurityPolicyDirectiveList::allowScriptWithNonce>(m_policies, strippedNonce))
</del><ins>+ if (allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowScriptWithNonce, strippedNonce))
</ins><span class="cx"> return true;
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -317,7 +243,7 @@
</span><span class="cx"> String strippedNonce = stripLeadingAndTrailingHTMLSpaces(nonce);
</span><span class="cx"> if (strippedNonce.isEmpty())
</span><span class="cx"> return false;
</span><del>- if (isAllowedByAllWithNonce<&ContentSecurityPolicyDirectiveList::allowStyleWithNonce>(m_policies, strippedNonce))
</del><ins>+ if (allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowStyleWithNonce, strippedNonce))
</ins><span class="cx"> return true;
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -327,9 +253,9 @@
</span><span class="cx"> if (overrideContentSecurityPolicy)
</span><span class="cx"> return true;
</span><span class="cx"> if (!m_hashAlgorithmsForInlineScripts.isEmpty() && !scriptContent.isEmpty()
</span><del>- && isAllowedByAllWithHashFromContent<&ContentSecurityPolicyDirectiveList::allowInlineScriptWithHash>(m_policies, scriptContent, documentEncoding(), m_hashAlgorithmsForInlineScripts))
</del><ins>+ && allPoliciesAllowHashFromContent(&ContentSecurityPolicyDirectiveList::allowInlineScriptWithHash, scriptContent, m_hashAlgorithmsForInlineScripts))
</ins><span class="cx"> return true;
</span><del>- return isAllowedByAllWithContext<&ContentSecurityPolicyDirectiveList::allowInlineScript>(m_policies, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowInlineScript, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, const String& styleContent, bool overrideContentSecurityPolicy) const
</span><span class="lines">@@ -339,14 +265,16 @@
</span><span class="cx"> if (m_overrideInlineStyleAllowed)
</span><span class="cx"> return true;
</span><span class="cx"> if (!m_hashAlgorithmsForInlineStylesheets.isEmpty() && !styleContent.isEmpty()
</span><del>- && isAllowedByAllWithHashFromContent<&ContentSecurityPolicyDirectiveList::allowInlineStyleWithHash>(m_policies, styleContent, documentEncoding(), m_hashAlgorithmsForInlineStylesheets))
</del><ins>+ && allPoliciesAllowHashFromContent(&ContentSecurityPolicyDirectiveList::allowInlineStyleWithHash, styleContent, m_hashAlgorithmsForInlineStylesheets))
</ins><span class="cx"> return true;
</span><del>- return isAllowedByAllWithContext<&ContentSecurityPolicyDirectiveList::allowInlineStyle>(m_policies, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowInlineStyle, contextURL, contextLine, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowEval(JSC::ExecState* state, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithState<&ContentSecurityPolicyDirectiveList::allowEval>(m_policies, state, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowEval, state, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowFrameAncestors(const Frame& frame, const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="lines">@@ -356,80 +284,115 @@
</span><span class="cx"> Frame& topFrame = frame.tree().top();
</span><span class="cx"> if (&frame == &topFrame)
</span><span class="cx"> return true;
</span><del>- return isAllowedByAllWithFrame<&ContentSecurityPolicyDirectiveList::allowFrameAncestors>(m_policies, frame, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowFrameAncestors, frame, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowPluginType(const String& type, const String& typeAttribute, const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><span class="cx"> if (overrideContentSecurityPolicy)
</span><span class="cx"> return true;
</span><del>- for (auto& policy : m_policies) {
- if (!policy->allowPluginType(type, typeAttribute, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport))
- return false;
- }
- return true;
</del><ins>+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowPluginType, type, typeAttribute, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowScriptFromSource(const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithURL<&ContentSecurityPolicyDirectiveList::allowScriptFromSource>(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowScriptFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowObjectFromSource(const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithURL<&ContentSecurityPolicyDirectiveList::allowObjectFromSource>(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowObjectFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowChildFrameFromSource(const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithURL<&ContentSecurityPolicyDirectiveList::allowChildFrameFromSource>(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowChildFrameFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowChildContextFromSource(const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithURL<&ContentSecurityPolicyDirectiveList::allowChildContextFromSource>(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowChildContextFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowImageFromSource(const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithURL<&ContentSecurityPolicyDirectiveList::allowImageFromSource>(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowImageFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowStyleFromSource(const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithURL<&ContentSecurityPolicyDirectiveList::allowStyleFromSource>(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowStyleFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowFontFromSource(const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithURL<&ContentSecurityPolicyDirectiveList::allowFontFromSource>(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowFontFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowMediaFromSource(const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithURL<&ContentSecurityPolicyDirectiveList::allowMediaFromSource>(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowMediaFromSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowConnectToSource(const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithURL<&ContentSecurityPolicyDirectiveList::allowConnectToSource>(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowConnectToSource, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowFormAction(const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithURL<&ContentSecurityPolicyDirectiveList::allowFormAction>(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowFormAction, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool ContentSecurityPolicy::allowBaseURI(const URL& url, bool overrideContentSecurityPolicy) const
</span><span class="cx"> {
</span><del>- return overrideContentSecurityPolicy || isAllowedByAllWithURL<&ContentSecurityPolicyDirectiveList::allowBaseURI>(m_policies, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</del><ins>+ if (overrideContentSecurityPolicy)
+ return true;
+ if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
+ return true;
+ return allPoliciesAllow(&ContentSecurityPolicyDirectiveList::allowBaseURI, url, ContentSecurityPolicyDirectiveList::ReportingStatus::SendReport);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-bool ContentSecurityPolicy::isActive() const
-{
- return !m_policies.isEmpty();
-}
-
</del><span class="cx"> ContentSecurityPolicy::ReflectedXSSDisposition ContentSecurityPolicy::reflectedXSSDisposition() const
</span><span class="cx"> {
</span><span class="cx"> ReflectedXSSDisposition disposition = ReflectedXSSUnset;
</span></span></pre></div>
<a id="trunkSourceWebCorepagecspContentSecurityPolicyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h (198612 => 198613)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h        2016-03-24 02:40:36 UTC (rev 198612)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h        2016-03-24 02:41:28 UTC (rev 198613)
</span><span class="lines">@@ -107,8 +107,6 @@
</span><span class="cx">
</span><span class="cx"> void setOverrideAllowInlineStyle(bool);
</span><span class="cx">
</span><del>- bool isActive() const;
-
</del><span class="cx"> void gatherReportURIs(DOMStringList&) const;
</span><span class="cx">
</span><span class="cx"> bool experimentalFeaturesEnabled() const;
</span><span class="lines">@@ -157,7 +155,8 @@
</span><span class="cx">
</span><span class="cx"> void didReceiveHeader(const String&, ContentSecurityPolicyHeaderType, ContentSecurityPolicy::PolicyFrom);
</span><span class="cx">
</span><del>- const TextEncoding& documentEncoding() const;
</del><ins>+ template<typename Predicate, typename... Args> bool allPoliciesAllow(Predicate&&, Args&&...) const WARN_UNUSED_RETURN;
+ template<typename Predicate> bool allPoliciesAllowHashFromContent(Predicate&&, const String& content, OptionSet<ContentSecurityPolicyHashAlgorithm>) const WARN_UNUSED_RETURN;
</ins><span class="cx">
</span><span class="cx"> // We can never have both a script execution context and a frame.
</span><span class="cx"> ScriptExecutionContext* m_scriptExecutionContext { nullptr };
</span><span class="lines">@@ -173,6 +172,16 @@
</span><span class="cx"> OptionSet<ContentSecurityPolicyHashAlgorithm> m_hashAlgorithmsForInlineStylesheets;
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+template<typename Predicate, typename... Args>
+inline bool ContentSecurityPolicy::allPoliciesAllow(Predicate&& predicate, Args&&... args) const
+{
+ for (auto& policy : m_policies) {
+ if (!(policy.get()->*predicate)(std::forward<Args>(args)...))
+ return false;
+ }
+ return true;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+}
+
</ins><span class="cx"> #endif
</span></span></pre>
</div>
</div>
</body>
</html>