Skip to main content
HighClient-sideOWASP A03:2021CWE-79

How to fix: Markdown Rendered to innerHTML Without Sanitization

Markdown renderer output (marked()/markdown-it) is assigned directly to innerHTML or dangerouslySetInnerHTML with no visible DOMPurify/sanitize-html call nearby.

Why it matters

Markdown renderers pass raw HTML embedded in the source straight through by default, so any user-controlled markdown (comments, bios, README content) becomes a stored or reflected XSS vector.

Libraries like marked() and markdown-it render Markdown to an HTML string, but they do not sanitize that HTML unless explicitly configured to. AI-generated code frequently produces the 'render markdown to HTML, inject into the DOM' pattern without the accompanying sanitization step, since the happy-path demo works fine either way.

How to fix it

  1. 1Pipe the renderer's output through DOMPurify.sanitize() (or an equivalent) before assigning it to innerHTML.
  2. 2Alternatively, render Markdown to React elements/AST nodes instead of raw HTML strings, avoiding the sink entirely.
  3. 3Add an automated test asserting that a markdown payload containing <script> or an event handler attribute does not execute.

Code examples

Sanitize before rendering

JavaScript
import DOMPurify from 'dompurify';
el.innerHTML = DOMPurify.sanitize(marked(userMarkdown));

References

Detected automatically by VulnRadar. The check id is cs-unsanitized-markdown-render, stable across every scan so you can filter or diff on it.

See every client-side check

Questions

How severe is Markdown Rendered to innerHTML Without Sanitization?
VulnRadar rates this high severity in the client-side category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id cs-unsanitized-markdown-render, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Markdown Rendered to innerHTML Without Sanitization map to?
It maps to CWE-79. In the OWASP Top 10 it falls under A03:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for markdown rendered to innerhtml without sanitization

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

Markdown Rendered to innerHTML Without Sanitization | VulnRadar