'unsafe-eval'
A CSP keyword that allows code to be built from strings at runtime with eval() and similar functions.
It re-enables string-to-code execution that injected data can abuse.
In more detail
Code that builds functions from strings, such as new Function(), is also blocked without it. String-to-code functions are a common XSS path, so strict policies leave this keyword out.
Related terms
- eval() — The JavaScript function that runs a string as code.
- Content Security Policy — An HTTP response header that tells the browser which sources of scripts and other content a page may load, limiting what injected markup can do.
- 'unsafe-inline' — A CSP keyword that allows all inline scripts or styles, which removes most of the protection CSP offers against XSS.
Taught in
- Content Security Policy (CSP), Trusted Types And XSS Defenses — Frontend Architecture & Web Platform