A content security policy allows inline script or eval
What it finds
A Content Security Policy is the last line of defence against injected script. The sources 'unsafe-inline' and 'unsafe-eval' in its script directives allow exactly the inline script and eval that an injection relies on.
Reported are the string literals 'unsafe-inline' and 'unsafe-eval' in the value of a scriptSrc, script-src, defaultSrc or default-src property, alone or in a list, as helmet and similar middleware take the directives, and in a literal Content-Security-Policy header value.
From the rule's source, csp_unsafe_source.rs.
import helmet from "helmet";export const policy = helmet({ contentSecurityPolicy: { directives: { scriptSrc: ["'self'", "'unsafe-inline'"],tx0 reports: 'unsafe-inline' allows the script styleSrc: ["'self'", "'unsafe-inline'"], }, },});export const headers = { "Content-Security-Policy": "default-src 'self'; script-src 'self' 'unsafe-eval'" };tx0 reports: this policy allows eval Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:csp-unsafe-source" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:csp-unsafe-source] reason="..."tx0 explain tx0/ts:csp-unsafe-source shows the same in the terminal. Found a false positive? Report it.