Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Report the correct document uri in the case of a ContentSecurityPolic…
…yClient https://bugs.webkit.org/show_bug.cgi?id=222489 <rdar://problem/73774118> Reviewed by Brent Fulgham. Source/WebCore: Tests: http/tests/security/contentSecurityPolicy/report-document-uri-after-blocked-redirect.html http/tests/security/contentSecurityPolicy/report-document-uri-blob.html Previously we were setting the document URI to be the blocked URI in the case where we were using a ContentSecurityPolicyClient and didn't have access to the document URL. This patch passes the document URL to the network process when loading a resource so we can properly set the document URI in this case. * page/csp/ContentSecurityPolicy.cpp: (WebCore::shouldReportProtocolOnly): (WebCore::ContentSecurityPolicy::deprecatedURLForReporting const): (WebCore::ContentSecurityPolicy::reportViolation const): Follow spec guidelines https://www.w3.org/TR/CSP2/#violation-reports and set the document URI to be the URI's scheme if it is a globally unique identifier. In the case where we are using a client and don't have the document URL, we should at least strip the blocked URL before reporting to align with the spec. * page/csp/ContentSecurityPolicy.h: (WebCore::ContentSecurityPolicy::setDocumentURL): Source/WebKit: Pass the document URL from the Network Process when we schedule a load in case we need to report a CSP violation in NetworkLoadChecker. * NetworkProcess/NetworkLoadChecker.cpp: (WebKit::NetworkLoadChecker::NetworkLoadChecker): (WebKit::NetworkLoadChecker::contentSecurityPolicy): The regular toString() method sets file:// URLs to null. We should use toRawString() so we can report the scheme if the source origin is a local file, as per the W3C spec. * NetworkProcess/NetworkLoadChecker.h: * NetworkProcess/NetworkResourceLoadParameters.cpp: (WebKit::NetworkResourceLoadParameters::encode const): (WebKit::NetworkResourceLoadParameters::decode): * NetworkProcess/NetworkResourceLoadParameters.h: * NetworkProcess/NetworkResourceLoader.cpp: * NetworkProcess/PingLoad.cpp: (WebKit::PingLoad::PingLoad): * WebProcess/Network/WebLoaderStrategy.cpp: (WebKit::WebLoaderStrategy::scheduleLoadFromNetworkProcess): Tools: Rename OverrideContentSecurityPolicy.mm to ContentSecurityPolicy.mm so we can use it for more general purpose CSP testing. Add a test for document-uri reporting for file:, data: and about: protocols. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicy.mm: Renamed from Tools/TestWebKitAPI/Tests/WebKitCocoa/OverrideContentSecurityPolicy.mm. (TEST): * TestWebKitAPI/Tests/WebKitCocoa/csp-document-uri-report.html: Added. LayoutTests: Layout test coverage for redirects using a ContentSecurityPolicyClient and blob files. * http/tests/security/contentSecurityPolicy/report-document-uri-blob-expected.txt: Added. * http/tests/security/contentSecurityPolicy/report-document-uri-blob.html: Added. * http/tests/security/contentSecurityPolicy/report-document-uri-after-blocked-redirect-expected.txt: Added. * http/tests/security/contentSecurityPolicy/report-document-uri-after-blocked-redirect.html: Added. * platform/mac-wk1/http/tests/security/contentSecurityPolicy/report-document-uri-after-blocked-redirect-expected.txt: Added. * platform/win/http/tests/security/contentSecurityPolicy/report-document-uri-after-blocked-redirect-expected.txt: Added. * platform/win/TestExpectations: Blob URLs timeout on win. Canonical link: https://commits.webkit.org/234793@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273820 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
23 changed files
with
305 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CONSOLE MESSAGE: Refused to connect to http://localhost:8000/security/contentSecurityPolicy/resources/xhr-redirect-not-allowed.pl because it does not appear in the connect-src directive of the Content Security Policy. | ||
CONSOLE MESSAGE: Blocked by Content Security Policy. | ||
CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8000/security/contentSecurityPolicy/resources/xhr-redirect-not-allowed.pl due to access control checks. | ||
PASS XMLHttpRequest.send() did not follow the disallowed redirect. | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
documentURI = http://127.0.0.1:8000/security/contentSecurityPolicy/report-document-uri-after-blocked-redirect.html | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Security-Policy" content="connect-src http://127.0.0.1:8000/security/contentSecurityPolicy/resources/redir.php"> | ||
<script src="/js-test-resources/js-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
window.jsTestIsAsync = true; | ||
function log(msg) { | ||
document.getElementById("console").appendChild(document.createTextNode(msg + "\n")); | ||
} | ||
|
||
// Expect the document URI to be the document URL stripped for reporting. | ||
document.addEventListener('securitypolicyviolation', e => { | ||
document.body.innerHTML += `documentURI = <b>${e.documentURI}</b><br/><br/>`; | ||
finishJSTest(); | ||
}); | ||
|
||
var xhr = new XMLHttpRequest; | ||
try { | ||
// Redirect to a different host, because as of CSP2 paths | ||
// are ignored when matching after a redirect. | ||
xhr.open("GET", "resources/redir.php?url=http://localhost:8000/security/contentSecurityPolicy/resources/xhr-redirect-not-allowed.pl", true); | ||
} catch(e) { | ||
testFailed("XMLHttpRequest.open() should not throw an exception."); | ||
} | ||
|
||
xhr.onload = function () { | ||
testFailed("XMLHttpRequest.send() should fail to follow the disallowed redirect."); | ||
finishJSTest(); | ||
}; | ||
|
||
xhr.onerror = function () { | ||
testPassed("XMLHttpRequest.send() did not follow the disallowed redirect."); | ||
}; | ||
|
||
xhr.send(); | ||
</script> | ||
</script> | ||
<script src="/js-test-resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
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. | ||
documentURI = blob | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Security-Policy" content="script-src 'nonce-test'"> | ||
<script nonce="test"> | ||
if (window.testRunner) | ||
testRunner.dumpAsText(); | ||
|
||
// Include a script not included in the script-src to cause a violation. | ||
// Include another script to report the document URI of this report, expecting | ||
// it to be stripped to only consist of the URL protocol. | ||
var violatingScript = "<script>\n\<" + "/script>" | ||
var reportingScript = "<script nonce=\"test\"> testRunner.waitUntilDone(); document.addEventListener('securitypolicyviolation', e => { document.body.innerHTML += `documentURI = <b>${e.documentURI}</b><br/><br/>`; testRunner.notifyDone(); });<" + "/script>"; | ||
|
||
let blob = new Blob([violatingScript + reportingScript], {type : "text/html"}); | ||
if (window.testRunner) | ||
testRunner.queueLoad(URL.createObjectURL(blob)); | ||
</script> | ||
<body> | ||
<p>Initial page</p> | ||
</body> | ||
</head> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CONSOLE MESSAGE: Refused to connect to http://localhost:8000/security/contentSecurityPolicy/resources/xhr-redirect-not-allowed.pl because it does not appear in the connect-src directive of the Content Security Policy. | ||
CONSOLE MESSAGE: Blocked by Content Security Policy. | ||
CONSOLE MESSAGE: XMLHttpRequest cannot load http://127.0.0.1:8000/security/contentSecurityPolicy/resources/redir.php?url=http://localhost:8000/security/contentSecurityPolicy/resources/xhr-redirect-not-allowed.pl due to access control checks. | ||
PASS XMLHttpRequest.send() did not follow the disallowed redirect. | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
documentURI = http://127.0.0.1:8000/security/contentSecurityPolicy/report-document-uri-after-blocked-redirect.html | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CONSOLE MESSAGE: Refused to connect to http://localhost:8000/security/contentSecurityPolicy/resources/xhr-redirect-not-allowed.pl because it does not appear in the connect-src directive of the Content Security Policy. | ||
CONSOLE MESSAGE: Blocked by Content Security Policy. | ||
CONSOLE MESSAGE: XMLHttpRequest cannot load http://127.0.0.1:8000/security/contentSecurityPolicy/resources/redir.php?url=http://localhost:8000/security/contentSecurityPolicy/resources/xhr-redirect-not-allowed.pl due to access control checks. | ||
PASS XMLHttpRequest.send() did not follow the disallowed redirect. | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
documentURI = http://127.0.0.1:8000/security/contentSecurityPolicy/report-document-uri-after-blocked-redirect.html | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.