Title: [123899] trunk
Revision
123899
Author
[email protected]
Date
2012-07-27 11:38:25 -0700 (Fri, 27 Jul 2012)

Log Message

CSP directives containing invalid characters should log an error.
https://bugs.webkit.org/show_bug.cgi?id=92487

Patch by Mike West <[email protected]> on 2012-07-27
Reviewed by Adam Barth.

Source/WebCore:

Unknown directive names are currently logged, but we exit the directive
parser early without logging if we hit an invalid character inside a
directive. `script-src: ...`, for example, was ignored without letting
the developer know what happened. This patch changes that behavior,
logging the whole name (in this case `script-src:`) as an unknown
directive.

Test: http/tests/security/contentSecurityPolicy/directive-parsing-04.html

* page/ContentSecurityPolicy.cpp:
(WebCore::CSPDirectiveList::parseDirective):

LayoutTests:

* http/tests/security/contentSecurityPolicy/directive-parsing-03-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/directive-parsing-04-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/directive-parsing-04.html: Added.
    Adding a test specifically for `script-src: ...` which bit me, and
    updating test #3, which now has a better error message.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (123898 => 123899)


--- trunk/LayoutTests/ChangeLog	2012-07-27 18:26:03 UTC (rev 123898)
+++ trunk/LayoutTests/ChangeLog	2012-07-27 18:38:25 UTC (rev 123899)
@@ -1,3 +1,16 @@
+2012-07-27  Mike West  <[email protected]>
+
+        CSP directives containing invalid characters should log an error.
+        https://bugs.webkit.org/show_bug.cgi?id=92487
+
+        Reviewed by Adam Barth.
+
+        * http/tests/security/contentSecurityPolicy/directive-parsing-03-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/directive-parsing-04-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/directive-parsing-04.html: Added.
+            Adding a test specifically for `script-src: ...` which bit me, and
+            updating test #3, which now has a better error message.
+
 2012-07-27  Ádám Kallai  <[email protected]>
 
         [Qt] platform/qt/svg/custom tests needs update after font change.

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/directive-parsing-03-expected.txt (123898 => 123899)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/directive-parsing-03-expected.txt	2012-07-27 18:26:03 UTC (rev 123898)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/directive-parsing-03-expected.txt	2012-07-27 18:38:25 UTC (rev 123899)
@@ -1,3 +1,5 @@
+CONSOLE MESSAGE: Unrecognized Content-Security-Policy directive 'aaa'.
+
 CONSOLE MESSAGE: Refused to load the script 'http://127.0.0.1:8000/security/contentSecurityPolicy/resources/script.js' because it violates the following Content Security Policy directive: "script-src 'none'".
 
 This script should not execute even though there are parse errors in the policy.

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/directive-parsing-04-expected.txt (0 => 123899)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/directive-parsing-04-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/directive-parsing-04-expected.txt	2012-07-27 18:38:25 UTC (rev 123899)
@@ -0,0 +1,10 @@
+CONSOLE MESSAGE: Unrecognized Content-Security-Policy directive 'script-src:'.
+
+A warning should be logged to the console, as `script-src: 'none'` shouldn't contain a colon. Since the directive is invalid, the script should run.
+
+
+
+--------
+Frame: '<!--framePath //<!--frame0-->-->'
+--------
+PASS

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/directive-parsing-04.html (0 => 123899)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/directive-parsing-04.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/directive-parsing-04.html	2012-07-27 18:38:25 UTC (rev 123899)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+if (window.testRunner) {
+  testRunner.dumpAsText();
+  testRunner.dumpChildFramesAsText();
+}
+</script>
+</head>
+<body>
+  <p>
+    A warning should be logged to the console, as `script-src: 'none'` shouldn't
+    contain a colon. Since the directive is invalid, the script should run.
+  </p>
+  <iframe src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (123898 => 123899)


--- trunk/Source/WebCore/ChangeLog	2012-07-27 18:26:03 UTC (rev 123898)
+++ trunk/Source/WebCore/ChangeLog	2012-07-27 18:38:25 UTC (rev 123899)
@@ -1,3 +1,22 @@
+2012-07-27  Mike West  <[email protected]>
+
+        CSP directives containing invalid characters should log an error.
+        https://bugs.webkit.org/show_bug.cgi?id=92487
+
+        Reviewed by Adam Barth.
+
+        Unknown directive names are currently logged, but we exit the directive
+        parser early without logging if we hit an invalid character inside a
+        directive. `script-src: ...`, for example, was ignored without letting
+        the developer know what happened. This patch changes that behavior,
+        logging the whole name (in this case `script-src:`) as an unknown
+        directive.
+
+        Test: http/tests/security/contentSecurityPolicy/directive-parsing-04.html
+
+        * page/ContentSecurityPolicy.cpp:
+        (WebCore::CSPDirectiveList::parseDirective):
+
 2012-07-27  No'am Rosenthal  <[email protected]>
 
         [Texmap] Performance regression in texture uploads after r121223

Modified: trunk/Source/WebCore/page/ContentSecurityPolicy.cpp (123898 => 123899)


--- trunk/Source/WebCore/page/ContentSecurityPolicy.cpp	2012-07-27 18:26:03 UTC (rev 123898)
+++ trunk/Source/WebCore/page/ContentSecurityPolicy.cpp	2012-07-27 18:38:25 UTC (rev 123899)
@@ -949,8 +949,11 @@
     if (position == end)
         return true;
 
-    if (!skipExactly<isASCIISpace>(position, end))
+    if (!skipExactly<isASCIISpace>(position, end)) {
+        skipWhile<isNotASCIISpace>(position, end);
+        logUnrecognizedDirective(String(nameBegin, position - nameBegin));
         return false;
+    }
 
     skipWhile<isASCIISpace>(position, end);
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to