How to fix: eval() Usage in Page Scripts
An eval() call was found inside the page's <script> blocks. eval() executes arbitrary JavaScript strings and is a common AI-generated mistake when dynamically constructing logic.
Why it matters
If any user-controlled data reaches eval(), it enables full JavaScript code execution in the browser or server context. Even when input is not directly user-controlled, eval() breaks static analysis and makes the application unauditable.
AI code generators often produce eval() when asked to 'dynamically evaluate' configuration, templates, or expressions. The correct alternative is almost always a lookup table, JSON.parse, or a dedicated expression parser.
How to fix it
- 1Remove all eval() calls. Use JSON.parse() for parsing JSON, Function() only with extreme caution and never with user input.
- 2Replace dynamic dispatch with an explicit lookup: const handlers = { add: (a,b) => a+b }; handlers[op](x, y).
- 3Enable eslint's no-eval rule to prevent regressions.
- 4If server-side: consider vm2 or isolated-vm for sandboxed evaluation, never raw eval().
Code examples
Remove eval: use a lookup table
// Bad (AI-generated)
const result = eval(`math.${operation}(${a}, ${b})`);
// Good
const ops = { add: (a,b) => a+b, sub: (a,b) => a-b, mul: (a,b) => a*b };
const fn = ops[operation];
if (!fn) throw new Error('Unknown operation');
const result = fn(Number(a), Number(b));References
Detected automatically by VulnRadar. The check id is vibe-eval-usage, stable across every scan so you can filter or diff on it.
More ai code checks
- LowGeneric Error Messages Leak No Context
- MediumTODO/FIXME Security Note in Response
- HighSSL Certificate Verification Disabled
- HighMath.random() Used for Security Tokens
- CriticalHardcoded Credential in Authentication Logic
- CriticalJWT 'none' Algorithm Accepted
- CriticalSQL String Concatenation Pattern Detected
- MediumStack Trace Exposed in Response
Questions
- How severe is eval() Usage in Page Scripts?
- VulnRadar rates this high severity in the ai code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id vibe-eval-usage, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does eval() Usage in Page Scripts map to?
- It maps to CWE-94. In the OWASP Top 10 it falls under A03:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.