Title: [286363] trunk
Revision
286363
Author
[email protected]
Date
2021-12-01 08:41:12 -0800 (Wed, 01 Dec 2021)

Log Message

CSP: Update URL stripping in reports to match other implementations
https://bugs.webkit.org/show_bug.cgi?id=233135

Reviewed by Kate Cheney.

LayoutTests/imported/w3c:

Update tests as passing.

* web-platform-tests/content-security-policy/generic/directive-name-case-insensitive.sub-expected.txt:
* web-platform-tests/content-security-policy/media-src/media-src-7_1_2.sub-expected.txt:
* web-platform-tests/content-security-policy/media-src/media-src-7_2_2.sub-expected.txt:
* web-platform-tests/content-security-policy/media-src/media-src-blocked.sub-expected.txt:
* web-platform-tests/content-security-policy/reporting/report-original-url.sub-expected.txt:
* web-platform-tests/content-security-policy/reporting/report-strips-fragment-expected.txt:
* web-platform-tests/content-security-policy/securitypolicyviolation/securitypolicyviolation-block-cross-origin-image.sub-expected.txt:

Source/WebCore:

* page/csp/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::createURLForReporting const):
(WebCore::ContentSecurityPolicy::reportViolation const):
(WebCore::ContentSecurityPolicy::deprecatedURLForReporting const): Deleted.
* page/csp/ContentSecurityPolicy.h:

LayoutTests:

Remove skipped tests that now pass. Change CSP tests to expect full URLs.

* TestExpectations:
* http/tests/security/contentSecurityPolicy/1.1/script-blocked-sends-multiple-reports-expected.txt:
* http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-expected.txt:
* http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-from-script-expected.txt:
* http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-from-script.html:
* http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image.html:
* http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-image-https-expected.txt:
* http/tests/security/contentSecurityPolicy/report-blocked-uri-cross-origin-expected.txt:
* http/wpt/fetch/csp-reports-bypass-csp-checks.html:
* platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_1_2.sub-expected.txt: Added.
* platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_2_2.sub-expected.txt: Added.
* platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-blocked.sub-expected.txt: Added.
* platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-redir-bug.sub-expected.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (286362 => 286363)


--- trunk/LayoutTests/ChangeLog	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/ChangeLog	2021-12-01 16:41:12 UTC (rev 286363)
@@ -1,3 +1,26 @@
+2021-12-01  Patrick Griffis  <[email protected]>
+
+        CSP: Update URL stripping in reports to match other implementations
+        https://bugs.webkit.org/show_bug.cgi?id=233135
+
+        Reviewed by Kate Cheney.
+
+        Remove skipped tests that now pass. Change CSP tests to expect full URLs.
+
+        * TestExpectations:
+        * http/tests/security/contentSecurityPolicy/1.1/script-blocked-sends-multiple-reports-expected.txt:
+        * http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-expected.txt:
+        * http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-from-script-expected.txt:
+        * http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-from-script.html:
+        * http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image.html:
+        * http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-image-https-expected.txt:
+        * http/tests/security/contentSecurityPolicy/report-blocked-uri-cross-origin-expected.txt:
+        * http/wpt/fetch/csp-reports-bypass-csp-checks.html:
+        * platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_1_2.sub-expected.txt: Added.
+        * platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_2_2.sub-expected.txt: Added.
+        * platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-blocked.sub-expected.txt: Added.
+        * platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-redir-bug.sub-expected.txt:
+
 2021-12-01  Andreu Botella  <[email protected]>
 
         imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/multipart-formdata.window.html is no longer failing – remove expectations

Modified: trunk/LayoutTests/TestExpectations (286362 => 286363)


--- trunk/LayoutTests/TestExpectations	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/TestExpectations	2021-12-01 16:41:12 UTC (rev 286363)
@@ -949,7 +949,6 @@
 imported/w3c/web-platform-tests/content-security-policy/style-src/style-src-inline-style-nonce-blocked-error-event.html [ Skip ]
 imported/w3c/web-platform-tests/content-security-policy/securitypolicyviolation/inside-dedicated-worker.html [ Skip ]
 imported/w3c/web-platform-tests/content-security-policy/securitypolicyviolation/img-src-redirect-upgrade-reporting.https.html [ Skip ]
