CSP: ws: and wss: blocked with connect-src *
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Dec 2016 04:18:11 +0000 (04:18 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Dec 2016 04:18:11 +0000 (04:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165804
<rdar://problem/28563643>

Reviewed by David Kilzer.

Source/WebCore:

Allow * to match ws: and wss:. This will make our behavior of * more closely conform
the behavior of * in the Content Security Policy Level 3 spec.,
<https://w3c.github.io/webappsec-csp/#match-url-to-source-expression> (Editor's Draft, 2 December 2016).

Tests: http/tests/security/contentSecurityPolicy/connect-src-star-secure-websocket-allowed.html
       http/tests/security/contentSecurityPolicy/connect-src-star-websocket-allowed.html
       http/tests/security/contentSecurityPolicy/default-src-star-secure-websocket-allowed.html
       http/tests/security/contentSecurityPolicy/default-src-star-websocket-allowed.html

* page/csp/ContentSecurityPolicySourceList.cpp:
(WebCore::ContentSecurityPolicySourceList::isProtocolAllowedByStar):

LayoutTests:

Add tests to ensure that * matches ws: and wss:.

* http/tests/security/contentSecurityPolicy/connect-src-star-secure-websocket-allowed-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/connect-src-star-secure-websocket-allowed.html: Added.
* http/tests/security/contentSecurityPolicy/connect-src-star-websocket-allowed-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/connect-src-star-websocket-allowed.html: Added.
* http/tests/security/contentSecurityPolicy/default-src-star-secure-websocket-allowed-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/default-src-star-secure-websocket-allowed.html: Added.
* http/tests/security/contentSecurityPolicy/default-src-star-websocket-allowed-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/default-src-star-websocket-allowed.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@209789 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/security/contentSecurityPolicy/connect-src-star-secure-websocket-allowed-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/contentSecurityPolicy/connect-src-star-secure-websocket-allowed.html [new file with mode: 0644]
LayoutTests/http/tests/security/contentSecurityPolicy/connect-src-star-websocket-allowed-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/contentSecurityPolicy/connect-src-star-websocket-allowed.html [new file with mode: 0644]
LayoutTests/http/tests/security/contentSecurityPolicy/default-src-star-secure-websocket-allowed-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/contentSecurityPolicy/default-src-star-secure-websocket-allowed.html [new file with mode: 0644]
LayoutTests/http/tests/security/contentSecurityPolicy/default-src-star-websocket-allowed-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/contentSecurityPolicy/default-src-star-websocket-allowed.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/csp/ContentSecurityPolicySourceList.cpp

index 2be9a33..bbbbb70 100644 (file)
@@ -1,3 +1,22 @@
+2016-12-13  Daniel Bates  <dabates@apple.com>
+
+        CSP: ws: and wss: blocked with connect-src *
+        https://bugs.webkit.org/show_bug.cgi?id=165804
+        <rdar://problem/28563643>
+
+        Reviewed by David Kilzer.
+
+        Add tests to ensure that * matches ws: and wss:.
+
+        * http/tests/security/contentSecurityPolicy/connect-src-star-secure-websocket-allowed-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/connect-src-star-secure-websocket-allowed.html: Added.
+        * http/tests/security/contentSecurityPolicy/connect-src-star-websocket-allowed-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/connect-src-star-websocket-allowed.html: Added.
+        * http/tests/security/contentSecurityPolicy/default-src-star-secure-websocket-allowed-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/default-src-star-secure-websocket-allowed.html: Added.
+        * http/tests/security/contentSecurityPolicy/default-src-star-websocket-allowed-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/default-src-star-websocket-allowed.html: Added.
+
 2016-12-13  Joseph Pecoraro  <pecoraro@apple.com>
 
         REGRESSION(r204163): Web Inspector: Page crashes when Inspector tries to load insecure SourceMap
diff --git a/LayoutTests/http/tests/security/contentSecurityPolicy/connect-src-star-secure-websocket-allowed-expected.txt b/LayoutTests/http/tests/security/contentSecurityPolicy/connect-src-star-secure-websocket-allowed-expected.txt
new file mode 100644 (file)
index 0000000..d4d6ac6
--- /dev/null
@@ -0,0 +1,2 @@
+PASS did create WebSocket.
+
diff --git a/LayoutTests/http/tests/security/contentSecurityPolicy/connect-src-star-secure-websocket-allowed.html b/LayoutTests/http/tests/security/contentSecurityPolicy/connect-src-star-secure-websocket-allowed.html
new file mode 100644 (file)
index 0000000..f414d34
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Security-Policy" content="connect-src *">
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+</script>
+</head>
+<body>
+<pre id="console"></pre>
+<script>
+function log(message)
+{
+    document.getElementById("console").appendChild(document.createTextNode(message + "\n"));
+}
+
+try {
+    new WebSocket("wss://127.0.0.1:9323/websocket/tests/hybi/echo");
+    log("PASS did create WebSocket.");
+} catch(e) {
+    log("FAIL did not create WebSocket.");
+}
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/security/contentSecurityPolicy/connect-src-star-websocket-allowed-expected.txt b/LayoutTests/http/tests/security/contentSecurityPolicy/connect-src-star-websocket-allowed-expected.txt
new file mode 100644 (file)
index 0000000..d4d6ac6
--- /dev/null
@@ -0,0 +1,2 @@
+PASS did create WebSocket.
+
diff --git a/LayoutTests/http/tests/security/contentSecurityPolicy/connect-src-star-websocket-allowed.html b/LayoutTests/http/tests/security/contentSecurityPolicy/connect-src-star-websocket-allowed.html
new file mode 100644 (file)
index 0000000..9b54deb
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Security-Policy" content="connect-src *">
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+</script>
+</head>
+<body>
+<pre id="console"></pre>
+<script>
+function log(message)
+{
+    document.getElementById("console").appendChild(document.createTextNode(message + "\n"));
+}
+
+try {
+    new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/echo");
+    log("PASS did create WebSocket.");
+} catch(e) {
+    log("FAIL did not create WebSocket.");
+}
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/security/contentSecurityPolicy/default-src-star-secure-websocket-allowed-expected.txt b/LayoutTests/http/tests/security/contentSecurityPolicy/default-src-star-secure-websocket-allowed-expected.txt
new file mode 100644 (file)
index 0000000..d4d6ac6
--- /dev/null
@@ -0,0 +1,2 @@
+PASS did create WebSocket.
+
diff --git a/LayoutTests/http/tests/security/contentSecurityPolicy/default-src-star-secure-websocket-allowed.html b/LayoutTests/http/tests/security/contentSecurityPolicy/default-src-star-secure-websocket-allowed.html
new file mode 100644 (file)
index 0000000..593363b
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'nonce-test'">
+<script nonce="test">
+if (window.testRunner)
+    testRunner.dumpAsText();
+</script>
+</head>
+<body>
+<pre id="console"></pre>
+<script nonce="test">
+function log(message)
+{
+    document.getElementById("console").appendChild(document.createTextNode(message + "\n"));
+}
+
+try {
+    new WebSocket("wss://127.0.0.1:9323/websocket/tests/hybi/echo");
+    log("PASS did create WebSocket.");
+} catch(e) {
+    log("FAIL did not create WebSocket.");
+}
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/security/contentSecurityPolicy/default-src-star-websocket-allowed-expected.txt b/LayoutTests/http/tests/security/contentSecurityPolicy/default-src-star-websocket-allowed-expected.txt
new file mode 100644 (file)
index 0000000..d4d6ac6
--- /dev/null
@@ -0,0 +1,2 @@
+PASS did create WebSocket.
+
diff --git a/LayoutTests/http/tests/security/contentSecurityPolicy/default-src-star-websocket-allowed.html b/LayoutTests/http/tests/security/contentSecurityPolicy/default-src-star-websocket-allowed.html
new file mode 100644 (file)
index 0000000..5c846e4
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'nonce-test'">
+<script nonce="test">
+if (window.testRunner)
+    testRunner.dumpAsText();
+</script>
+</head>
+<body>
+<pre id="console"></pre>
+<script nonce="test">
+function log(message)
+{
+    document.getElementById("console").appendChild(document.createTextNode(message + "\n"));
+}
+
+try {
+    new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/echo");
+    log("PASS did create WebSocket.");
+} catch(e) {
+    log("FAIL did not create WebSocket.");
+}
+</script>
+</body>
+</html>
index 1e6965f..b413217 100644 (file)
@@ -1,3 +1,23 @@
+2016-12-13  Daniel Bates  <dabates@apple.com>
+
+        CSP: ws: and wss: blocked with connect-src *
+        https://bugs.webkit.org/show_bug.cgi?id=165804
+        <rdar://problem/28563643>
+
+        Reviewed by David Kilzer.
+
+        Allow * to match ws: and wss:. This will make our behavior of * more closely conform
+        the behavior of * in the Content Security Policy Level 3 spec.,
+        <https://w3c.github.io/webappsec-csp/#match-url-to-source-expression> (Editor's Draft, 2 December 2016).
+
+        Tests: http/tests/security/contentSecurityPolicy/connect-src-star-secure-websocket-allowed.html
+               http/tests/security/contentSecurityPolicy/connect-src-star-websocket-allowed.html
+               http/tests/security/contentSecurityPolicy/default-src-star-secure-websocket-allowed.html
+               http/tests/security/contentSecurityPolicy/default-src-star-websocket-allowed.html
+
+        * page/csp/ContentSecurityPolicySourceList.cpp:
+        (WebCore::ContentSecurityPolicySourceList::isProtocolAllowedByStar):
+
 2016-12-13  Dave Hyatt  <hyatt@apple.com>
 
         [CSS Parser] Make CSSFunctionValue derive from CSSValueList
index 5d51f68..8036804 100644 (file)
@@ -123,7 +123,7 @@ bool ContentSecurityPolicySourceList::isProtocolAllowedByStar(const URL& url) co
 
     // Although not allowed by the Content Security Policy Level 3 spec., we allow a data URL to match
     // "img-src *" and either a data URL or blob URL to match "media-src *" for web compatibility.
-    bool isAllowed = url.protocolIsInHTTPFamily() || m_policy.protocolMatchesSelf(url);
+    bool isAllowed = url.protocolIsInHTTPFamily() || url.protocolIs("ws") || url.protocolIs("wss") || m_policy.protocolMatchesSelf(url);
     if (equalIgnoringASCIICase(m_directiveName, ContentSecurityPolicyDirectiveNames::imgSrc))
         isAllowed |= url.protocolIsData();
     else if (equalIgnoringASCIICase(m_directiveName, ContentSecurityPolicyDirectiveNames::mediaSrc))