Diff
Modified: trunk/LayoutTests/ChangeLog (193938 => 193939)
--- trunk/LayoutTests/ChangeLog 2015-12-11 02:06:59 UTC (rev 193938)
+++ trunk/LayoutTests/ChangeLog 2015-12-11 02:08:31 UTC (rev 193939)
@@ -1,3 +1,26 @@
+2015-12-10 Daniel Bates <[email protected]>
+
+ [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.
+
2015-12-10 Brady Eidson <[email protected]>
Modern IDB: storage/indexeddb/delete-in-upgradeneeded-close-in-versionchange.html fails
Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-expected.txt (193938 => 193939)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-expected.txt 2015-12-11 02:06:59 UTC (rev 193938)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-expected.txt 2015-12-11 02:08:31 UTC (rev 193939)
@@ -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: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script-expected.txt (0 => 193939)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script-expected.txt 2015-12-11 02:08:31 UTC (rev 193939)
@@ -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: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script.html (from rev 193938, trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked.html) (0 => 193939)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script.html (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-external-script.html 2015-12-11 02:08:31 UTC (rev 193939)
@@ -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: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe-expected.txt (0 => 193939)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe-expected.txt 2015-12-11 02:08:31 UTC (rev 193939)
@@ -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: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe.html (0 => 193939)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe.html (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked-in-subframe.html 2015-12-11 02:08:31 UTC (rev 193939)
@@ -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: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked.html (193938 => 193939)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked.html 2015-12-11 02:06:59 UTC (rev 193938)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/eval-blocked.html 2015-12-11 02:08:31 UTC (rev 193939)
@@ -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: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/resources/eval-blocked-in-external-script.js (0 => 193939)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/resources/eval-blocked-in-external-script.js (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/resources/eval-blocked-in-external-script.js 2015-12-11 02:08:31 UTC (rev 193939)
@@ -0,0 +1 @@
+eval("'FAIL'");
Modified: trunk/Source/_javascript_Core/ChangeLog (193938 => 193939)
--- trunk/Source/_javascript_Core/ChangeLog 2015-12-11 02:06:59 UTC (rev 193938)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-12-11 02:08:31 UTC (rev 193939)
@@ -1,3 +1,20 @@
+2015-12-10 Daniel Bates <[email protected]>
+
+ [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.
+
2015-12-10 Joseph Pecoraro <[email protected]>
Fix jsc symlink creation on iOS
Modified: trunk/Source/_javascript_Core/interpreter/Interpreter.cpp (193938 => 193939)
--- trunk/Source/_javascript_Core/interpreter/Interpreter.cpp 2015-12-11 02:06:59 UTC (rev 193938)
+++ trunk/Source/_javascript_Core/interpreter/Interpreter.cpp 2015-12-11 02:08:31 UTC (rev 193939)
@@ -144,8 +144,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: trunk/Source/_javascript_Core/runtime/JSGlobalObjectFunctions.cpp (193938 => 193939)
--- trunk/Source/_javascript_Core/runtime/JSGlobalObjectFunctions.cpp 2015-12-11 02:06:59 UTC (rev 193938)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObjectFunctions.cpp 2015-12-11 02:08:31 UTC (rev 193939)
@@ -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()) {