eval()
The JavaScript function that runs a string as code.
Evaluating strings that contain user input lets attackers run arbitrary code.
In more detail
The code runs with access to the variables around the call, which makes its effects hard to predict. If any part of the string comes from users, attackers can run their own code, which is why eval is treated as an injection sink and blocked by strict CSP.
Related terms
- 'unsafe-eval' — A CSP keyword that allows code to be built from strings at runtime with eval() and similar functions.
- injection sink — A place in code where a string is interpreted as HTML or code, such as innerHTML, document.write or eval, and so can run an attack if the string is untrusted.
Taught in
- Content Security Policy (CSP), Trusted Types And XSS Defenses — Frontend Architecture & Web Platform