Title: [288792] trunk
Revision
288792
Author
[email protected]
Date
2022-01-29 11:27:59 -0800 (Sat, 29 Jan 2022)

Log Message

CSP: Properly block image content in object elements
https://bugs.webkit.org/show_bug.cgi?id=235837

Reviewed by Kate Cheney.

LayoutTests/imported/w3c:

Update expectations with more passes.

* web-platform-tests/content-security-policy/object-src/object-src-url-blocked-expected.txt:
* web-platform-tests/content-security-policy/object-src/object-src-url-embed-blocked-expected.txt:
* web-platform-tests/content-security-policy/object-src/object-src-url-redirect-blocked.sub-expected.txt:

Source/WebCore:

When an image is loaded through an object element it now passes through
the object-src directive check as the spec documents:
https://www.w3.org/TR/CSP3/#directive-object-src

* loader/ImageLoader.cpp:
(WebCore::ImageLoader::updateFromElement):
* loader/ResourceLoaderOptions.h:
(WebCore::ResourceLoaderOptions::loadedFromPluginElement):
(WebCore::ResourceLoaderOptions::ResourceLoaderOptions):
(WebCore::ResourceLoaderOptions::loadedFromOpaqueSource): Deleted.
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::allowedByContentSecurityPolicy const):
* page/csp/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::allowObjectFromSource const):
* page/csp/ContentSecurityPolicy.h:

LayoutTests:

* http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked-expected.txt:
* http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked2-expected.txt:
* http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked3-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (288791 => 288792)


--- trunk/LayoutTests/ChangeLog	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/LayoutTests/ChangeLog	2022-01-29 19:27:59 UTC (rev 288792)
@@ -1,3 +1,14 @@
+2022-01-29  Patrick Griffis  <[email protected]>
+
+        CSP: Properly block image content in object elements
+        https://bugs.webkit.org/show_bug.cgi?id=235837
+
+        Reviewed by Kate Cheney.
+
+        * http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked-expected.txt:
+        * http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked2-expected.txt:
+        * http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked3-expected.txt:
+
 2022-01-29  Tyler Wilcock  <[email protected]>
 
         AX: Isolated tree objects don't update their AXPropertyName::ElementRect or AXPropertyName::BoundingBoxRect in response to dynamic page changes

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked-expected.txt (288791 => 288792)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked-expected.txt	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked-expected.txt	2022-01-29 19:27:59 UTC (rev 288792)
@@ -1,3 +1,3 @@
-CONSOLE MESSAGE: Refused to load http://localhost:8000/security/resources/abe.png because it appears in neither the img-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8000/security/resources/abe.png because it appears in neither the object-src directive nor the default-src directive of the Content Security Policy.
 ALERT: PASS
 This test passes if it doesn't alert FAIL and does alert PASS.

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked2-expected.txt (288791 => 288792)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked2-expected.txt	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked2-expected.txt	2022-01-29 19:27:59 UTC (rev 288792)
@@ -1,3 +1,3 @@
-CONSOLE MESSAGE: Refused to load http://localhost:8000/security/resources/abe.png because it appears in neither the img-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8000/security/resources/abe.png because it appears in neither the object-src directive nor the default-src directive of the Content Security Policy.
 ALERT: PASS
 This test passes if it doesn't alert FAIL and does alert PASS.

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked3-expected.txt (288791 => 288792)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked3-expected.txt	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/userAgentShadowDOM/default-src-object-data-url-blocked3-expected.txt	2022-01-29 19:27:59 UTC (rev 288792)
@@ -1,3 +1,3 @@
-CONSOLE MESSAGE: Refused to load http://localhost:8000/security/resources/abe.png because it appears in neither the img-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8000/security/resources/abe.png because it appears in neither the object-src directive nor the default-src directive of the Content Security Policy.
 ALERT: PASS
 This test passes if it doesn't alert FAIL and does alert PASS.

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (288791 => 288792)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-29 19:27:59 UTC (rev 288792)
@@ -1,3 +1,16 @@
+2022-01-29  Patrick Griffis  <[email protected]>
+
+        CSP: Properly block image content in object elements
+        https://bugs.webkit.org/show_bug.cgi?id=235837
+
+        Reviewed by Kate Cheney.
+
+        Update expectations with more passes.
+
+        * web-platform-tests/content-security-policy/object-src/object-src-url-blocked-expected.txt:
+        * web-platform-tests/content-security-policy/object-src/object-src-url-embed-blocked-expected.txt:
+        * web-platform-tests/content-security-policy/object-src/object-src-url-redirect-blocked.sub-expected.txt:
+
 2022-01-28  Antoine Quint  <[email protected]>
 
         css/css-backgrounds/animations/box-shadow-composition.html has failures

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/object-src/object-src-url-blocked-expected.txt (288791 => 288792)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/object-src/object-src-url-blocked-expected.txt	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/object-src/object-src-url-blocked-expected.txt	2022-01-29 19:27:59 UTC (rev 288792)
@@ -1,6 +1,4 @@
 
 
-Harness Error (TIMEOUT), message = null
+PASS Should block the object and fire a spv
 
