Security
High
All
SN-0127
In addition to being obtuse from a syntax perspective, function constructors are also dangerous: their execution evaluates the constructor string arguments similar to the way eval works, which could expose your program to random, unintended code which can be both slow and a security risk.
Avoid function constructors altogether.
30 min
This rule is linked to Common Weakness Enumeration CWE-95 Improper Neutralization of Directives in Dynamically Evaluated Code (Eval Injection).
var obj = new Function(“return ” + data)(); // Noncompliant
var obj = JSON.parse(data);