- 01Inspect the source
- 02Check the renderer
- 03Verify the destination
Each step answers a different question. Verify the final document in its actual destination.
Do not inject raw Markdown-parser output into a page and assume it is safe. A parser converts syntax into HTML; it does not necessarily remove dangerous markup. If documents can contain untrusted text or HTML, sanitize the resulting HTML with a maintained sanitizer, review every plugin that touches it, and test the final browser output.
Understand the rendering pipeline
A browser Markdown preview commonly follows this sequence:
- Parse: convert Markdown tokens into an HTML representation.
- Sanitize: remove HTML elements and attributes that should not reach the page.
- Enhance: render supported diagrams, math, media, or code highlighting.
- Insert: place the final approved output into the document.
Each later step can change the security properties of the content. Sanitizing before a plugin modifies HTML does not protect changes made afterward. An extension that generates SVG, adds links, or updates attributes belongs in the security review too.
OWASP recommends HTML sanitization when an application intentionally allows markup to be displayed, and names DOMPurify as a sanitizer option. It also warns that modifying sanitized output afterward can undermine the protection. Keep the sanitizer current and verify how the actual framework uses its output.
A safer implementation checklist
- Define the input boundary. Decide whether users can enter raw HTML, remote images, links, or embedded media. Do not assume a file extension tells you whether content is trusted.
- Sanitize the HTML that will be inserted. Use an established HTML sanitizer with an explicit policy appropriate for the preview. Escaping everything may break intended formatting; sanitizing markup is a separate operation.
- Review URL schemes and attributes. Check
href,src,target, and event-handler attributes. When opening external links in a new tab, set an appropriaterelvalue. - Keep sanitization after parsing. If a renderer or plugin mutates content afterward, sanitize the final output or ensure the transformation cannot introduce unsafe HTML.
- Handle SVG and embeds deliberately. Diagram output and media are richer than ordinary paragraphs. Limit allowed elements and attributes, and test each extension's generated DOM.
- Keep dependencies patched. Sanitizer bypasses and browser behavior evolve. Pin and update dependencies through the normal security review process.
- Use CSP as another layer. A Content Security Policy can reduce the impact of mistakes, but it is not a substitute for safe rendering or an excuse to allow unsafe content.
Test the rendered result
Test more than a parser's return string. Load the preview in a real browser and verify both that ordinary Markdown still works and that unwanted markup does not execute or navigate unexpectedly.
- Try ordinary headings, fenced code, links, images, tables, and every supported rich-content extension.
- Include hostile inline HTML and event-handler attributes in test fixtures; confirm the browser never executes them.
- Check dangerous URL schemes, new-tab link attributes, SVG output, and links generated by extensions.
- Run checks after changing the parser, sanitizer, extension configuration, or the code that inserts preview HTML.
- Inspect console errors and the resulting DOM. A screenshot alone cannot prove that generated markup is safe.
Keep security fixtures synthetic. Do not put private documents, API keys, or real user content into test logs or third-party analytics.
What Markups does today
The current Markups Markdown service parses documents with Marked and configured extensions, then passes parsed preview HTML through the project's sanitization helper before insertion. Mermaid diagrams are rendered with strict security settings, and generated SVG is sanitized again before it enters the preview. External rendered links receive noopener noreferrer; in-page anchors remain local.
This describes the code inspected on November 4, 2026; it is not a guarantee that every possible document or future extension is risk-free. Security depends on keeping the parser and sanitizer current and testing the complete path whenever it changes. See the public Markups Markdown service and its sanitization helper for the implementation.
Sources
- OWASP: Cross Site Scripting Prevention Cheat Sheet — covers HTML sanitization and safe handling of markup.
- DOMPurify project documentation — sanitizer usage, configuration, and maintenance.
- Marked documentation — documents the Markdown parser used by Markups.
Want to inspect a small example? Try it in a Markdown preview, then verify your publishing destination.