-NOTRUN Should block the object and fire a spv
-

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/object-src/object-src-url-embed-blocked-expected.txt (288791 => 288792)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/object-src/object-src-url-embed-blocked-expected.txt	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/object-src/object-src-url-embed-blocked-expected.txt	2022-01-29 19:27:59 UTC (rev 288792)
@@ -1,6 +1,4 @@
 
 
-Harness Error (TIMEOUT), message = null
+PASS Should block the object and fire a spv
 
-NOTRUN Should block the object and fire a spv
-

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/object-src/object-src-url-redirect-blocked.sub-expected.txt (288791 => 288792)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/object-src/object-src-url-redirect-blocked.sub-expected.txt	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/object-src/object-src-url-redirect-blocked.sub-expected.txt	2022-01-29 19:27:59 UTC (rev 288792)
@@ -1,6 +1,3 @@
-Blocked access to external URL http://www1.localhost/content-security-policy/support/pass.png
 
-Harness Error (TIMEOUT), message = null
+PASS Should block the object and fire a spv
 
-NOTRUN Should block the object and fire a spv
-

Modified: trunk/Source/WebCore/ChangeLog (288791 => 288792)


--- trunk/Source/WebCore/ChangeLog	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/Source/WebCore/ChangeLog	2022-01-29 19:27:59 UTC (rev 288792)
@@ -1,3 +1,26 @@
+2022-01-29  Patrick Griffis  <[email protected]>
+
+        CSP: Properly block image content in object elements
+        https://bugs.webkit.org/show_bug.cgi?id=235837
+
+        Reviewed by Kate Cheney.
+
+        When an image is loaded through an object element it now passes through
+        the object-src directive check as the spec documents:
+        https://www.w3.org/TR/CSP3/#directive-object-src
+
+        * loader/ImageLoader.cpp:
+        (WebCore::ImageLoader::updateFromElement):
+        * loader/ResourceLoaderOptions.h:
+        (WebCore::ResourceLoaderOptions::loadedFromPluginElement):
+        (WebCore::ResourceLoaderOptions::ResourceLoaderOptions):
+        (WebCore::ResourceLoaderOptions::loadedFromOpaqueSource): Deleted.
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::allowedByContentSecurityPolicy const):
+        * page/csp/ContentSecurityPolicy.cpp:
+        (WebCore::ContentSecurityPolicy::allowObjectFromSource const):
+        * page/csp/ContentSecurityPolicy.h:
+
 2022-01-29  Tyler Wilcock  <[email protected]>
 
         AX: Isolated tree objects don't update their AXPropertyName::ElementRect or AXPropertyName::BoundingBoxRect in response to dynamic page changes

Modified: trunk/Source/WebCore/loader/ImageLoader.cpp (288791 => 288792)


--- trunk/Source/WebCore/loader/ImageLoader.cpp	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/Source/WebCore/loader/ImageLoader.cpp	2022-01-29 19:27:59 UTC (rev 288792)
@@ -38,6 +38,7 @@
 #include "HTMLNames.h"
 #include "HTMLObjectElement.h"
 #include "HTMLParserIdioms.h"
+#include "HTMLPlugInElement.h"
 #include "InspectorInstrumentation.h"
 #include "JSDOMPromiseDeferred.h"
 #include "LazyLoadImageObserver.h"
@@ -181,6 +182,7 @@
     if (!attr.isNull() && !stripLeadingAndTrailingHTMLSpaces(attr).isEmpty()) {
         ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
         options.contentSecurityPolicyImposition = element().isInUserAgentShadowTree() ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck;
+        options.loadedFromPluginElement = is<HTMLPlugInElement>(element()) ? LoadedFromPluginElement::Yes : LoadedFromPluginElement::No;
         options.sameOriginDataURLFlag = SameOriginDataURLFlag::Set;
         bool isImageElement = is<HTMLImageElement>(element());
         if (isImageElement)

Modified: trunk/Source/WebCore/loader/ResourceLoaderOptions.h (288791 => 288792)


--- trunk/Source/WebCore/loader/ResourceLoaderOptions.h	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/Source/WebCore/loader/ResourceLoaderOptions.h	2022-01-29 19:27:59 UTC (rev 288792)
@@ -147,6 +147,12 @@
 };
 static constexpr unsigned bitWidthOfLoadedFromOpaqueSource = 1;
 
