Problem
Currently, html-dom-parser unsafely assigns strings to innerHtml. Browsers now support a method for developers to assert that any innerHtml has been sanitized and is safe to assign to innerHtml, in the form of TrustedTypes. See documentation here:
Suggested Solution
I can think of 2 ways to fix this:
- Allow the user to pass in a TrustedHTML object instead of a string. This would mean that the caller of html-dom-parser would do the sanitization, and then pass in a safe string into html-dom-parser.
- This strategy requires relaxing the check for
typeof "string" here in the code. However, we would also need to avoid any re-assigning of the html string, removing instances like this, which would make special character escapes hard to handle.
- Allow the user to pass in a TrustedTypePolicy, and then
html-dom-parser would run policy.createHtml(myString) before assigning anything to innerHtml.
Keywords
security, trustedtypes, innerhtml
Problem
Currently,
html-dom-parserunsafely assigns strings toinnerHtml. Browsers now support a method for developers to assert that anyinnerHtmlhas been sanitized and is safe to assign toinnerHtml, in the form of TrustedTypes. See documentation here:Suggested Solution
I can think of 2 ways to fix this:
typeof "string"here in the code. However, we would also need to avoid any re-assigning of the html string, removing instances like this, which would make special character escapes hard to handle.html-dom-parserwould runpolicy.createHtml(myString)before assigning anything toinnerHtml.Keywords
security, trustedtypes, innerhtml