You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ensure that HTML assignments are done through TrustedHTML #1877
When using a content security policy (see policy below), I get an error like this:
docsify.js:8535 This document requires 'TrustedHTML' assignment.
_renderTo @ docsify.js:8535
initRender @ docsify.js:8729
Docsify @ docsify.js:9247
(anonymous) @ docsify.js:9277
docsify.js:8535
Uncaught TypeError: Failed to set the 'outerHTML' property on 'Element': This document requires 'TrustedHTML' assignment.
at Docsify._renderTo (docsify.js:8535:53)
at Docsify.initRender (docsify.js:8729:16)
at new Docsify (docsify.js:9247:12)
at HTMLDocument.<anonymous> (docsify.js:9277:39)
If I remove the trused type policy from the header I still get this error:
docsify.js:8535
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src cdn.jsdelivr.net 'self' ". Either the 'unsafe-inline' keyword, a hash ('sha256-6h52w3SLKvExCLgdk907pJwQu8hZtVM4QMirrrfKGaI='), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present.
Line 8535 is an assignment to innerHTML/outerHTML adding a SHA to script tag generated by docsify internals is not possibility.
Steps to reproduce
Enable custom response headers on your server. Use the following Content Security Policy:
tl;dr Define a Trusted Types policy (where you sanitize incoming html, say, with dom-purify). Ensure all HTML assignments such as Line 8535 in docsify.js 4.12.2 are done through the trusted type function and not directly.
Even on Firefox, I am seeing CSP violations thrown as errors and Docsify does not load. I am not sure how to get around CSP violations other than defining a Trusted Types policy (except for defining 'unsafe-inline' and thus negating the purpose of a CSP).
Security is not my area of expertise, unfortunately :(.
Activity
trusktr commentedon Sep 7, 2022
What's the fix that Docsify needs?
CxRes commentedon Sep 7, 2022
tl;dr Define a Trusted Types policy (where you sanitize incoming html, say, with dom-purify). Ensure all HTML assignments such as Line 8535 in docsify.js 4.12.2 are done through the trusted type function and not directly.
Long version by one of the developers of this technique https://web.dev/trusted-types/
trusktr commentedon Sep 7, 2022
Trusted Types isn't in Firefox or Safari yet. EDIT: there's a polyfill.
CxRes commentedon Sep 7, 2022
Even on Firefox, I am seeing CSP violations thrown as errors and Docsify does not load. I am not sure how to get around CSP violations other than defining a Trusted Types policy (except for defining
'unsafe-inline'and thus negating the purpose of a CSP).Security is not my area of expertise, unfortunately :(.