+enum class LoadedFromPluginElement : bool {
+    No,
+    Yes
+};
+static constexpr unsigned bitWidthOfLoadedFromPluginElement = 1;
+
 struct ResourceLoaderOptions : public FetchOptions {
     ResourceLoaderOptions()
         : ResourceLoaderOptions(FetchOptions())
@@ -172,6 +178,7 @@
         , clientCredentialPolicy(ClientCredentialPolicy::CannotAskClientForCredentials)
         , preflightPolicy(PreflightPolicy::Consider)
         , loadedFromOpaqueSource(LoadedFromOpaqueSource::No)
+        , loadedFromPluginElement(LoadedFromPluginElement::No)
     { }
 
     ResourceLoaderOptions(SendCallbackPolicy sendLoadCallbacks, ContentSniffingPolicy sniffContent, DataBufferingPolicy dataBufferingPolicy, StoredCredentialsPolicy storedCredentialsPolicy, ClientCredentialPolicy credentialPolicy, FetchOptions::Credentials credentials, SecurityCheckPolicy securityCheck, FetchOptions::Mode mode, CertificateInfoPolicy certificateInfoPolicy, ContentSecurityPolicyImposition contentSecurityPolicyImposition, DefersLoadingPolicy defersLoadingPolicy, CachingPolicy cachingPolicy)
@@ -192,6 +199,7 @@
         , clientCredentialPolicy(credentialPolicy)
         , preflightPolicy(PreflightPolicy::Consider)
         , loadedFromOpaqueSource(LoadedFromOpaqueSource::No)
+        , loadedFromPluginElement(LoadedFromPluginElement::No)
 
     {
         this->credentials = credentials;
@@ -225,6 +233,7 @@
     ClientCredentialPolicy clientCredentialPolicy : bitWidthOfClientCredentialPolicy;
     PreflightPolicy preflightPolicy : bitWidthOfPreflightPolicy;
     LoadedFromOpaqueSource loadedFromOpaqueSource : bitWidthOfLoadedFromOpaqueSource;
+    LoadedFromPluginElement loadedFromPluginElement : bitWidthOfLoadedFromPluginElement;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (288791 => 288792)


--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2022-01-29 19:27:59 UTC (rev 288792)
@@ -496,6 +496,11 @@
     ASSERT(m_document);
     ASSERT(m_document->contentSecurityPolicy());
 
+    // All content loaded through embed or object elements goes through object-src: https://www.w3.org/TR/CSP3/#directive-object-src.
+    if (options.loadedFromPluginElement == LoadedFromPluginElement::Yes
+        && !m_document->contentSecurityPolicy()->allowObjectFromSource(url, redirectResponseReceived, preRedirectURL))
+        return false;
+
     switch (type) {
 #if ENABLE(XSLT)
     case CachedResource::Type::XSLStyleSheet:

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp (288791 => 288792)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp	2022-01-29 19:27:59 UTC (rev 288792)
@@ -567,7 +567,7 @@
     return allPoliciesAllow(WTFMove(handleViolatedDirective), &ContentSecurityPolicyDirectiveList::violatedDirectiveForPluginType, type, typeAttribute);
 }
 
-bool ContentSecurityPolicy::allowObjectFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived) const
+bool ContentSecurityPolicy::allowObjectFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived, const URL& preRedirectURL) const
 {
     if (LegacySchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol().toStringWithoutCopying()))
         return true;
@@ -576,9 +576,10 @@
     // on the specified type), it MUST be blocked if object-src's value is 'none', but will otherwise be allowed".
     String sourceURL;
     TextPosition sourcePosition(OrdinalNumber::beforeFirst(), OrdinalNumber());
+    const auto& blockedURL = !preRedirectURL.isNull() ? preRedirectURL : url;
     auto handleViolatedDirective = [&] (const ContentSecurityPolicyDirective& violatedDirective) {
         String consoleMessage = consoleMessageForViolation(violatedDirective, url, "Refused to load");
-        reportViolation(violatedDirective, url.string(), consoleMessage, sourceURL, StringView(), sourcePosition);
+        reportViolation(violatedDirective, blockedURL.string(), consoleMessage, sourceURL, StringView(), sourcePosition);
     };
     return allPoliciesAllow(WTFMove(handleViolatedDirective), &ContentSecurityPolicyDirectiveList::violatedDirectiveForObjectSource, url, redirectResponseReceived == RedirectResponseReceived::Yes, ContentSecurityPolicySourceListDirective::ShouldAllowEmptyURLIfSourceListIsNotNone::Yes);
 }

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h (288791 => 288792)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h	2022-01-29 16:43:19 UTC (rev 288791)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h	2022-01-29 19:27:59 UTC (rev 288792)
@@ -127,7 +127,7 @@
     WEBCORE_EXPORT bool allowConnectToSource(const URL&, RedirectResponseReceived = RedirectResponseReceived::No, const URL& requestedURL = URL()) const;
     bool allowFormAction(const URL&, RedirectResponseReceived = RedirectResponseReceived::No, const URL& preRedirectURL = URL()) const;
 
-    bool allowObjectFromSource(const URL&, RedirectResponseReceived = RedirectResponseReceived::No) const;
+    bool allowObjectFromSource(const URL&, RedirectResponseReceived = RedirectResponseReceived::No, const URL& preRedirectURL = URL()) const;
     bool allowBaseURI(const URL&, bool overrideContentSecurityPolicy = false) const;
 
     void setOverrideAllowInlineStyle(bool);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to