-imported/w3c/web-platform-tests/content-security-policy/reporting/report-strips-fragment.html [ Skip ]
 imported/w3c/web-platform-tests/content-security-policy/reporting/report-original-url.sub.html [ Skip ]
 imported/w3c/web-platform-tests/content-security-policy/prefetch-src/prefetch-header-blocked.html [ Skip ]
 imported/w3c/web-platform-tests/content-security-policy/prefetch-src/prefetch-header-allowed.html [ Skip ]

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/script-blocked-sends-multiple-reports-expected.txt (286362 => 286363)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/script-blocked-sends-multiple-reports-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/script-blocked-sends-multiple-reports-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -13,7 +13,7 @@
 REQUEST_METHOD: POST
 REQUEST_URI: /security/contentSecurityPolicy/resources/save-report.py?test=script-blocked-sends-multiple-reports-report-only
 === POST DATA =""
-{"csp-report":{"document-uri":"http://127.0.0.1:8000/security/contentSecurityPolicy/1.1/script-blocked-sends-multiple-reports.py","referrer":"","violated-directive":"script-src-elem","effective-directive":"script-src","original-policy":"script-src http://example.com 'unsafe-inline'; report-uri ../resources/save-report.py?test=script-blocked-sends-multiple-reports-report-only","blocked-uri":"http://localhost:8000","status-code":200}}
+{"csp-report":{"document-uri":"http://127.0.0.1:8000/security/contentSecurityPolicy/1.1/script-blocked-sends-multiple-reports.py","referrer":"","violated-directive":"script-src-elem","effective-directive":"script-src","original-policy":"script-src http://example.com 'unsafe-inline'; report-uri ../resources/save-report.py?test=script-blocked-sends-multiple-reports-report-only","blocked-uri":"http://localhost:8000/security/contentSecurityPolicy/resources/alert-fail.js","status-code":200}}
 
 --------
 Frame: 'enforced-1'
@@ -25,7 +25,7 @@
 REQUEST_METHOD: POST
 REQUEST_URI: /security/contentSecurityPolicy/resources/save-report.py?test=script-blocked-sends-multiple-reports-enforced-1
 === POST DATA =""
-{"csp-report":{"document-uri":"http://127.0.0.1:8000/security/contentSecurityPolicy/1.1/script-blocked-sends-multiple-reports.py","referrer":"","violated-directive":"script-src-elem","effective-directive":"script-src","original-policy":"script-src http://127.0.0.1:8000 'unsafe-inline'; report-uri ../resources/save-report.py?test=script-blocked-sends-multiple-reports-enforced-1","blocked-uri":"http://localhost:8000","status-code":200}}
+{"csp-report":{"document-uri":"http://127.0.0.1:8000/security/contentSecurityPolicy/1.1/script-blocked-sends-multiple-reports.py","referrer":"","violated-directive":"script-src-elem","effective-directive":"script-src","original-policy":"script-src http://127.0.0.1:8000 'unsafe-inline'; report-uri ../resources/save-report.py?test=script-blocked-sends-multiple-reports-enforced-1","blocked-uri":"http://localhost:8000/security/contentSecurityPolicy/resources/alert-fail.js","status-code":200}}
 
 --------
 Frame: 'enforced-2'
@@ -37,4 +37,4 @@
 REQUEST_METHOD: POST
 REQUEST_URI: /security/contentSecurityPolicy/resources/save-report.py?test=script-blocked-sends-multiple-reports-enforced-2
 === POST DATA =""
