Title: [194970] branches/safari-601-branch

Diff

Modified: branches/safari-601-branch/LayoutTests/ChangeLog (194969 => 194970)


--- branches/safari-601-branch/LayoutTests/ChangeLog	2016-01-13 19:33:02 UTC (rev 194969)
+++ branches/safari-601-branch/LayoutTests/ChangeLog	2016-01-13 20:17:21 UTC (rev 194970)
@@ -1,3 +1,30 @@
+2016-01-13  Matthew Hanson  <matthew_han...@apple.com>
+
+        Merge r193939. rdar://problem/24154418
+
+    2015-12-10  Daniel Bates  <daba...@apple.com>
+
+            [CSP] eval() is not blocked for stringified literals
+            https://bugs.webkit.org/show_bug.cgi?id=152158
+            <rdar://problem/15775625>
+
+            Reviewed by Saam Barati.
+
+            Update test LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked.html to be
+            more comprehensive.
+
+            Add tests to ensure that we block eval() from within an external _javascript_ script when the
+            policy of the page disallows eval() and that we block eval() inside a subframe that disallows
+            eval() when the page in the main frame allows eval().
+
+            * http/tests/security/contentSecurityPolicy/eval-blocked-expected.txt:
+            * http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script-expected.txt: Added.
+            * http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script.html: Added.
+            * http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe-expected.txt: Copied from LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-expected.txt.
+            * http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe.html: Added.
+            * http/tests/security/contentSecurityPolicy/eval-blocked.html:
+            * http/tests/security/contentSecurityPolicy/resources/eval-blocked-in-external-script.js: Added.
+
 2016-01-12  Matthew Hanson  <matthew_han...@apple.com>
 
         Merge r194704. rdar://problem/24043057

Modified: branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-expected.txt (194969 => 194970)


--- branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-expected.txt	2016-01-13 19:33:02 UTC (rev 194969)
+++ branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-expected.txt	2016-01-13 20:17:21 UTC (rev 194970)
@@ -1,5 +1,37 @@
-CONSOLE MESSAGE: line 12: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+CONSOLE MESSAGE: line 14: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
 CONSOLE MESSAGE: line 15: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
+CONSOLE MESSAGE: line 32: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
 
+CONSOLE MESSAGE: line 33: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 34: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 35: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 36: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 37: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 38: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 39: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 40: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 41: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 42: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 43: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 44: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 45: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 46: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 47: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+

Added: branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script-expected.txt (0 => 194970)


--- branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script-expected.txt	2016-01-13 20:17:21 UTC (rev 194970)
@@ -0,0 +1,3 @@
+CONSOLE MESSAGE: line 1: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'unsafe-inline'".
+
+

Copied: branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script.html (from rev 194949, branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked.html) (0 => 194970)


--- branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script.html	2016-01-13 20:17:21 UTC (rev 194970)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'">
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+</script>
+<script src=""
+</head>
+</html>

Added: branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe-expected.txt (0 => 194970)


--- branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe-expected.txt	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe-expected.txt	2016-01-13 20:17:21 UTC (rev 194970)
@@ -0,0 +1,44 @@
+CONSOLE MESSAGE: line 14: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 15: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 32: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 33: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 34: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 35: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 36: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 37: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 38: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 39: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 40: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 41: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 42: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 43: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 44: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 45: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 46: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+CONSOLE MESSAGE: line 47: EvalError: Refused to evaluate a string as _javascript_ because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
+
+Tests that eval() is blocked in a subframe that disallows eval() when the parent frame allows eval().
+
+
+
+--------
+Frame: '<!--framePath //<!--frame0-->-->'
+--------
+

Added: branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe.html (0 => 194970)


--- branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe.html	2016-01-13 20:17:21 UTC (rev 194970)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.dumpChildFramesAsText();
+}
+</script>
+</head>
+<body>
+<p>Tests that eval() is blocked in a subframe that disallows eval() when the parent frame allows eval().</p>
+<iframe src=""
+</body>
+</html>

Modified: branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked.html (194969 => 194970)


--- branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked.html	2016-01-13 19:33:02 UTC (rev 194969)
+++ branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked.html	2016-01-13 20:17:21 UTC (rev 194970)
@@ -5,14 +5,45 @@
 <script>
 if (window.testRunner)
     testRunner.dumpAsText();
+
+var dummy = 79;
 </script>
 </head>
 <body>
