Title: [286853] trunk
Revision
286853
Author
[email protected]
Date
2021-12-10 08:56:55 -0800 (Fri, 10 Dec 2021)

Log Message

CSP: Allow external scripts with SRI hashes matching CSP
https://bugs.webkit.org/show_bug.cgi?id=233911

Reviewed by Kate Cheney.

LayoutTests/imported/w3c:

Update expectations with more passes.

* web-platform-tests/content-security-policy/script-src/script-src-report-only-policy-works-with-external-hash-policy-expected.txt:
* web-platform-tests/content-security-policy/script-src/script-src-sri_hash.sub-expected.txt:

Source/WebCore:

This is a change in CSP3 that allows loading external
scripts that have SRI hashes matching CSP hashes.
https://www.w3.org/TR/CSP3/#external-hash

ResourceCryptographicDigest was changed to not validate padding
during base64 decoding which is harmless and fixes parsing the
hashes used in WPT's script-src-sri_hash.sub.html.

* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::isAllowedByContentSecurityPolicy):
* loader/ResourceCryptographicDigest.cpp:
(WebCore::parseCryptographicDigestImpl):
(WebCore::decodeEncodedResourceCryptographicDigest):
* loader/SubresourceIntegrity.cpp:
(WebCore::parseIntegrityMetadata):
* loader/SubresourceIntegrity.h:
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::allowedByContentSecurityPolicy const):
* page/csp/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::allScriptPoliciesAllow const):
(WebCore::parseSubResourceIntegrityIntoDigests):
(WebCore::ContentSecurityPolicy::allowResourceFromSource const):
(WebCore::ContentSecurityPolicy::allowScriptFromSource const):
* page/csp/ContentSecurityPolicy.h:
* page/csp/ContentSecurityPolicyDirectiveList.cpp:
(WebCore::ContentSecurityPolicyDirectiveList::violatedDirectiveForScript const):
* page/csp/ContentSecurityPolicyDirectiveList.h:
* page/csp/ContentSecurityPolicySourceList.cpp:
(WebCore::ContentSecurityPolicySourceList::matchesAll const):
* page/csp/ContentSecurityPolicySourceList.h:
* page/csp/ContentSecurityPolicySourceListDirective.cpp:
(WebCore::ContentSecurityPolicySourceListDirective::containsAllHashes const):
* page/csp/ContentSecurityPolicySourceListDirective.h:

LayoutTests:

Update tests to accept base64 with extra padding.

* http/tests/security/contentSecurityPolicy/1.1/scripthash-tests-expected.txt:
* http/tests/security/contentSecurityPolicy/1.1/scripthash-tests.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (286852 => 286853)


--- trunk/LayoutTests/ChangeLog	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/LayoutTests/ChangeLog	2021-12-10 16:56:55 UTC (rev 286853)
@@ -1,3 +1,15 @@
+2021-12-10  Patrick Griffis  <[email protected]>
+
+        CSP: Allow external scripts with SRI hashes matching CSP
+        https://bugs.webkit.org/show_bug.cgi?id=233911
+
+        Reviewed by Kate Cheney.
+
+        Update tests to accept base64 with extra padding.
+
+        * http/tests/security/contentSecurityPolicy/1.1/scripthash-tests-expected.txt:
+        * http/tests/security/contentSecurityPolicy/1.1/scripthash-tests.html:
+
 2021-12-10  Alan Bujtas  <[email protected]>
 
         [LFC][IFC] Enable bidi handling for content with inline boxes

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/scripthash-tests-expected.txt (286852 => 286853)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/scripthash-tests-expected.txt	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/scripthash-tests-expected.txt	2021-12-10 16:56:55 UTC (rev 286853)
@@ -12,8 +12,6 @@
 CONSOLE MESSAGE: Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy.
 CONSOLE MESSAGE: The source list for Content Security Policy directive 'script-src' contains an invalid source: ''sha256-/Vet2Rva6wwsny8xybL+=bQal0Gtf0FZW7EOVqqg+Hna=''. It will be ignored.
 CONSOLE MESSAGE: Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy.
