Changeset 128670 in webkit for trunk/Source/JavaScriptCore
- Timestamp:
- Sep 14, 2012, 4:33:20 PM (13 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r128667 r128670 1 2012-09-14 Mike West <[email protected]> 2 3 JSC should throw a more descriptive exception when blocking 'eval' via CSP. 4 https://bugs.webkit.org/show_bug.cgi?id=94331 5 6 Reviewed by Geoffrey Garen. 7 8 Unless explicitly whitelisted, the 'script-src' Content Security Policy 9 directive blocks 'eval' and 'eval'-like constructs such as 10 'new Function()'. When 'eval' is encountered in code, an 'EvalError' is 11 thrown, but the associated message is poor: "Eval is disabled" doesn't 12 give developers enough information about why their code isn't behaving 13 as expected. 14 15 This patch adds an 'errorMessage' parameter to the JavaScriptCore method 16 used to disable 'eval'; ContentSecurityPolicy has the opportunity to 17 pass in a more detailed and descriptive error that contains more context 18 for the developer. 19 20 * runtime/Executable.cpp: 21 (JSC::EvalExecutable::compileInternal): 22 Drop the hard-coded "Eval is disabled" error message in favor of 23 reading the error message off the global object. 24 * runtime/FunctionConstructor.cpp: 25 (JSC::FunctionConstructor::getCallData): 26 Drop the hard-coded "Function constructor is disabled" error message 27 in favor of reading the error message off the global object. 28 * runtime/JSGlobalObject.h: 29 (JSGlobalObject): 30 (JSC::JSGlobalObject::evalEnabled): 31 Making this accessor method const. 32 (JSC::JSGlobalObject::evalDisabledErrorMessage): 33 Accessor for the error message set via 'setEvalDisabled'. 34 (JSC::JSGlobalObject::setEvalEnabled): 35 Adding an 'errorMessage' parameter which is stored on the global 36 object, and used when exceptions are thrown. 37 1 38 2012-09-14 Filip Pizlo <[email protected]> 2 39 -
trunk/Source/JavaScriptCore/runtime/Executable.cpp
r127958 r128670 203 203 } else { 204 204 if (!lexicalGlobalObject->evalEnabled()) 205 return throwError(exec, createEvalError(exec, ASCIILiteral("Eval is disabled")));205 return throwError(exec, createEvalError(exec, lexicalGlobalObject->evalDisabledErrorMessage())); 206 206 RefPtr<EvalNode> evalNode = parse<EvalNode>(globalData, lexicalGlobalObject, m_source, 0, Identifier(), isStrictMode() ? JSParseStrict : JSParseNormal, EvalNode::isFunctionNode ? JSParseFunctionCode : JSParseProgramCode, lexicalGlobalObject->debugger(), exec, &exception); 207 207 if (!evalNode) { -
trunk/Source/JavaScriptCore/runtime/FunctionConstructor.cpp
r127505 r128670 83 83 { 84 84 if (!globalObject->evalEnabled()) 85 return throwError(exec, createEvalError(exec, ASCIILiteral("Function constructor is disabled")));85 return throwError(exec, createEvalError(exec, globalObject->evalDisabledErrorMessage())); 86 86 return constructFunctionSkippingEvalEnabledCheck(exec, globalObject, args, functionName, sourceURL, position); 87 87 } -
trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h
r127363 r128670 156 156 157 157 bool m_evalEnabled; 158 String m_evalDisabledErrorMessage; 158 159 bool m_experimentsEnabled; 159 160 … … 305 306 bool isDynamicScope(bool& requiresDynamicChecks) const; 306 307 307 void setEvalEnabled(bool enabled) { m_evalEnabled = enabled; } 308 bool evalEnabled() { return m_evalEnabled; } 308 bool evalEnabled() const { return m_evalEnabled; } 309 const String& evalDisabledErrorMessage() const { return m_evalDisabledErrorMessage; } 310 void setEvalEnabled(bool enabled, const String& errorMessage = String()) 311 { 312 m_evalEnabled = enabled; 313 m_evalDisabledErrorMessage = errorMessage; 314 } 309 315 310 316 void resetPrototype(JSGlobalData&, JSValue prototype);
Note:
See TracChangeset
for help on using the changeset viewer.