Title: [234149] trunk
Revision
234149
Author
[email protected]
Date
2018-07-24 09:29:03 -0700 (Tue, 24 Jul 2018)

Log Message

Cannot view PDF's on my.gov.au: "Refused to load https://my.gov.au/attachment/viewAttachment because it
appears in neither the object-src directive nor the default-src directive of the Content Security Policy"
https://bugs.webkit.org/show_bug.cgi?id=187870
<rdar://problem/41190880>

Reviewed by Dean Jackson.

Source/WebCore:

Fixes an issue where opening attachments on my.gov.au would show a "Blocked Plug-in" message.

Opening an attachment on my.gov.au opens a same-origin plugin document in a child window. Currently
same-origin plugin documents inherit their CSP policy from their opener. If the opener's CSP policy
disallows embedding plugins then the plugin document would be blocked from loading a plugin. For now
we relax the inheritance model such that we only inherit the plugin-types and report-uri directives
from the opener.

Developers that want to block plugin content from being loaded in a same-origin child window must now
serve such plugin content with a CSP policy that includes "object-src 'none'". This matches the behavior
described in the second Note in section object-src of the CSP 3 spec: <https://w3c.github.io/webappsec-csp/#directive-object-src>
(Editor's Draft, 10 July 2018). It also makes the behavior in WebKit more closely aligned with the
behavior of Chrome and Firefox.

Tests: http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window.html
       http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php
       http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window.html

* dom/Document.cpp:
(WebCore::Document::initContentSecurityPolicy): For plugin documents that have an opener call ContentSecurityPolicy::createPolicyForPluginDocumentFrom()
to only inherit the plugin-types and report-uri directives from its opener's CSP policy. Otherwise, call ContentSecurityPolicy::copyStateFrom()
to inherit all directives from the owner frame as we do now.
* page/csp/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::createPolicyForPluginDocumentFrom): Create a new policy from the specified policy
inheriting only the plugin-types and report-uri directives.
* page/csp/ContentSecurityPolicy.h: Define a new PolicyFrom enumerator, InheritedForPluginDocument, for plugin documents
loaded in a child window.
* page/csp/ContentSecurityPolicyDirectiveList.cpp:
(WebCore::ContentSecurityPolicyDirectiveList::parse): When policyFrom is InheritedForPluginDocument then only
recognize the plugin-types and report-uri directives when parsing the policy.

LayoutTests:

Add new tests and fix up the existing test http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window.html
so that still tests a scenario where a same-origin plugin document loaded in a child window is blocked from
loading its plugin now that that "object-src: 'none'" is no longer inherited by the plugin document.

* http/tests/plugins/resources/plugin-document-alert-and-notify-done.pl:
* http/tests/security/contentSecurityPolicy/resources/checkDidSameOriginChildWindowLoad.js: Added.
(checkDidSameOriginChildWindowLoadAndNotifyDone):
(checkDidLoad):
* http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window.html: Added.
* http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-expected.txt:
* http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php: Added.
* http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window.html:
* http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window.html: Added.
* platform/ios/TestExpectations: Skip the included tests as we do not support plugins on iOS.
* platform/win/TestExpectations: Skip the included tests as plugins do not seem to work on Windows. We currently skip many
(if not all) plugin tests on Windows despite <rdar://problem/5074411> being marked as Closed (why?).

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (234148 => 234149)


--- trunk/LayoutTests/ChangeLog	2018-07-24 16:27:25 UTC (rev 234148)
+++ trunk/LayoutTests/ChangeLog	2018-07-24 16:29:03 UTC (rev 234149)
@@ -1,3 +1,32 @@
+2018-07-24  Daniel Bates  <[email protected]>
+
+        Cannot view PDF's on my.gov.au: "Refused to load https://my.gov.au/attachment/viewAttachment because it
+        appears in neither the object-src directive nor the default-src directive of the Content Security Policy"
+        https://bugs.webkit.org/show_bug.cgi?id=187870
+        <rdar://problem/41190880>
+
+        Reviewed by Dean Jackson.
+
+        Add new tests and fix up the existing test http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window.html
+        so that still tests a scenario where a same-origin plugin document loaded in a child window is blocked from
+        loading its plugin now that that "object-src: 'none'" is no longer inherited by the plugin document.
+
+        * http/tests/plugins/resources/plugin-document-alert-and-notify-done.pl:
+        * http/tests/security/contentSecurityPolicy/resources/checkDidSameOriginChildWindowLoad.js: Added.
+        (checkDidSameOriginChildWindowLoadAndNotifyDone):
+        (checkDidLoad):
+        * http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window.html: Added.
+        * http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-expected.txt:
+        * http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php: Added.
+        * http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window.html:
+        * http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window.html: Added.
+        * platform/ios/TestExpectations: Skip the included tests as we do not support plugins on iOS.
+        * platform/win/TestExpectations: Skip the included tests as plugins do not seem to work on Windows. We currently skip many
+        (if not all) plugin tests on Windows despite <rdar://problem/5074411> being marked as Closed (why?). 
+
 2018-07-24  Zan Dobersek  <[email protected]>
 
         Unreviewed WPE gardening.