-CONSOLE MESSAGE: The source list for Content Security Policy directive 'script-src' contains an invalid source: ''sha256-/vET2rVA6WWSNY8XYBl+BqAL0gTF0fzw7eovQQG+hNA==''. It will be ignored.
-CONSOLE MESSAGE: Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy.
 CONSOLE MESSAGE: The source list for Content Security Policy directive 'script-src' contains an invalid source: ''sha256-/vET2rVA6WWSNY8XYBl+BqAL0gTF0fzw7eovQQG+hNA===''. It will be ignored.
 CONSOLE MESSAGE: Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy.
 CONSOLE MESSAGE: The source list for Content Security Policy directive 'script-src' contains an invalid source: ''sha256-'. It will be ignored.
@@ -53,7 +51,7 @@
 PASS "SHA-256 hash with SHA-384 prefix" did not run inline script.
 PASS "SHA-256 hash with SHA-512 prefix" did not run inline script.
 PASS "Malformed SHA-256 hash (equal sign in disallowed position)" did not run inline script.
-PASS "SHA-256 hash with one extraneous equal sign" did not run inline script.
+PASS "SHA-256 hash with one extraneous equal sign" did run inline script.
 PASS "SHA-256 hash with two extraneous equal signs" did not run inline script.
 PASS "Malformed hash source" did not run inline script.
 PASS "Hash source without hash" did not run inline script.

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/scripthash-tests.html (286852 => 286853)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/scripthash-tests.html	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/scripthash-tests.html	2021-12-10 16:56:55 UTC (rev 286853)
@@ -159,7 +159,7 @@
     charset: "UTF8",
     script: encodeURIComponent("didRunInlineScript = true;"),
     hashSource: "'sha256-/vET2rVA6WWSNY8XYBl+BqAL0gTF0fzw7eovQQG+hNA=='",
