Skip to main content
HeadersMedium PriorityFree

Trusted Types readiness

Updated November 2026·SecScanner Team

Trusted Types is a browser API that helps prevent DOM-based XSS by requiring typed objects for dangerous DOM operations.

97% of the 101 most-visited sites we scan fail this check. See the full data.

Results in 1–3 minutes · Free · No signup required

Why It Matters

DOM-based XSS is difficult to detect and prevent with traditional CSP. Trusted Types provides an additional layer of protection by enforcing type-safe DOM manipulation.

How We Check

We check if your CSP includes require-trusted-types-for directive and whether your site would be compatible with Trusted Types enforcement.

Good vs Bad Values

Good and bad values for Trusted Types readiness
ValueVerdictWhy
Content-Security-Policy: require-trusted-types-for 'script'GoodDangerous DOM sinks such as innerHTML, document.write and script.src reject plain strings and only accept Trusted Types objects. This is the directive the scanner looks for.
require-trusted-types-for 'script'; trusted-types app-policy dompurifyGoodEnforcement plus an allowlist of policy names, so only code you named can create Trusted Types objects.
require-trusted-types-for 'script'; trusted-types defaultGoodA catch-all default policy sanitizes strings automatically. Handy for migrating legacy code, but the default policy then becomes a security-critical function.
require-trusted-types-for 'script'; trusted-types 'none'GoodNo policies may be created, so every sink assignment fails. Strictest option, realistic only for code that already avoids those sinks.
trusted-types app-policy (without require-trusted-types-for)WeakThis only limits which policy names may be created. Nothing forces sinks to demand typed values, so no DOM XSS protection results.
Content-Security-Policy-Report-Only: require-trusted-types-for 'script'WeakThe right first step in a rollout: violations are reported and nothing breaks. It does not enforce, and the scanner reads only the enforcing header.
require-trusted-types-for script (no quotes)BadThe keyword must be quoted as 'script'. Without the quotes the directive is invalid and ignored.
No Content-Security-Policy headerBadTrusted Types is delivered through CSP, so with no CSP there is nothing to enforce.
CSP present, no require-trusted-types-for directiveBadThe site has CSP but string-based DOM sinks remain open to DOM-based XSS.

How to Fix

Add require-trusted-types-for 'script' to your CSP. Create Trusted Type policies for legitimate DOM operations. Test in report-only mode first.

1. Report-only first (Nginx). Collect violations for a week or two before enforcing:

add_header Content-Security-Policy-Report-Only "require-trusted-types-for 'script'; report-uri /csp-report" always;

2. Create a policy in your own code and use it everywhere a string becomes HTML or a script URL. DOMPurify supports Trusted Types directly:

const policy = window.trustedTypes?.createPolicy("app-policy", {
  createHTML: (input) => DOMPurify.sanitize(input),
});
el.innerHTML = policy ? policy.createHTML(userHtml) : DOMPurify.sanitize(userHtml);

3. Enforce. Apache:

Header always append Content-Security-Policy "require-trusted-types-for 'script'; trusted-types app-policy dompurify"

Next.js — merge the directives into the CSP you already build per request (typically in middleware.ts), keeping a single Content-Security-Policy header:

const csp = [
  "default-src 'self'",
  `script-src 'self' 'nonce-${nonce}' 'strict-dynamic'`,
  "require-trusted-types-for 'script'",
  "trusted-types app-policy nextjs#bundler",
].join("; ");

Next.js and webpack-based builds register their own policy names (for example nextjs#bundler), so list the ones your bundle creates in trusted-types; the console violation report names any that are missing. Cloudflare: add the same directives through a Response Header Transform Rule only if your CSP is static; nonce-based policies belong in the application.

Verify in DevTools: run document.body.innerHTML = 'x'. With enforcement active the assignment throws a TypeError saying the sink requires TrustedHTML.

Common Mistakes

  • Enforcing immediately. Any library that assigns a string to `innerHTML`, builds script URLs or calls `eval` throws, and the page breaks. Start with `Content-Security-Policy-Report-Only` and fix what the reports list.
  • Writing a policy that returns its input unchanged (`createHTML: (s) => s`). The type checks pass, the sanitization does not exist, and the protection is only cosmetic.
  • Skipping third-party code. Analytics, tag managers, chat widgets and A/B-testing snippets often write to `innerHTML`; they need their own policy names in `trusted-types` or a default policy.
  • Treating Trusted Types as a replacement for a script-source CSP. It narrows DOM-based XSS; you still need `script-src` with nonces or hashes against injected script tags.
  • Assuming every browser enforces it. Support began in Chromium and has been spreading to other engines; where the directive is unknown it is ignored, which makes it a safe hardening layer but not a guarantee for every visitor.
  • Using a framework's escape hatch (`dangerouslySetInnerHTML`, `v-html`, `bypassSecurityTrustHtml`) with unsanitized content. Trusted Types makes those call sites visible, so route them through one reviewed policy.

Frequently Asked Questions

What is Trusted Types readiness?

Trusted Types is a browser API that helps prevent DOM-based XSS by requiring typed objects for dangerous DOM operations.

Why does Trusted Types readiness matter for website security?

DOM-based XSS is difficult to detect and prevent with traditional CSP. Trusted Types provides an additional layer of protection by enforcing type-safe DOM manipulation.

How do I fix Trusted Types readiness issues?

Add require-trusted-types-for 'script' to your CSP. Create Trusted Type policies for legitimate DOM operations. Test in report-only mode first.

Related Security Checks

Check Your Website Now

Run a free security scan to check for Trusted Types readiness issues and 61 other security checks.

Scan Your Website Free