Modified: trunk/LayoutTests/http/tests/plugins/resources/plugin-document-alert-and-notify-done.pl (234148 => 234149)


--- trunk/LayoutTests/http/tests/plugins/resources/plugin-document-alert-and-notify-done.pl	2018-07-24 16:27:25 UTC (rev 234148)
+++ trunk/LayoutTests/http/tests/plugins/resources/plugin-document-alert-and-notify-done.pl	2018-07-24 16:29:03 UTC (rev 234149)
@@ -1,7 +1,13 @@
 #!/usr/bin/perl -wT
 use strict;
 
+use CGI;
+
+my $cgi = new CGI;
+
 # Do not rename this file. The TestNetscapePlugin is hardcoded to look for this filename
 # to trigger a _javascript_ alert and call testRunner.notifyDone().
-print "Content-Type: application/x-webkit-test-netscape\n\n";
+print "Content-Type: application/x-webkit-test-netscape\n";
+print $cgi->param("additionalHeader") . "\n" if $cgi->param("additionalHeader");
+print "\n";
 print "This is a mock plugin. It alerts when loaded and calls testRunner.notifyDone()";

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/resources/checkDidSameOriginChildWindowLoad.js (0 => 234149)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/resources/checkDidSameOriginChildWindowLoad.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/resources/checkDidSameOriginChildWindowLoad.js	2018-07-24 16:29:03 UTC (rev 234149)
@@ -0,0 +1,19 @@
+function checkDidSameOriginChildWindowLoadAndNotifyDone(childWindow)
+{
+    checkDidSameOriginChildWindowLoad(childWindow, () => {
+        if (window.testRunner)
+            testRunner.notifyDone();
+    });
+}
+
+function checkDidSameOriginChildWindowLoad(childWindow, callback)
+{
+    function checkDidLoad() {
+        if (childWindow.document.location.origin !== document.location.origin)
+            return;
+        // Child window did load
+        window.clearInterval(intervalID);
+        callback()
+    }
+    intervalID = window.setInterval(checkDidLoad, 10);
+}

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window-expected.txt (0 => 234149)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window-expected.txt	2018-07-24 16:29:03 UTC (rev 234149)
@@ -0,0 +1,2 @@
+ALERT: Plugin Loaded!
+

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window.html (0 => 234149)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window.html	2018-07-24 16:29:03 UTC (rev 234149)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; object-src 'none'">
+<script src=""
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.setCanOpenWindows();
+    testRunner.setCloseRemainingWindowsWhenComplete(true);
+    testRunner.waitUntilDone();
+}
+</script>
+</head>
+<body>
+<script>
+checkDidSameOriginChildWindowLoadAndNotifyDone(window.open("http://127.0.0.1:8000/plugins/resources/plugin-document-alert-and-notify-done.pl"));
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-expected.txt (234148 => 234149)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-expected.txt	2018-07-24 16:27:25 UTC (rev 234148)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-expected.txt	2018-07-24 16:29:03 UTC (rev 234149)
@@ -1,2 +1,2 @@
-CONSOLE MESSAGE: Refused to load http://127.0.0.1:8000/plugins/resources/plugin-document-alert-and-notify-done.pl because it does not appear in the object-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://127.0.0.1:8000/plugins/resources/plugin-document-alert-and-notify-done.pl because its MIME type does not appear in the plugin-types directive of the Content Security Policy.
 

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report-expected.txt (0 => 234149)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report-expected.txt	2018-07-24 16:29:03 UTC (rev 234149)
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: Refused to load http://127.0.0.1:8000/plugins/resources/mock-plugin.pl because its MIME type does not appear in the plugin-types directive of the Content Security Policy.
+CSP report received:
+CONTENT_TYPE: application/csp-report
+HTTP_HOST: 127.0.0.1:8000
+HTTP_REFERER: http://127.0.0.1:8000/plugins/resources/mock-plugin.pl
+REQUEST_METHOD: POST
+REQUEST_URI: /security/contentSecurityPolicy/resources/save-report.php?test=/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php
+=== POST DATA =""
+{"csp-report":{"document-uri":"http://127.0.0.1:8000/plugins/resources/mock-plugin.pl","referrer":"http://127.0.0.1:8000/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php","violated-directive":"plugin-types application/x-webkit-dummy-plugin","effective-directive":"plugin-types","original-policy":"script-src 'self' 'unsafe-inline'; plugin-types application/x-webkit-dummy-plugin; report-uri /security/contentSecurityPolicy/resources/save-report.php?test=/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php","blocked-uri":"http://127.0.0.1:8000/plugins/resources/mock-plugin.pl","status-code":200}}

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php (0 => 234149)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php	2018-07-24 16:29:03 UTC (rev 234149)
@@ -0,0 +1,27 @@
+<?php
+    header("Content-Security-Policy: script-src 'self' 'unsafe-inline'; plugin-types application/x-webkit-dummy-plugin; report-uri /security/contentSecurityPolicy/resources/save-report.php?test=/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php");
+?>
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.setCanOpenWindows();
+    testRunner.setCloseRemainingWindowsWhenComplete(true);
+    testRunner.waitUntilDone();
+}
+</script>
+</head>
+<body>
+<script>
+function navigateToCSPReport()
+{
+    window.location.href = ""
+}
+
+checkDidSameOriginChildWindowLoad(window.open("http://127.0.0.1:8000/plugins/resources/mock-plugin.pl"), navigateToCSPReport);
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window.html (234148 => 234149)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window.html	2018-07-24 16:27:25 UTC (rev 234148)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window.html	2018-07-24 16:29:03 UTC (rev 234149)
@@ -1,7 +1,8 @@
 <!DOCTYPE html>
 <html>
 <head>