-    expectedResult: DoNotRunInlineScript,
+    expectedResult: RunInlineScript,
 },
 {
     name: "SHA-256 hash with two extraneous equal signs",

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (286852 => 286853)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-12-10 16:56:55 UTC (rev 286853)
@@ -1,3 +1,15 @@
+2021-12-10  Patrick Griffis  <[email protected]>
+
+        CSP: Allow external scripts with SRI hashes matching CSP
+        https://bugs.webkit.org/show_bug.cgi?id=233911
+
+        Reviewed by Kate Cheney.
+
+        Update expectations with more passes.
+
+        * web-platform-tests/content-security-policy/script-src/script-src-report-only-policy-works-with-external-hash-policy-expected.txt:
+        * web-platform-tests/content-security-policy/script-src/script-src-sri_hash.sub-expected.txt:
+
 2021-12-10  Manuel Rego Casasnovas  <[email protected]>
 
         [WPT] Import resources/accesskey.js

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/script-src-report-only-policy-works-with-external-hash-policy-expected.txt (286852 => 286853)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/script-src-report-only-policy-works-with-external-hash-policy-expected.txt	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/script-src-report-only-policy-works-with-external-hash-policy-expected.txt	2021-12-10 16:56:55 UTC (rev 286853)
@@ -1,4 +1,4 @@
 
-FAIL Should fire securitypolicyviolation event assert_equals: expected "report" but got "enforce"
-FAIL External script in a script tag with matching SRI hash should run. assert_true: External script ran. expected true got false
+PASS Should fire securitypolicyviolation event
+PASS External script in a script tag with matching SRI hash should run.
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/script-src-sri_hash.sub-expected.txt (286852 => 286853)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/script-src-sri_hash.sub-expected.txt	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/script-src-sri_hash.sub-expected.txt	2021-12-10 16:56:55 UTC (rev 286853)
@@ -2,14 +2,14 @@
 
 
 PASS Load all the tests.
-FAIL matching integrity assert_unreached: Script should load! http://localhost:8800/content-security-policy/script-src/simpleSourcedScript.js Reached unreachable code
-FAIL multiple matching integrity assert_unreached: Script should load! http://localhost:8800/content-security-policy/script-src/simpleSourcedScript.js Reached unreachable code
+PASS matching integrity
+PASS multiple matching integrity
 PASS no integrity
-FAIL matching plus unsupported integrity assert_unreached: Script should load! http://localhost:8800/content-security-policy/script-src/simpleSourcedScript.js Reached unreachable code
+PASS matching plus unsupported integrity
 PASS mismatched integrity
 PASS multiple mismatched integrity
 PASS partially matching integrity
 FAIL crossorigin no integrity but allowed host assert_unreached: Script should load! http://127.0.0.1:8800/content-security-policy/script-src/crossoriginScript.js Reached unreachable code
 FAIL crossorigin mismatched integrity but allowed host assert_unreached: Script should load! http://127.0.0.1:8800/content-security-policy/script-src/crossoriginScript.js Reached unreachable code
-FAIL External script in a script tag with matching SRI hash should run. assert_true: External script ran. expected true got false
+PASS External script in a script tag with matching SRI hash should run.
 

Modified: trunk/Source/WebCore/ChangeLog (286852 => 286853)


--- trunk/Source/WebCore/ChangeLog	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/ChangeLog	2021-12-10 16:56:55 UTC (rev 286853)
@@ -1,3 +1,44 @@
+2021-12-10  Patrick Griffis  <[email protected]>
+
+        CSP: Allow external scripts with SRI hashes matching CSP
+        https://bugs.webkit.org/show_bug.cgi?id=233911
+
+        Reviewed by Kate Cheney.
+
+        This is a change in CSP3 that allows loading external
+        scripts that have SRI hashes matching CSP hashes.
+        https://www.w3.org/TR/CSP3/#external-hash
+
+        ResourceCryptographicDigest was changed to not validate padding
+        during base64 decoding which is harmless and fixes parsing the
+        hashes used in WPT's script-src-sri_hash.sub.html.
+
+        * loader/DocumentThreadableLoader.cpp:
+        (WebCore::DocumentThreadableLoader::isAllowedByContentSecurityPolicy):
+        * loader/ResourceCryptographicDigest.cpp:
+        (WebCore::parseCryptographicDigestImpl):
+        (WebCore::decodeEncodedResourceCryptographicDigest):
+        * loader/SubresourceIntegrity.cpp:
+        (WebCore::parseIntegrityMetadata):
+        * loader/SubresourceIntegrity.h:
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::allowedByContentSecurityPolicy const):
+        * page/csp/ContentSecurityPolicy.cpp:
+        (WebCore::ContentSecurityPolicy::allScriptPoliciesAllow const):
+        (WebCore::parseSubResourceIntegrityIntoDigests):
+        (WebCore::ContentSecurityPolicy::allowResourceFromSource const):
+        (WebCore::ContentSecurityPolicy::allowScriptFromSource const):
+        * page/csp/ContentSecurityPolicy.h:
+        * page/csp/ContentSecurityPolicyDirectiveList.cpp:
+        (WebCore::ContentSecurityPolicyDirectiveList::violatedDirectiveForScript const):
+        * page/csp/ContentSecurityPolicyDirectiveList.h:
+        * page/csp/ContentSecurityPolicySourceList.cpp:
+        (WebCore::ContentSecurityPolicySourceList::matchesAll const):
+        * page/csp/ContentSecurityPolicySourceList.h:
+        * page/csp/ContentSecurityPolicySourceListDirective.cpp:
+        (WebCore::ContentSecurityPolicySourceListDirective::containsAllHashes const):
+        * page/csp/ContentSecurityPolicySourceListDirective.h:
+
 2021-12-10  Alan Bujtas  <[email protected]>
 
         [LFC][IFC] Replace Vector<std::unique_ptr<DisplayBoxNode> with Vector<DisplayBoxTree::Node>

Modified: trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp (286852 => 286853)


--- trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp	2021-12-10 16:56:55 UTC (rev 286853)
@@ -685,7 +685,7 @@
     case ContentSecurityPolicyEnforcement::EnforceConnectSrcDirective:
         return contentSecurityPolicy().allowConnectToSource(url, redirectResponseReceived, preRedirectURL);
     case ContentSecurityPolicyEnforcement::EnforceScriptSrcDirective:
-        return contentSecurityPolicy().allowScriptFromSource(url, redirectResponseReceived, preRedirectURL);
+        return contentSecurityPolicy().allowScriptFromSource(url, redirectResponseReceived, preRedirectURL, m_options.integrity);
     }
     ASSERT_NOT_REACHED();
     return false;

Modified: trunk/Source/WebCore/loader/ResourceCryptographicDigest.cpp (286852 => 286853)


--- trunk/Source/WebCore/loader/ResourceCryptographicDigest.cpp	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/loader/ResourceCryptographicDigest.cpp	2021-12-10 16:56:55 UTC (rev 286853)
@@ -71,7 +71,7 @@
 
     StringView hashValue(beginHashValue, buffer.position() - beginHashValue);
 