-{"csp-report":{"document-uri":"http://127.0.0.1:8000/security/contentSecurityPolicy/1.1/script-blocked-sends-multiple-reports.py","referrer":"","violated-directive":"script-src-elem","effective-directive":"script-src","original-policy":" script-src http://127.0.0.1:8000 https://127.0.0.1:8443 'unsafe-inline'; report-uri ../resources/save-report.py?test=script-blocked-sends-multiple-reports-enforced-2","blocked-uri":"http://localhost:8000","status-code":200}}
+{"csp-report":{"document-uri":"http://127.0.0.1:8000/security/contentSecurityPolicy/1.1/script-blocked-sends-multiple-reports.py","referrer":"","violated-directive":"script-src-elem","effective-directive":"script-src","original-policy":" script-src http://127.0.0.1:8000 https://127.0.0.1:8443 'unsafe-inline'; report-uri ../resources/save-report.py?test=script-blocked-sends-multiple-reports-enforced-2","blocked-uri":"http://localhost:8000/security/contentSecurityPolicy/resources/alert-fail.js","status-code":200}}

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-expected.txt (286362 => 286363)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -7,7 +7,7 @@
 Kicking off the tests:
 PASS window.e.documentURI is "http://127.0.0.1:8000/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image.html"
 PASS window.e.referrer is ""
-PASS window.e.blockedURI is "http://localhost:8000"
+PASS window.e.blockedURI is "http://localhost:8000/security/resources/abe.png"
 PASS window.e.violatedDirective is "img-src"
 PASS window.e.effectiveDirective is "img-src"
 PASS window.e.originalPolicy is "img-src 'none'"

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-from-script-expected.txt (286362 => 286363)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-from-script-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-from-script-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -11,7 +11,7 @@
 PASS window.e.violatedDirective is "img-src"
 PASS window.e.effectiveDirective is "img-src"
 PASS window.e.originalPolicy is "img-src 'none'"
-PASS window.e.sourceFile is "http://localhost:8000"
+PASS window.e.sourceFile is "http://localhost:8000/security/contentSecurityPolicy/resources/inject-image.js"
 PASS window.e.lineNumber is 3
 PASS window.e.columnNumber is 2
 PASS window.e.statusCode is 200

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-from-script.html (286362 => 286363)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-from-script.html	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image-from-script.html	2021-12-01 16:41:12 UTC (rev 286363)
@@ -14,7 +14,7 @@
             'violatedDirective': 'img-src',
             'effectiveDirective': 'img-src',
             'originalPolicy': 'img-src \'none\'',
