/

CVE-2021-47837

Severity:

HIGH RISK

(7.2)

XSS in Markdownify Markdown Processing

CVE-2021-47837

Awaiting Analysis

Vulnerability type

Category:

Cross-Site Scripting (XSS)

CWE:

CWE-79

Impact:

Stored Cross-Site Scripting leading to client-side code execution

Severity:

HIGH RISK

(7.2)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Markdownify 1.2.0 contains a stored cross-site scripting vulnerability where malicious script content can be embedded in markdown files and rendered unsafely in the browser.

When a crafted markdown file is uploaded and later viewed, the embedded scripts can execute in the victim's browser, potentially leading to account compromise, data theft, or browser-based remote code execution via chained attacks.

Affected context

This vulnerability arises in applications that use Markdownify 1.2.0 to convert user-supplied markdown content into HTML and then render that HTML in a browser context.

It is most relevant where:

  • Users can upload or store markdown files or text that is later displayed to other users
  • The rendered HTML is inserted into pages with active JavaScript enabled
  • No robust HTML sanitization or output encoding is applied after markdown rendering

Exploit preconditions

  • Attack surface: Web applications or services that accept markdown content and render it in a browser using Markdownify 1.2.0.
  • Required access: Ability to submit or upload markdown content (e.g., as an authenticated user, contributor, or via any endpoint that accepts markdown).
  • Trigger point: A victim opens or views a page that displays the attacker-controlled markdown output converted to HTML.
  • Why exploitation is possible: The markdown-to-HTML conversion does not sufficiently neutralize or sanitize script-capable constructs, allowing attacker-controlled markup to be interpreted as executable JavaScript in the browser.

Why this happens

The core issue is improper neutralization of user-controlled content during markdown-to-HTML conversion, aligning with CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting).

Markdownify 1.2.0 allows certain HTML or script-like constructs to pass through the rendering pipeline without robust escaping or sanitization.

When this untrusted HTML is rendered in the browser, it is treated as active content instead of inert text, enabling arbitrary JavaScript execution under the origin of the vulnerable application.

Potential impact

  • Execution of arbitrary JavaScript in the victim's browser under the application's origin
  • Theft of session tokens, API keys stored in browser storage, or sensitive page data
  • Forged actions on behalf of the victim (e.g., changing settings, posting content, initiating transactions)
  • Installation of malicious browser-based payloads, or use as a step in broader remote code execution chains
  • Defacement of application content or injection of phishing interfaces within the legitimate site

General mitigation guidance

Effective mitigation focuses on treating all markdown-derived HTML as untrusted and ensuring it cannot execute arbitrary scripts:

  • Apply a robust HTML sanitization layer after markdown rendering, configured to strip or safely transform script-capable elements and dangerous attributes.
  • Use strict output encoding when injecting user-derived HTML into templates, especially in inline event handlers, URLs, or script-adjacent contexts.
  • Prefer markdown renderers and configuration modes that disable raw HTML by default, only allowing a minimal, well-audited subset of tags.
  • Enforce least-privilege browser behavior via Content Security Policy (CSP), disallowing inline scripts and restricting script sources to trusted origins.
  • Separate trusted administrative content from untrusted user-generated content, and avoid mixing them inside the same DOM containers when possible.

How teams detect issues like this

Organizations can identify and monitor for this class of vulnerability through:

  • Static analysis rules or linters that flag unsafe insertion of markdown-rendered HTML into the DOM without sanitization or encoding.
  • Code review checklists focused on user-generated content flows, verifying that all markdown output passes through a sanitization layer.
  • Differential testing where crafted markdown samples (containing script tags, event handlers, and JavaScript URLs) are rendered to ensure they are neutralized.
  • Runtime monitoring for anomalous inline script execution or DOM-based XSS indicators, augmented by CSP violation reporting.
  • Use of automated security scanning tools that crawl pages accepting markdown content and test for stored XSS behaviors.

Sources

SourceLink
github.comgithub.com/amitmerchant1990/electron-markdownify
imgur.comimgur.com/a/T4jBoiS
exploit-db.comexploit-db.com/exploits/49835
vulncheck.comvulncheck.com/advisories/markdownify-persistent-cross-site-scripting

Frequently asked

questions

Yes. Any remote user who can submit markdown content to an affected application may exploit the issue, and any other user who later views the rendered content can be impacted, subject to access controls and application-specific workflows.

Not necessarily. Exploitation typically requires only the level of access needed to submit or upload markdown content.

In many applications, this might be any authenticated user or, in some cases, even anonymous contributors if public submission is allowed.

The most robust pattern is to treat markdown-rendered HTML as untrusted: disable raw HTML where feasible, and apply strict server-side HTML sanitization after markdown processing, combined with conservative CSP and output encoding practices.

Establish a standard content-handling pipeline where all user-supplied rich text (including markdown) is:

  • Processed by libraries configured in a safe mode
  • Sanitized through a vetted, centrally managed sanitization component
  • Reviewed via security-focused code review and automated checks to ensure no direct insertion of unsanitized user content into the DOM.
Find out what's already
exploitable in your codebase.