-    if (auto digest = base64Decode(hashValue, Base64DecodeOptions::ValidatePadding))
+    if (auto digest = base64Decode(hashValue))
         return ResourceCryptographicDigest { *algorithm, WTFMove(*digest) };
 
     if (auto digest = base64URLDecode(hashValue))
@@ -125,7 +125,7 @@
 
 std::optional<ResourceCryptographicDigest> decodeEncodedResourceCryptographicDigest(const EncodedResourceCryptographicDigest& encodedDigest)
 {
-    if (auto digest = base64Decode(encodedDigest.digest, Base64DecodeOptions::ValidatePadding))
+    if (auto digest = base64Decode(encodedDigest.digest))
         return ResourceCryptographicDigest { encodedDigest.algorithm, WTFMove(*digest) };
 
     if (auto digest = base64URLDecode(encodedDigest.digest))

Modified: trunk/Source/WebCore/loader/SubresourceIntegrity.cpp (286852 => 286853)


--- trunk/Source/WebCore/loader/SubresourceIntegrity.cpp	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/loader/SubresourceIntegrity.cpp	2021-12-10 16:56:55 UTC (rev 286853)
@@ -96,7 +96,7 @@
     }
 }
 
-static std::optional<Vector<EncodedResourceCryptographicDigest>> parseIntegrityMetadata(const String& integrityMetadata)
+std::optional<Vector<EncodedResourceCryptographicDigest>> parseIntegrityMetadata(const String& integrityMetadata)
 {
     if (integrityMetadata.isEmpty())
         return std::nullopt;

Modified: trunk/Source/WebCore/loader/SubresourceIntegrity.h (286852 => 286853)


--- trunk/Source/WebCore/loader/SubresourceIntegrity.h	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/loader/SubresourceIntegrity.h	2021-12-10 16:56:55 UTC (rev 286853)
@@ -33,5 +33,6 @@
 
 bool matchIntegrityMetadata(const CachedResource&, const String& integrityMetadata);
 String integrityMismatchDescription(const CachedResource&, const String& integrityMetadata);
+std::optional<Vector<EncodedResourceCryptographicDigest>> parseIntegrityMetadata(const String& integrityMetadata);
 
 }

Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (286852 => 286853)


--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2021-12-10 16:56:55 UTC (rev 286853)
@@ -501,7 +501,7 @@
     case CachedResource::Type::XSLStyleSheet:
 #endif
     case CachedResource::Type::Script:
-        if (!m_document->contentSecurityPolicy()->allowScriptFromSource(url, redirectResponseReceived, preRedirectURL))
+        if (!m_document->contentSecurityPolicy()->allowScriptFromSource(url, redirectResponseReceived, preRedirectURL, options.integrity))
             return false;
         break;
     case CachedResource::Type::CSSStyleSheet:

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp (286852 => 286853)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp	2021-12-10 16:56:55 UTC (rev 286853)
@@ -52,6 +52,7 @@
 #include "SecurityOrigin.h"
 #include "SecurityPolicyViolationEvent.h"
 #include "Settings.h"
+#include "SubresourceIntegrity.h"
 #include <_javascript_Core/ScriptCallStack.h>
 #include <_javascript_Core/ScriptCallStackFactory.h>
 #include <pal/crypto/CryptoDigest.h>