-<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; object-src 'none'">
+<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; plugin-types application/x-webkit-dummy-plugin">
+<script src=""
 <script>
 if (window.testRunner) {
     testRunner.dumpAsText();
@@ -13,21 +14,7 @@
 </head>
 <body>
 <script>
-checkDidLoadAndNotifyDone(window.open("http://127.0.0.1:8000/plugins/resources/plugin-document-alert-and-notify-done.pl"));
-
-// Assumes that the specified window is loading a same-origin document.
-function checkDidLoadAndNotifyDone(childWindow)
-{
-    function checkDidLoad() {
-        if (childWindow.document.location.origin !== document.location.origin)
-            return;
-        // Child window did load
-        window.clearInterval(intervalID);
-        if (window.testRunner)
-            testRunner.notifyDone();
-    }
-    intervalID = window.setInterval(checkDidLoad, 10);
-}
+checkDidSameOriginChildWindowLoadAndNotifyDone(window.open("http://127.0.0.1:8000/plugins/resources/plugin-document-alert-and-notify-done.pl"));
 </script>
 </body>
 </html>

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window-expected.txt (0 => 234149)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window-expected.txt	2018-07-24 16:29:03 UTC (rev 234149)
@@ -0,0 +1,2 @@
+CONSOLE MESSAGE: Refused to load http://127.0.0.1:8000/plugins/resources/plugin-document-alert-and-notify-done.pl?additionalHeader=Content-Security-Policy%3A+object-src+%27none%27 because it does not appear in the object-src directive of the Content Security Policy.
+

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window.html (0 => 234149)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window.html	2018-07-24 16:29:03 UTC (rev 234149)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; object-src 'none'">
+<script src=""
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.setCanOpenWindows();
+    testRunner.setCloseRemainingWindowsWhenComplete(true);
+    testRunner.waitUntilDone();
+}
+</script>
+</head>
+<body>
+<script>
+checkDidSameOriginChildWindowLoadAndNotifyDone(window.open("http://127.0.0.1:8000/plugins/resources/plugin-document-alert-and-notify-done.pl?additionalHeader=Content-Security-Policy%3A+object-src+%27none%27"));
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/ios/TestExpectations (234148 => 234149)