-            'sourceFile': 'http://localhost:8000',
+            'sourceFile': 'http://localhost:8000/security/contentSecurityPolicy/resources/inject-image.js',
             'lineNumber': 3,
             'columnNumber': 2,
             'statusCode': 200,

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image.html (286362 => 286363)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image.html	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-cross-origin-image.html	2021-12-01 16:41:12 UTC (rev 286363)
@@ -10,7 +10,7 @@
         var expectations = {
             'documentURI': document.location.toString(),
             'referrer': document.referrer,
-            'blockedURI': 'http://localhost:8000',
+            'blockedURI': 'http://localhost:8000/security/resources/abe.png',
             'violatedDirective': 'img-src',
             'effectiveDirective': 'img-src',
             'originalPolicy': 'img-src \'none\'',

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-image-https-expected.txt (286362 => 286363)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-image-https-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-image-https-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -12,7 +12,7 @@
 Kicking off the tests:
 PASS window.e.documentURI is "https://127.0.0.1:8443/security/contentSecurityPolicy/1.1/securitypolicyviolation-block-image.html"
 PASS window.e.referrer is "http://127.0.0.1:8000/"
-FAIL window.e.blockedURI should be http://127.0.0.1:8000/security/resources/abe.png. Was http://127.0.0.1:8000.
+PASS window.e.blockedURI is "http://127.0.0.1:8000/security/resources/abe.png"
 PASS window.e.violatedDirective is "img-src"
 PASS window.e.effectiveDirective is "img-src"
 PASS window.e.originalPolicy is "img-src 'none'"

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-blocked-uri-cross-origin-expected.txt (286362 => 286363)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-blocked-uri-cross-origin-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-blocked-uri-cross-origin-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -6,4 +6,4 @@
 REQUEST_METHOD: POST
 REQUEST_URI: /security/contentSecurityPolicy/resources/save-report.py
 === POST DATA =""
-{"csp-report":{"document-uri":"http://127.0.0.1:8000/security/contentSecurityPolicy/report-blocked-uri-cross-origin.py","referrer":"","violated-directive":"img-src","effective-directive":"img-src","original-policy":"img-src 'none'; report-uri resources/save-report.py","blocked-uri":"http://localhost:8080","status-code":200}}
+{"csp-report":{"document-uri":"http://127.0.0.1:8000/security/contentSecurityPolicy/report-blocked-uri-cross-origin.py","referrer":"","violated-directive":"img-src","effective-directive":"img-src","original-policy":"img-src 'none'; report-uri resources/save-report.py","blocked-uri":"http://localhost:8080/security/resources/abe.png","status-code":200}}

Modified: trunk/LayoutTests/http/wpt/fetch/csp-reports-bypass-csp-checks.html (286362 => 286363)


--- trunk/LayoutTests/http/wpt/fetch/csp-reports-bypass-csp-checks.html	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/http/wpt/fetch/csp-reports-bypass-csp-checks.html	2021-12-01 16:41:12 UTC (rev 286363)
@@ -19,7 +19,7 @@
     let results = JSON.parse(text);
     const report = results["csp-report"];
     if (report["effective-directive"] === "connect-src") {
-        assert_equals(report["blocked-uri"], "http://localhost:8888");
+        assert_equals(report["blocked-uri"], "http://localhost:8888/test");
         done();
     }
 });

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (286362 => 286363)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-12-01 16:41:12 UTC (rev 286363)
@@ -1,3 +1,20 @@
+2021-12-01  Patrick Griffis  <[email protected]>
+
+        CSP: Update URL stripping in reports to match other implementations
+        https://bugs.webkit.org/show_bug.cgi?id=233135
+
+        Reviewed by Kate Cheney.
+
+        Update tests as passing.
+
+        * web-platform-tests/content-security-policy/generic/directive-name-case-insensitive.sub-expected.txt:
+        * web-platform-tests/content-security-policy/media-src/media-src-7_1_2.sub-expected.txt:
+        * web-platform-tests/content-security-policy/media-src/media-src-7_2_2.sub-expected.txt:
+        * web-platform-tests/content-security-policy/media-src/media-src-blocked.sub-expected.txt:
+        * web-platform-tests/content-security-policy/reporting/report-original-url.sub-expected.txt:
+        * web-platform-tests/content-security-policy/reporting/report-strips-fragment-expected.txt:
+        * web-platform-tests/content-security-policy/securitypolicyviolation/securitypolicyviolation-block-cross-origin-image.sub-expected.txt:
+
 2021-12-01  Andreu Botella  <[email protected]>
 
         imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/multipart-formdata.window.html is no longer failing – remove expectations

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/generic/directive-name-case-insensitive.sub-expected.txt (286362 => 286363)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/generic/directive-name-case-insensitive.sub-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/generic/directive-name-case-insensitive.sub-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -4,5 +4,5 @@
 
 FAIL Test that the www1 image is allowed to load assert_unreached: www1 image should have loaded Reached unreachable code
 PASS Test that the www2 image is not allowed to load
-FAIL Test that the www2 image throws a violation event assert_equals: expected "http://www2.localhost:8800/content-security-policy/support/fail.png" but got "http://www2.localhost:8800"
+PASS Test that the www2 image throws a violation event
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_1_2.sub-expected.txt (286362 => 286363)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_1_2.sub-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_1_2.sub-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -1,7 +1,9 @@
 Video element src attribute must match src list - negative test
 
 
+Harness Error (TIMEOUT), message = null
+
 PASS Disallowed async video src
 PASS Disallowed async video source element
-FAIL Test that securitypolicyviolation events are fired assert_equals: expected "http://www2.localhost:8800/media/A4.ogv" but got "http://www2.localhost:8800"
+TIMEOUT Test that securitypolicyviolation events are fired Test timed out
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_2_2.sub-expected.txt (286362 => 286363)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_2_2.sub-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_2_2.sub-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -1,7 +1,9 @@
 Audio element src attribute must match src list - negative test
 
 