@@ -339,7 +340,7 @@
     for (auto& policy : m_policies) {
         auto violatedDirectiveForNonParserInsertedScript = policy.get()->violatedDirectiveForParserInsertedScript(parserInserted);
         auto violatedDirectiveForScriptNonce = policy.get()->violatedDirectiveForScriptNonce(nonce);
-        auto violatedDirectiveForScriptSrc = policy.get()->violatedDirectiveForScript(url, false);
+        auto violatedDirectiveForScriptSrc = policy.get()->violatedDirectiveForScript(url, false, { });
         auto [foundHashInEnforcedPolicies, foundHashInReportOnlyPolicies] = findHashOfContentInPolicies(&ContentSecurityPolicyDirectiveList::violatedDirectiveForScriptHash, scriptContent, m_hashAlgorithmsForInlineScripts);
 
         if (violatedDirectiveForNonParserInsertedScript && violatedDirectiveForScriptNonce && violatedDirectiveForScriptSrc && !foundHashInEnforcedPolicies) {
@@ -640,12 +641,40 @@
     return allowResourceFromSource(url, redirectResponseReceived, ContentSecurityPolicyDirectiveNames::childSrc, &ContentSecurityPolicyDirectiveList::violatedDirectiveForChildContext, preRedirectURL);
 }
 
-bool ContentSecurityPolicy::allowScriptFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived, const URL& preRedirectURL) const
+static Vector<ResourceCryptographicDigest> parseSubResourceIntegrityIntoDigests(const String& subResourceIntegrity)
 {
+    auto encodedDigests = parseIntegrityMetadata(subResourceIntegrity);
+    Vector<ResourceCryptographicDigest> decodedDigests;
+
+    if (!encodedDigests.has_value())
+        return { };
+
+    for (const auto& encodedDigest : encodedDigests.value()) {
+        auto decodedDigest = decodeEncodedResourceCryptographicDigest(encodedDigest);
+        if (decodedDigest.has_value())
+            decodedDigests.append(decodedDigest.value());
+    }
+
+    return decodedDigests;
+}
+
+bool ContentSecurityPolicy::allowScriptFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived, const URL& preRedirectURL, const String& subResourceIntegrity) const
+{
     if (shouldPerformEarlyCSPCheck())
         return true;
+    if (LegacySchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol().toStringWithoutCopying()))
+        return true;
 
-    return allowResourceFromSource(url, redirectResponseReceived, ContentSecurityPolicyDirectiveNames::scriptSrc, &ContentSecurityPolicyDirectiveList::violatedDirectiveForScript, preRedirectURL);
+    String sourceURL;
+    const auto& blockedURL = !preRedirectURL.isNull() ? preRedirectURL : url;
+    TextPosition sourcePosition(OrdinalNumber::beforeFirst(), OrdinalNumber());
+    auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
+        String consoleMessage = consoleMessageForViolation(ContentSecurityPolicyDirectiveNames::scriptSrc, violatedDirective, blockedURL, "Refused to load");
+        reportViolation(ContentSecurityPolicyDirectiveNames::scriptSrc, violatedDirective, blockedURL.string(), consoleMessage, sourceURL, StringView(), sourcePosition);
+    };
+
+    auto subResourceIntegrityDigests = parseSubResourceIntegrityIntoDigests(subResourceIntegrity);
+    return allPoliciesAllow(WTFMove(handleViolatedDirective), &ContentSecurityPolicyDirectiveList::violatedDirectiveForScript, url, redirectResponseReceived == RedirectResponseReceived::Yes, subResourceIntegrityDigests);
 }
 
 bool ContentSecurityPolicy::allowImageFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived, const URL& preRedirectURL) const

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h (286852 => 286853)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h	2021-12-10 16:56:55 UTC (rev 286853)
@@ -113,7 +113,7 @@
     WEBCORE_EXPORT bool overridesXFrameOptions() const;
 
     enum class RedirectResponseReceived { No, Yes };
-    WEBCORE_EXPORT bool allowScriptFromSource(const URL&, RedirectResponseReceived = RedirectResponseReceived::No, const URL& preRedirectURL = URL()) const;
+    WEBCORE_EXPORT bool allowScriptFromSource(const URL&, RedirectResponseReceived = RedirectResponseReceived::No, const URL& preRedirectURL = URL(), const String& = nullString()) const;
     bool allowImageFromSource(const URL&, RedirectResponseReceived = RedirectResponseReceived::No, const URL& preRedirectURL = URL()) const;
     bool allowStyleFromSource(const URL&, RedirectResponseReceived = RedirectResponseReceived::No, const URL& preRedirectURL = URL()) const;
     bool allowFontFromSource(const URL&, RedirectResponseReceived = RedirectResponseReceived::No, const URL& preRedirectURL = URL()) const;

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp (286852 => 286853)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp	2021-12-10 16:56:55 UTC (rev 286853)
@@ -387,9 +387,13 @@
     return m_pluginTypes.get();
 }
 
