Dynamic eval execution #
Calls to eval(), including globalThis.eval, window.eval and global.eval.
Why it matters
eval executes a string as code with the caller's privileges. If any part of that string can be influenced by an attacker, it becomes arbitrary code execution.
What it detects
- eval(expression)
- globalThis.eval(expression)
- window.eval(expression)
- global.eval(expression)
export function calculate(expression: string) {
return eval(expression);
}export function parseSettings(text: string) {
return JSON.parse(text) as Record<string, unknown>;
}Recommended fix
Avoid evaluating strings as code; use explicit parsing or a safe data format.
False-positive and limitation notes
- The rule matches the call shape only. It does not prove that the evaluated string is attacker-controlled, so a call on a fixed trusted string is still reported.
- Indirect forms such as aliasing eval to another variable are not tracked.
Enable or disable with "SEC001": true | false under rules.security in codeguard.config.json.