Markdown Parsers Don't Stop XSS Attacks — Sanitization Is a Separate Step
Developers often assume a correctly functioning Markdown parser is sufficient protection against cross-site scripting (XSS), but parsing and sanitization are two distinct responsibilities. A Markdown parser determines what input means and converts it to HTML, while a sanitizer like DOMPurify enforces an allow-list of what that HTML is permitted to contain. Testing with Node.js, Marked, DOMPurify, and jsdom showed that valid parsed output can still carry dangerous event attributes, javascript: URL schemes, and DOM-clobbering name attributes unless explicitly stripped. Sanitization must occur after all HTML-transforming steps, since later plugins can reintroduce unsafe properties that an earlier sanitizer already removed. Security best practices recommend disabling raw HTML in Markdown where unnecessary, pinning sanitizer versions, and treating all externally sourced Markdown as untrusted by default.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in