+Harness Error (TIMEOUT), message = null
+
 PASS Disallaowed audio src
 PASS Disallowed audio source element
-FAIL Test that securitypolicyviolation events are fired assert_equals: expected "http://www2.localhost:8800/media/sound_5.oga" but got "http://www2.localhost:8800"
+TIMEOUT Test that securitypolicyviolation events are fired Test timed out
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-blocked.sub-expected.txt (286362 => 286363)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-blocked.sub-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-blocked.sub-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -1,9 +1,11 @@
 Video element src attribute must match src list - 'none' negative test
 
 
+Harness Error (TIMEOUT), message = null
+
 PASS Disallowed async video src
 PASS Disallowed async video source element
 PASS Disallaowed audio src
 PASS Disallowed audio source element
-FAIL Test that securitypolicyviolation events are fired assert_true: Unexpected blockedURI expected true got false
+TIMEOUT Test that securitypolicyviolation events are fired Test timed out
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/reporting/report-original-url.sub-expected.txt (286362 => 286363)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/reporting/report-original-url.sub-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/reporting/report-original-url.sub-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -1,5 +1,3 @@
-CONSOLE MESSAGE: Refused to load http://localhost:8800/content-security-policy/support/fail.png?t=1 because it does not appear in the img-src directive of the Content Security Policy.
-CONSOLE MESSAGE: Refused to load http://www2.localhost:8800/content-security-policy/support/fail.png?t=2 because it does not appear in the img-src directive of the Content Security Policy.
 Blocked access to external URL http://www1.localhost:8800/common/redirect.py?location=http%3A%2F%2Flocalhost%3A8800%2Fcontent-security-policy%2Fsupport%2Ffail.png%3Ft%3D3
 Blocked access to external URL http://www1.localhost:8800/common/redirect.py?location=http%3A%2F%2Fwww2.localhost%3A8800%2Fcontent-security-policy%2Fsupport%2Ffail.png%3Ft%3D4
 
@@ -6,8 +4,8 @@
 Harness Error (TIMEOUT), message = null
 
 PASS Direct block, same-origin = full URL in report
-TIMEOUT Direct block, cross-origin = full URL in report Test timed out
+PASS Direct block, cross-origin = full URL in report
 TIMEOUT Block after redirect, same-origin = original URL in report Test timed out
-PASS Block after redirect, cross-origin = original URL in report
+TIMEOUT Block after redirect, cross-origin = original URL in report Test timed out
 PASS Violation report status OK.
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/reporting/report-strips-fragment-expected.txt (286362 => 286363)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/reporting/report-strips-fragment-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/reporting/report-strips-fragment-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -1,6 +1,3 @@
-CONSOLE MESSAGE: Refused to load https://evil.com/img.png because it does not appear in the img-src directive of the Content Security Policy.
 
-Harness Error (TIMEOUT), message = null
+PASS Reported document URI does not contain fragments.
 
-TIMEOUT Reported document URI does not contain fragments. Test timed out
-

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/securitypolicyviolation/securitypolicyviolation-block-cross-origin-image.sub-expected.txt (286362 => 286363)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/securitypolicyviolation/securitypolicyviolation-block-cross-origin-image.sub-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/securitypolicyviolation/securitypolicyviolation-block-cross-origin-image.sub-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -1,3 +1,3 @@
 
-FAIL Non-redirected cross-origin URLs are not stripped. assert_equals: expected "http://127.0.0.1:8800/content-security-policy/support/fail.png" but got "http://127.0.0.1:8800"
+FAIL Non-redirected cross-origin URLs are not stripped. assert_equals: expected 4 but got 6
 

Added: trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_1_2.sub-expected.txt (0 => 286363)


--- trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_1_2.sub-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_1_2.sub-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -0,0 +1,7 @@
+Video element src attribute must match src list - negative test
+
+
+PASS Disallowed async video src
+PASS Disallowed async video source element
+PASS Test that securitypolicyviolation events are fired
+

Added: trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_2_2.sub-expected.txt (0 => 286363)


--- trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_2_2.sub-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-7_2_2.sub-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -0,0 +1,7 @@
+Audio element src attribute must match src list - negative test
+
+
+PASS Disallaowed audio src
+PASS Disallowed audio source element
+PASS Test that securitypolicyviolation events are fired
+

Copied: trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-blocked.sub-expected.txt (from rev 286362, trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-blocked.sub-expected.txt) (0 => 286363)


--- trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-blocked.sub-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-blocked.sub-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -0,0 +1,9 @@
+Video element src attribute must match src list - 'none' negative test
+
+
+PASS Disallowed async video src
+PASS Disallowed async video source element
+PASS Disallaowed audio src
+PASS Disallowed audio source element
+PASS Test that securitypolicyviolation events are fired
+

Modified: trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-redir-bug.sub-expected.txt (286362 => 286363)


--- trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-redir-bug.sub-expected.txt	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/LayoutTests/platform/glib/imported/w3c/web-platform-tests/content-security-policy/media-src/media-src-redir-bug.sub-expected.txt	2021-12-01 16:41:12 UTC (rev 286363)
@@ -7,9 +7,9 @@
 
 Harness Error (TIMEOUT), message = null
 
-FAIL In-policy async video src assert_unreached: Media error handler shouldn't be triggered for allowed domain. Reached unreachable code
+NOTRUN In-policy async video src
 NOTRUN in-policy async video src w/redir
-FAIL In-policy async video source element assert_unreached: Media error handler shouldn't be triggered for allowed domain. Reached unreachable code
+NOTRUN In-policy async video source element
 NOTRUN In-policy async video source element w/redir
 NOTRUN Should not fire policy violation events
 This test tests a buggy interaction in Chrome 46. Two hosts (self and www2) are both allowed as media-src, but only one (self) is allowed for connect-src. If a video src starts on an allowed host (self), and is redirected to another allowed media-src host, it should succeed. But a bug causes the redirect to be done in a fetch context to which connect-src is being applied instead, so the load is blocked. (This test passes in Firefox 45, modulo an event listener not firing.)

Modified: trunk/Source/WebCore/ChangeLog (286362 => 286363)


--- trunk/Source/WebCore/ChangeLog	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/Source/WebCore/ChangeLog	2021-12-01 16:41:12 UTC (rev 286363)
@@ -1,3 +1,16 @@
+2021-12-01  Patrick Griffis  <[email protected]>
+
+        CSP: Update URL stripping in reports to match other implementations
+        https://bugs.webkit.org/show_bug.cgi?id=233135
+
+        Reviewed by Kate Cheney.
+
+        * page/csp/ContentSecurityPolicy.cpp:
+        (WebCore::ContentSecurityPolicy::createURLForReporting const):
+        (WebCore::ContentSecurityPolicy::reportViolation const):
+        (WebCore::ContentSecurityPolicy::deprecatedURLForReporting const): Deleted.
+        * page/csp/ContentSecurityPolicy.h:
+
 2021-12-01  Youenn Fablet  <[email protected]>
 
         Reuse navigation preload if service worker is fetching the corresponding navigation request

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp (286362 => 286363)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp	2021-12-01 16:41:12 UTC (rev 286363)
@@ -713,13 +713,24 @@
     return !url.isHierarchical() || url.protocolIs("file");
 }
 
-String ContentSecurityPolicy::deprecatedURLForReporting(const URL& url) const
+String ContentSecurityPolicy::createURLForReporting(const URL& url, const String& violatedDirective) const
 {
+    // This implements the deprecated CSP2 "strip uri for reporting" algorithm from https://www.w3.org/TR/CSP2/#violation-reports
+    // with the change that cross-origin is considered safe except on some directives.
+    // The frame-src, object-src, and block-all-mixed-content directives would allow a website to put another in a frame
+    // and listen to emitted securitypolicyviolations.
+    bool directiveIsSafe = violatedDirective != ContentSecurityPolicyDirectiveNames::frameSrc
+        && violatedDirective != ContentSecurityPolicyDirectiveNames::objectSrc
+        && violatedDirective != ContentSecurityPolicyDirectiveNames::blockAllMixedContent;
+    auto securityOrigin = static_cast<SecurityOriginData>(*m_selfSource).securityOrigin();
+
     if (!url.isValid())
         return { };
     if (shouldReportProtocolOnly(url))
         return url.protocol().toString();
-    return static_cast<SecurityOriginData>(*m_selfSource).securityOrigin()->canRequest(url) ? url.strippedForUseAsReferrer() : SecurityOrigin::create(url)->toString();
+    if (securityOrigin->canRequest(url) || directiveIsSafe)
+        return url.strippedForUseAsReferrer();
+    return SecurityOrigin::create(url)->toString();
 }
 
 void ContentSecurityPolicy::reportViolation(const String& violatedDirective, const ContentSecurityPolicyDirective& effectiveViolatedDirective, const String& blockedURL, const String& consoleMessage, JSC::JSGlobalObject* state) const