-const ContentSecurityPolicyDirective* ContentSecurityPolicyDirectiveList::violatedDirectiveForScript(const URL& url, bool didReceiveRedirectResponse) const
+const ContentSecurityPolicyDirective* ContentSecurityPolicyDirectiveList::violatedDirectiveForScript(const URL& url, bool didReceiveRedirectResponse, const Vector<ResourceCryptographicDigest>& subResourceIntegrityDigests) const
 {
     auto* operativeDirective = this->operativeDirective(m_scriptSrc.get(), ContentSecurityPolicyDirectiveNames::scriptSrcElem);
+
+    if (operativeDirective->containsAllHashes(subResourceIntegrityDigests))
+        return nullptr;
+
     if (checkSource(operativeDirective, url, didReceiveRedirectResponse))
         return nullptr;
     return operativeDirective;

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.h (286852 => 286853)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.h	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.h	2021-12-10 16:56:55 UTC (rev 286853)
@@ -75,7 +75,7 @@
     const ContentSecurityPolicyDirective* violatedDirectiveForMedia(const URL&, bool didReceiveRedirectResponse) const;
     const ContentSecurityPolicyDirective* violatedDirectiveForObjectSource(const URL&, bool didReceiveRedirectResponse, ContentSecurityPolicySourceListDirective::ShouldAllowEmptyURLIfSourceListIsNotNone) const;
     const ContentSecurityPolicyDirective* violatedDirectiveForPluginType(const String& type, const String& typeAttribute) const;
-    const ContentSecurityPolicyDirective* violatedDirectiveForScript(const URL&, bool didReceiveRedirectResponse) const;
+    const ContentSecurityPolicyDirective* violatedDirectiveForScript(const URL&, bool didReceiveRedirectResponse, const Vector<ResourceCryptographicDigest>&) const;
     const ContentSecurityPolicyDirective* violatedDirectiveForStyle(const URL&, bool didReceiveRedirectResponse) const;
 
     const ContentSecurityPolicyDirective* defaultSrc() const { return m_defaultSrc.get(); }

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.cpp (286852 => 286853)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.cpp	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.cpp	2021-12-10 16:56:55 UTC (rev 286853)
@@ -155,6 +155,19 @@
     return false;
 }
 
+bool ContentSecurityPolicySourceList::matchesAll(const Vector<ContentSecurityPolicyHash>& hashes) const
+{
+    if (hashes.isEmpty())
+        return false;
+
+    for (auto& hash : hashes) {
+        if (!m_hashes.contains(hash))
+            return false;
+    }
+
+    return true;
+}
+
 bool ContentSecurityPolicySourceList::matches(const String& nonce) const
 {
     if (nonce.isEmpty())

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.h (286852 => 286853)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.h	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.h	2021-12-10 16:56:55 UTC (rev 286853)
@@ -45,6 +45,7 @@
 
     bool matches(const URL&, bool didReceiveRedirectResponse) const;
     bool matches(const Vector<ContentSecurityPolicyHash>&) const;
+    bool matchesAll(const Vector<ContentSecurityPolicyHash>&) const;
     bool matches(const String& nonce) const;
 
     OptionSet<ContentSecurityPolicyHashAlgorithm> hashAlgorithmsUsed() const { return m_hashAlgorithmsUsed; }

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceListDirective.cpp (286852 => 286853)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceListDirective.cpp	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceListDirective.cpp	2021-12-10 16:56:55 UTC (rev 286853)
@@ -52,6 +52,11 @@
     return m_sourceList.matches(nonce);
 }
 
+bool ContentSecurityPolicySourceListDirective::containsAllHashes(const Vector<ContentSecurityPolicyHash>& hashes) const
+{
+    return m_sourceList.matchesAll(hashes);
+}
+
 bool ContentSecurityPolicySourceListDirective::allows(const Vector<ContentSecurityPolicyHash>& hashes) const
 {
     return m_sourceList.matches(hashes);

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceListDirective.h (286852 => 286853)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceListDirective.h	2021-12-10 16:33:19 UTC (rev 286852)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceListDirective.h	2021-12-10 16:56:55 UTC (rev 286853)
@@ -40,6 +40,7 @@
     enum class ShouldAllowEmptyURLIfSourceListIsNotNone { No, Yes };
     bool allows(const URL&, bool didReceiveRedirectResponse, ShouldAllowEmptyURLIfSourceListIsNotNone);
     bool allows(const Vector<ContentSecurityPolicyHash>&) const;
+    bool containsAllHashes(const Vector<ContentSecurityPolicyHash>&) const;
     bool allowUnsafeHashes(const Vector<ContentSecurityPolicyHash>&) const;
     bool allows(const String& nonce) const;
     bool allowInline() const { return m_sourceList.allowInline(); }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to