Trusted Types
A browser security feature that makes dangerous DOM sinks such as innerHTML reject plain strings and accept only values produced by a policy you define.
In more detail
Enable it with the CSP directive require-trusted-types-for 'script'. You create policies with trustedTypes.createPolicy, whose functions sanitize input and return TrustedHTML; assigning a raw string then throws a TypeError, so every risky path is forced through reviewed code.
Related terms
- injection sink — A place in code where a string is interpreted as HTML or code, such as innerHTML, document.write or eval, and so can run an attack if the string is untrusted.
- DOM-based XSS — Cross-site scripting that happens entirely in the browser, when page JavaScript copies attacker-controlled data, such as part of the URL, into a dangerous sink.
- sanitization — Cleaning untrusted input by removing or neutralising anything dangerous, such as script tags and event attributes in HTML.
- Content Security Policy — An HTTP response header that tells the browser which sources of scripts and other content a page may load, limiting what injected markup can do.
Taught in
- Content Security Policy (CSP), Trusted Types And XSS Defenses — Frontend Architecture & Web Platform