Security rules

NGB019: Unsafe CSP / Trusted Types policy

Evaluates Content Security Policies that are statically visible in the repository — <meta http-equiv="Content-Security-Policy"> in the project index.html, constant header values set in TypeScript (e.g.

Property Value
Rule ID NGB019
Category Security configuration
Default severity medium
CWE CWE-693
Built-in presets recommended: warn, strict: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Evaluates Content Security Policies that are statically visible in the repository — <meta http-equiv="Content-Security-Policy"> in the project index.html, constant header values set in TypeScript (e.g. an SSR server.ts), and hosting configs (firebase.json, vercel.json, staticwebapp.config.json, _headers) — and reports risky directives. When no policy is observable, it emits a csp-not-assessed diagnostic instead of a finding.

Why it matters

A strict CSP with Trusted Types is the main browser-side mitigation if an XSS bug slips through. unsafe-inline without nonces, unsafe-eval, wildcard script sources or permissive Trusted Types settings remove most of that protection.

Detection behavior and supported patterns

  • script-src (or default-src fallback) with 'unsafe-inline' and no nonce/hash
  • 'unsafe-eval'; '*', 'http:', 'https:', 'data:', 'blob:' script sources (host sources are tolerated with 'strict-dynamic' + nonce/hash)
  • missing object-src 'none' (low)
  • trusted-types with '*' or 'allow-duplicates' (medium); 'angular#unsafe-bypass' and trusted-types without require-trusted-types-for (informational)
  • angular.json security.autoCsp: true is recognized as an observed, hash-based policy

Example

TypeScript
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline' 'unsafe-eval'">

Safer alternative

TypeScript
"security": { "autoCsp": true }   // angular.json build options

Remediation

Enable Angular security.autoCsp or serve a nonce-based policy: script-src 'nonce-…' 'strict-dynamic'; object-src 'none'; base-uri 'self'; require-trusted-types-for 'script'; trusted-types angular. Remove 'unsafe-eval' and 'unsafe-inline'.

False-positive considerations

  • A meta CSP that is replaced by a stricter header at deploy time is still reported; prefer keeping one source of truth.

Known limitations

  • Production HTTP response headers (CDN, reverse proxy, server config outside the repo) cannot be seen; their absence is reported as "not assessed", never as missing CSP.
  • Structured header builders (e.g. helmet contentSecurityPolicy.directives) and dynamically built header strings are not evaluated; dynamic values produce an informational diagnostic.
  • Report-only policies are ignored because they do not enforce anything.

References

Run it

Shell
ngbastion explain NGB019