-<script>
-eval("alert('FAIL (1 of 2)')");
-</script>
-<script>
-window.eval("alert('FAIL (2 of 2)')");
-</script>
+<!-- eval() string literal "alert()" -->
+<script>eval("alert('FAIL')")</script>
+<script>window.eval("alert('FAIL')")</script>
+<!-- eval() non-string literal (should be allowed) -->
+<script>eval(0)</script>
+<script>window.eval(0)</script>
+<script>eval(1)</script>
+<script>window.eval(1)</script>
+<script>eval(7)</script>
+<script>window.eval(7)</script>
+<script>eval(3.14)</script>
+<script>window.eval(3.14)</script>
+<script>eval(true)</script>
+<script>window.eval(true)</script>
+<script>eval(false)</script>
+<script>window.eval(false)</script>
+<script>eval(Function)</script>
+<script>window.eval(Function)</script>
+<!-- eval() string literal -->
+<script>eval("")</script>
+<script>window.eval("")</script>
+<script>eval("0")</script>
+<script>window.eval("0")</script>
+<script>eval("1")</script>
+<script>window.eval("1")</script>
+<script>eval("2.73")</script>
+<script>window.eval("2.73")</script>
+<script>eval("true")</script>
+<script>window.eval("true")</script>
+<script>eval("false")</script>
+<script>window.eval("false")</script>
+<script>eval("Object")</script>
+<script>window.eval("Object")</script>
+<script>eval("dummy")</script>
+<script>window.eval("dummy")</script>
 </body>
 </html>

Added: branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/resources/eval-blocked-in-external-script.js (0 => 194970)


--- branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/resources/eval-blocked-in-external-script.js	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/http/tests/security/contentSecurityPolicy/resources/eval-blocked-in-external-script.js	2016-01-13 20:17:21 UTC (rev 194970)
@@ -0,0 +1 @@
+eval("'FAIL'");

Modified: branches/safari-601-branch/Source/_javascript_Core/ChangeLog (194969 => 194970)


--- branches/safari-601-branch/Source/_javascript_Core/ChangeLog	2016-01-13 19:33:02 UTC (rev 194969)
+++ branches/safari-601-branch/Source/_javascript_Core/ChangeLog	2016-01-13 20:17:21 UTC (rev 194970)
@@ -1,3 +1,24 @@
+2016-01-13  Matthew Hanson  <matthew_han...@apple.com>
+
+        Merge r193939. rdar://problem/24154418
+
+    2015-12-10  Daniel Bates  <daba...@apple.com>
+
+            [CSP] eval() is not blocked for stringified literals
+            https://bugs.webkit.org/show_bug.cgi?id=152158
+            <rdar://problem/15775625>
+
+            Reviewed by Saam Barati.
+
+            Fixes an issue where stringified literals can be eval()ed despite being disallowed by
+            Content Security Policy of the page.
+
+            * interpreter/Interpreter.cpp:
+            (JSC::eval): Throw a _javascript_ EvalError exception if eval() is disallowed for the page
+            and return undefined.
+            * runtime/JSGlobalObjectFunctions.cpp:
+            (JSC::globalFuncEval): Ditto.
+
 2016-01-12  Matthew Hanson  <matthew_han...@apple.com>
 
         Merge r194704. rdar://problem/24043057

Modified: branches/safari-601-branch/Source/_javascript_Core/interpreter/Interpreter.cpp (194969 => 194970)


--- branches/safari-601-branch/Source/_javascript_Core/interpreter/Interpreter.cpp	2016-01-13 19:33:02 UTC (rev 194969)
+++ branches/safari-601-branch/Source/_javascript_Core/interpreter/Interpreter.cpp	2016-01-13 20:17:21 UTC (rev 194970)
@@ -139,8 +139,13 @@
     JSValue program = callFrame->argument(0);
     if (!program.isString())
         return program;
-    
+
     TopCallFrameSetter topCallFrame(callFrame->vm(), callFrame);
+    JSGlobalObject* globalObject = callFrame->lexicalGlobalObject();
+    if (!globalObject->evalEnabled()) {
+        callFrame->vm().throwException(callFrame, createEvalError(callFrame, globalObject->evalDisabledErrorMessage()));
+        return jsUndefined();
+    }
     String programSource = asString(program)->value(callFrame);
     if (callFrame->hadException())
         return JSValue();

Modified: branches/safari-601-branch/Source/_javascript_Core/runtime/JSGlobalObjectFunctions.cpp (194969 => 194970)


--- branches/safari-601-branch/Source/_javascript_Core/runtime/JSGlobalObjectFunctions.cpp	2016-01-13 19:33:02 UTC (rev 194969)
+++ branches/safari-601-branch/Source/_javascript_Core/runtime/JSGlobalObjectFunctions.cpp	2016-01-13 20:17:21 UTC (rev 194970)
@@ -567,6 +567,12 @@
     if (!x.isString())
         return JSValue::encode(x);
 
+    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
+    if (!globalObject->evalEnabled()) {
+        exec->vm().throwException(exec, createEvalError(exec, globalObject->evalDisabledErrorMessage()));
+        return JSValue::encode(jsUndefined());
+    }
+
     String s = x.toString(exec)->value(exec);
 
     if (s.is8Bit()) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to