Markdown and richtext previews rendered unsanitized HTML by default (stored XSS)
Description
The markdown and richtext widgets render their preview with dangerouslySetInnerHTML, and the serializer keeps raw HTML. Sanitizing that HTML with DOMPurify was opt-in (sanitize_preview: true), so by default any HTML in an entry, such as <img src=x onerror=...>, ran in the CMS origin when another user opened the entry. Anyone who could get content into the repository could therefore act with the viewing editor's backend token. That includes another editor or a merged pull request.
Patches
Fixed in decap-cms-widget-markdown 3.9.0 and decap-cms-widget-richtext 3.3.0, shipped in decap-cms-app and decap-cms 3.13.0: the preview is sanitized unless a field sets sanitize_preview: false. Setting it to false is a documented opt-out for trusted content and brings the behaviour back.
Workarounds
Set sanitize_preview: true on every markdown and richtext field.
Credits
Reported independently by several researchers before the fix shipped. The original report follows.
---
Summary
Stored Cross-Site Scripting (XSS) via Unsanitized HTML Preview in Markdown and Richtext Widgets.
An insecure default configuration in the preview components allows arbitrary JavaScript execution. Since sanitize_preview defaults to false, any user with content editing privileges can inject malicious scripts that execute in the browser of any user (including Administrators) who views the preview pane — without any interaction beyond opening the entry.
---
Affected Packages
| Package | Affected Versions | Latest Vulnerable |
|---|---|---|
decap-cms-widget-markdown | >= 3.0.0 | 3.8.0 |
decap-cms-widget-richtext | >= 3.2.0 | 3.2.1 |
---
Details
The vulnerability exists in the preview components for both Markdown and Richtext widgets. The rendering logic applies DOMPurify conditionally, but defaults to an unsafe state.
File 1: packages/decap-cms-widget-richtext/src/RichtextPreview.js — Lines 25, 64 File 2: packages/decap-cms-widget-markdown/src/MarkdownPreview.js — Lines 26, 28
// Line 25/26 — Vulnerable conditional (default is false = no sanitization)
const toRender = field?.get('sanitize_preview', false)
? DOMPurify.sanitize(html)
: html; // ← raw unsanitized HTML when sanitize_preview is not set
// Line 64/28 — Sink: raw HTML injected directly into the DOM
<div dangerouslySetInnerHTML={{ __html: toRender }} />Root Cause
The fallback value in field?.get('sanitize_preview', false) is false. Unless a developer explicitly enables sanitization in config.yml, the CMS renders raw HTML via dangerouslySetInnerHTML, bypassing all XSS filters. This is a Secure by Default violation — the safe behavior requires opt-in rather than opt-out.
---
Proof of Concept
Environment: Local Decap CMS v3.12.2 instance (no production systems accessed)
Steps to reproduce:
- Open the Decap CMS dashboard.
- Navigate to any collection using a Markdown or Richtext widget.
- In the editor field, input the following payload:
<img src=x onerror="alert('XSS Confirmed: ' + document.domain + ' | Cookies: ' + document.cookie)">- Observe the preview pane — JavaScript executes immediately without saving.
- Save the entry. Any editor or administrator who opens this entry will have the script executed in their session.
Expected behavior: Preview renders safe escaped HTML. Actual behavior: JavaScript executes in the preview pane.
---
Impact
Vulnerability Type: Stored Cross-Site Scripting (XSS) Affected Users: All CMS users — Administrators, Content Managers, Editors Severity: High CVSS v3.1 Score: 8.0 (AV:N/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:N)
An attacker with editor-level access could:
- Steal session tokens, cookies, or localStorage data (e.g., OAuth tokens stored by the CMS)
- Perform unauthorized admin actions (create users, delete content, modify settings)
- Redirect victims to phishing pages
- Establish persistent access by modifying saved content across multiple entries
---
Suggested Fix
Option 1 — Flip the default (recommended): Change false to true to enforce Secure by Default:
// packages/decap-cms-widget-richtext/src/RichtextPreview.js:25
// packages/decap-cms-widget-markdown/src/MarkdownPreview.js:26
const toRender = field?.get('sanitize_preview', true) // true = sanitize by default
? DOMPurify.sanitize(html)
: html;Option 2 — Remove the opt-out entirely (stronger): Always sanitize, remove the conditional:
const toRender = DOMPurify.sanitize(html); // always sanitize, no exceptionsAdditionally: Update SECURITY.md and field documentation to explicitly warn operators about sanitize_preview behavior.
---
Timeline
- Discovery date: 2026-04-17
- Report date: 2026-04-17
- Tested on: Decap CMS v3.12.2 (local environment only)
- No production systems were accessed or harmed during research.