Trusted Types Policy Builder
Generate CSP require-trusted-types-for and trusted-types directives with policy names — a modern anti-XSS mitigation.
—
Trusted Types: closing innerHTML for good
Most DOM-based XSS comes in through a handful of known sinks: innerHTML, outerHTML, document.write, a script src, eval. Trusted Types is the browser mechanism that closes all of them at once — with the policy on, assigning a plain string to any of those sinks throws. Only an object created by a policy you declared gets through.
List the policy names your application creates and the page assembles the header: the trusted-types directive with the allowed names, plus require-trusted-types-for with the value script, which is what actually turns the enforcement on. There is also the option to allow duplicate names, useful when the same code loads twice, and to emit in report-only mode with a report-to destination.
The adoption path that usually works is report mode first. You ship the Report-Only header, let it run for a few days and collect the sinks that would have been blocked — almost always a third-party library nobody remembered writes HTML directly. Only after cleaning those up is it worth switching to the enforcing header.
Frequently asked questions
Does it work in every browser?
Do I need a policy named default?
Does this replace a sanitiser library?
Related Tools
Content-Security-Policy Builder
Build a Content-Security-Policy header by adding directives (default-src, script-src, img-src, frame-ancestors) with predefined sources.
Basic CSP Evaluator
Evaluates a Content-Security-Policy directive reporting unsafe-inline, unsafe-eval or wildcard issues.
Secure CSP Nonce Generator
Generate a 128-bit base64 random nonce for Content-Security-Policy with sample header and <script nonce> attribute.
Permissions-Policy Builder
Builds the Permissions-Policy header from a list of feature=allowlist entries (e.g. geolocation=()).
TOTP otpauth URI Builder
Builds an otpauth://totp/ URI with issuer, account, base32 secret, digits and period for QR code apps.
Network Error Logging (NEL) Builder
Build NEL and Report-To headers to send network error reports to your own endpoint with sampling fractions.