@@ -749,8 +760,15 @@
     // FIXME: Support sending reports from worker.
     CSPInfo info;
 
-    auto blockedURL = URL(URL(), blockedURLString);
-    info.documentURI = m_documentURL ? m_documentURL.value().strippedForUseAsReferrer() : deprecatedURLForReporting(blockedURL);
+    String blockedURI;
+    if (blockedURLString == "eval" || blockedURLString == "inline")
+        blockedURI = blockedURLString;
+    else {
+        // If there is a redirect then we use the pre-redirect URL: https://www.w3.org/TR/CSP3/#security-violation-reports.
+        blockedURI = createURLForReporting(preRedirectURL.isNull() ? URL(URL(), blockedURLString) : preRedirectURL, violatedDirective);
+    }
+
+    info.documentURI = m_documentURL ? m_documentURL.value().strippedForUseAsReferrer() : blockedURI;
     info.lineNumber = sourcePosition.m_line.oneBasedInt();
     info.columnNumber = sourcePosition.m_column.oneBasedInt();
     info.sample = violatedDirectiveList.shouldReportSample(violatedDirective) ? sourceContent.left(40).toString() : emptyString();
@@ -771,7 +789,7 @@
         auto stack = createScriptCallStack(JSExecState::currentState(), 2);
         auto* callFrame = stack->firstNonNativeCallFrame();
         if (callFrame && callFrame->lineNumber()) {
-            info.sourceFile = deprecatedURLForReporting(URL { URL { }, callFrame->sourceURL() });
+            info.sourceFile = createURLForReporting(URL { URL { }, callFrame->sourceURL() }, violatedDirective);
             info.lineNumber = callFrame->lineNumber();
             info.columnNumber = callFrame->columnNumber();
         }
@@ -778,14 +796,6 @@
     }
     ASSERT(m_client || is<Document>(m_scriptExecutionContext));
 
-    String blockedURI;
-    if (blockedURLString == "eval" || blockedURLString == "inline")
-        blockedURI = blockedURLString;
-    else if (preRedirectURL.isNull())
-        blockedURI = deprecatedURLForReporting(blockedURL);
-    else
-        blockedURI = deprecatedURLForReporting(preRedirectURL);
-
     // FIXME: Is it policy to not use the status code for HTTPS, or is that a bug?
     unsigned short httpStatusCode = m_selfSourceProtocol == "http" ? m_httpStatusCode : 0;
 

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h (286362 => 286363)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h	2021-12-01 15:47:44 UTC (rev 286362)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h	2021-12-01 16:41:12 UTC (rev 286363)
@@ -192,8 +192,7 @@
     void logToConsole(const String& message, const String& contextURL = String(), const OrdinalNumber& contextLine = OrdinalNumber::beforeFirst(), const OrdinalNumber& contextColumn = OrdinalNumber::beforeFirst(), JSC::JSGlobalObject* = nullptr) const;
     void applyPolicyToScriptExecutionContext();
 
-    // Implements the deprecated CSP2 "strip uri for reporting" algorithm from <https://www.w3.org/TR/CSP2/#violation-reports>.
-    String deprecatedURLForReporting(const URL&) const;
+    String createURLForReporting(const URL&, const String&) const;
 
     const TextEncoding& documentEncoding() const;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to