# GHSA-38W6-4FQR-X68Q: Markdown and richtext previews rendered unsanitized HTML by default (stored XSS)

- Database: GitHub
- Severity: CVSS 7.3 (High)
- Published: 2026-10-26
- Modified: 2026-10-26

## Affected versions

- decap-cms-widget-markdown (npm): fixed in 3.9.0
- decap-cms-widget-richtext (npm): fixed in 3.3.0
- decap-cms-app (npm): fixed in 3.13.0
- decap-cms (npm): fixed in 3.13.0

## Description

## Summary

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

```javascript
// 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:**
1. Open the Decap CMS dashboard.
2. Navigate to any collection using a Markdown or Richtext widget.
3. In the editor field, input the following payload:
```html
<img src=x onerror="alert('XSS Confirmed: ' + document.domain + ' | Cookies: ' + document.cookie)">
```
4. Observe the preview pane — JavaScript executes immediately without saving.
5. 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:

```javascript
// 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:

```javascript
const toRender = DOMPurify.sanitize(html); // always sanitize, no exceptions
```

**Additionally:** 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.**

## References

- https://github.com/decaporg/decap-cms/security/advisories/GHSA-38w6-4fqr-x68q

Page: https://cve.now/GHSA-38W6-4FQR-X68Q

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