--- trunk/LayoutTests/platform/ios/TestExpectations	2018-07-24 16:27:25 UTC (rev 234148)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2018-07-24 16:29:03 UTC (rev 234149)
@@ -155,7 +155,10 @@
 http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-plugin-in-main-frame.html
 http/tests/security/contentSecurityPolicy/cross-origin-plugin-document-allowed-in-child-window.html
 http/tests/security/contentSecurityPolicy/plugin-blocked-in-about-blank-window.html
+http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window.html
 http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window.html
+http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php
+http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window.html
 
 # Pointer-lock not supported on iOS
 pointer-lock

Modified: trunk/LayoutTests/platform/win/TestExpectations (234148 => 234149)


--- trunk/LayoutTests/platform/win/TestExpectations	2018-07-24 16:27:25 UTC (rev 234148)
+++ trunk/LayoutTests/platform/win/TestExpectations	2018-07-24 16:29:03 UTC (rev 234149)
@@ -737,6 +737,11 @@
 webkit.org/b/117323 fast/frames/sandboxed-iframe-plugins.html [ Skip ]
 webkit.org/b/117323 platform/win/plugins/call-_javascript_-that-destroys-plugin.html [ Skip ]
 webkit.org/b/117323 platform/win/plugins/windowless-paint-rect-coordinates.html [ Skip ]
+
+http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window.html [ Skip ]
+http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php [ Skip ]
+http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window.html [ Skip ]
+
 ################################################################################
 ############################   End Plugin Failures   ###########################
 ################################################################################

Modified: trunk/Source/WebCore/ChangeLog (234148 => 234149)


--- trunk/Source/WebCore/ChangeLog	2018-07-24 16:27:25 UTC (rev 234148)
+++ trunk/Source/WebCore/ChangeLog	2018-07-24 16:29:03 UTC (rev 234149)
@@ -1,5 +1,45 @@
 2018-07-24  Daniel Bates  <[email protected]>
 
+        Cannot view PDF's on my.gov.au: "Refused to load https://my.gov.au/attachment/viewAttachment because it
+        appears in neither the object-src directive nor the default-src directive of the Content Security Policy"
+        https://bugs.webkit.org/show_bug.cgi?id=187870
+        <rdar://problem/41190880>
+
+        Reviewed by Dean Jackson.
+
+        Fixes an issue where opening attachments on my.gov.au would show a "Blocked Plug-in" message.
+
+        Opening an attachment on my.gov.au opens a same-origin plugin document in a child window. Currently
+        same-origin plugin documents inherit their CSP policy from their opener. If the opener's CSP policy
+        disallows embedding plugins then the plugin document would be blocked from loading a plugin. For now
+        we relax the inheritance model such that we only inherit the plugin-types and report-uri directives
+        from the opener.
+
+        Developers that want to block plugin content from being loaded in a same-origin child window must now
+        serve such plugin content with a CSP policy that includes "object-src 'none'". This matches the behavior
+        described in the second Note in section object-src of the CSP 3 spec: <https://w3c.github.io/webappsec-csp/#directive-object-src>
+        (Editor's Draft, 10 July 2018). It also makes the behavior in WebKit more closely aligned with the
+        behavior of Chrome and Firefox.
+
+        Tests: http/tests/security/contentSecurityPolicy/same-origin-plugin-document-allowed-in-child-window.html
+               http/tests/security/contentSecurityPolicy/same-origin-plugin-document-blocked-in-child-window-report.php
+               http/tests/security/contentSecurityPolicy/same-origin-plugin-document-with-csp-blocked-in-child-window.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::initContentSecurityPolicy): For plugin documents that have an opener call ContentSecurityPolicy::createPolicyForPluginDocumentFrom()
+        to only inherit the plugin-types and report-uri directives from its opener's CSP policy. Otherwise, call ContentSecurityPolicy::copyStateFrom()
+        to inherit all directives from the owner frame as we do now.
+        * page/csp/ContentSecurityPolicy.cpp:
+        (WebCore::ContentSecurityPolicy::createPolicyForPluginDocumentFrom): Create a new policy from the specified policy
+        inheriting only the plugin-types and report-uri directives.
+        * page/csp/ContentSecurityPolicy.h: Define a new PolicyFrom enumerator, InheritedForPluginDocument, for plugin documents
+        loaded in a child window.
+        * page/csp/ContentSecurityPolicyDirectiveList.cpp:
+        (WebCore::ContentSecurityPolicyDirectiveList::parse): When policyFrom is InheritedForPluginDocument then only
+        recognize the plugin-types and report-uri directives when parsing the policy.
+
+2018-07-24  Daniel Bates  <[email protected]>
+
         Rename Document::firstPartyForSameSiteCookies() to siteForCookies()
         https://bugs.webkit.org/show_bug.cgi?id=187892
 

