Rendering Markdown comments safely: setHTML(), DOMPurify, and Trusted Types

Title “Rendering Markdown Comments Safely: setHTML(), DOMPurify, and Trusted Types”, code windows render-comment.js and render-comment-server.js, and a round photo of a person.

Agustin Barrientos shows how marked.js keeps raw HTML in comments and why “we sanitize” means little when library defaults differ so much. He defines one explicit allowlist in the SanitizerConfig format, uses it with setHTML() where available and DOMPurify as a fallback, and enforces Trusted Types so no one can bypass it with a raw innerHTML assignment.

agustinbarrientos.com/writing/senior-eye/rendering-markdown-comments-safely