A content security policy lets pages run inline scripts or code built from strings

tx0/csharp:permissive-content-security-policyrecommendedwarningsecurity/configurationdepth fastsecurity, cwe-693

What it finds

A Content Security Policy tells the browser which scripts a page may run, so that markup injected into the page cannot run its own. 'unsafe-inline' in the policy for scripts allows exactly the inline scripts and event handlers an injection adds, and 'unsafe-eval' allows code built from strings; either leaves the policy without its main protection. Nonces or hashes allow chosen inline scripts instead.

Reported are string literals that hold a policy whose script-src directive, or its default-src when it has none, allows 'unsafe-inline' without a nonce, a hash or 'strict-dynamic', which make browsers ignore it, or allows 'unsafe-eval'.

From the rule's source, permissive_content_security_policy.rs.

Example from the rule's tests
using Microsoft.AspNetCore.Http; class Headers{    void Apply(HttpResponse response)    {        response.Headers["Content-Security-Policy"] = "default-src 'self'; script-src 'self' 'unsafe-inline'";tx0 reports: the policy allows 'unsafe-inline' for scripts        response.Headers["Content-Security-Policy"] = "default-src 'self' 'unsafe-eval'";tx0 reports: the policy allows 'unsafe-eval' for scripts        response.Headers["Content-Security-Policy"] = "default-src 'self'; style-src 'self' 'unsafe-inline'";        response.Headers["Content-Security-Policy"] = "script-src 'self' 'nonce-abc123' 'unsafe-inline'";        response.Headers["Content-Security-Policy"] = "default-src 'self'";    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/csharp:permissive-content-security-policy" = "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/csharp:permissive-content-security-policy] reason="..."

tx0 explain tx0/csharp:permissive-content-security-policy shows the same in the terminal. Found a false positive? Report it.