Modified: trunk/Source/WebCore/dom/Document.cpp (234148 => 234149)


--- trunk/Source/WebCore/dom/Document.cpp	2018-07-24 16:27:25 UTC (rev 234148)
+++ trunk/Source/WebCore/dom/Document.cpp	2018-07-24 16:29:03 UTC (rev 234149)
@@ -5669,7 +5669,7 @@
     if (parentFrame)
         contentSecurityPolicy()->copyUpgradeInsecureRequestStateFrom(*parentFrame->document()->contentSecurityPolicy());
 
-    // 2. Inherit Content Security Policy
+    // 2. Inherit Content Security Policy (without copying Upgrade Insecure Requests state).
     if (!shouldInheritContentSecurityPolicyFromOwner())
         return;
     Frame* ownerFrame = parentFrame;
@@ -5677,7 +5677,12 @@
         ownerFrame = m_frame->loader().opener();
     if (!ownerFrame)
         return;
-    contentSecurityPolicy()->copyStateFrom(ownerFrame->document()->contentSecurityPolicy()); // Does not copy Upgrade Insecure Requests state.
+    // FIXME: The CSP 3 spec. implies that only plugin documents delivered with a local scheme (e.g. blob, file, data)
+    // should inherit a policy.
+    if (isPluginDocument() && m_frame->loader().opener())
+        contentSecurityPolicy()->createPolicyForPluginDocumentFrom(*ownerFrame->document()->contentSecurityPolicy());
+    else
+        contentSecurityPolicy()->copyStateFrom(ownerFrame->document()->contentSecurityPolicy());
 }
 
 bool Document::isContextThread() const

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp (234148 => 234149)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp	2018-07-24 16:27:25 UTC (rev 234148)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp	2018-07-24 16:29:03 UTC (rev 234149)
@@ -117,6 +117,17 @@
     m_httpStatusCode = other->m_httpStatusCode;
 }
 
+void ContentSecurityPolicy::createPolicyForPluginDocumentFrom(const ContentSecurityPolicy& other)
+{
+    if (m_hasAPIPolicy)
+        return;
+    ASSERT(m_policies.isEmpty());
+    for (auto& policy : other.m_policies)
+        didReceiveHeader(policy->header(), policy->headerType(), ContentSecurityPolicy::PolicyFrom::InheritedForPluginDocument, String { });
+    m_referrer = other.m_referrer;
+    m_httpStatusCode = other.m_httpStatusCode;
+}
+
 void ContentSecurityPolicy::copyUpgradeInsecureRequestStateFrom(const ContentSecurityPolicy& other)
 {
     m_upgradeInsecureRequests = other.m_upgradeInsecureRequests;

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h (234148 => 234149)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h	2018-07-24 16:27:25 UTC (rev 234148)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h	2018-07-24 16:29:03 UTC (rev 234149)
@@ -70,6 +70,7 @@
 
     void copyStateFrom(const ContentSecurityPolicy*);
     void copyUpgradeInsecureRequestStateFrom(const ContentSecurityPolicy&);
+    void createPolicyForPluginDocumentFrom(const ContentSecurityPolicy&);
 
     void didCreateWindowProxy(JSWindowProxy&) const;
 
@@ -78,6 +79,7 @@
         HTTPEquivMeta,
         HTTPHeader,
         Inherited,
+        InheritedForPluginDocument,
     };
     WEBCORE_EXPORT ContentSecurityPolicyResponseHeaders responseHeaders() const;
     enum ReportParsingErrors { No, Yes };

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp (234148 => 234149)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp	2018-07-24 16:27:25 UTC (rev 234148)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp	2018-07-24 16:29:03 UTC (rev 234149)
@@ -354,6 +354,10 @@
                     m_policy.reportInvalidDirectiveInHTTPEquivMeta(name);
                     continue;
                 }
+            } else if (policyFrom == ContentSecurityPolicy::PolicyFrom::InheritedForPluginDocument) {
+                if (!equalIgnoringASCIICase(name, ContentSecurityPolicyDirectiveNames::pluginTypes)
+                    && !equalIgnoringASCIICase(name, ContentSecurityPolicyDirectiveNames::reportURI))
+                    continue;
             }
             addDirective(name, value);
         }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to