Loading...
const html = await res.text();
el.innerHTML = html;const policy = trustedTypes.createPolicy('sanitize', {
createHTML: (s) => DOMPurify.sanitize(s),
});
const html = await res.text();
el.innerHTML = policy.createHTML(html);With Trusted Types enforced, innerHTML accepts only values from a policy, so every HTML string goes through the sanitizer.
require-trusted-types-for 'script'.trustedTypes.createPolicy() sanitize input, they do not return it unchanged.trusted-types directive lists the allowed policy names.No. They force every value for a dangerous sink to go through a policy, and the policy itself must still sanitize.
Send require-trusted-types-for 'script' in a Content-Security-Policy-Report-Only header first, fix the reported violations, then enforce.
HTML sinks like innerHTML and insertAdjacentHTML, script sinks like eval(), and script URL sinks like script.src.