-
-
Save camelcaseblog/3634cc9c4d50825295a52e56cd7c906c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sanitizeHtml = require("sanitize-html") | |
const evilHtml = ` | |
<img | |
id="xss-image" | |
src="/" | |
onerror="d = document; | |
c = ('cooki' + 'e').trim(); | |
qs = 'queryS' + 'elector'; | |
console.log(d[c]); | |
d[qs + 'All']('.top_nlsitem').forEach(n => n.style.backgroundColor = 'green'); | |
d[qs]('#xss-image').src = 'ht' + 'tps://upload.wikimedia.org/wikipedia/commons/c/ca/1x1.png';" | |
/> | |
` | |
const legitHtml = sanitizeHtml(evilHtml, { allowedTags: "img" }) | |
console.log(legitHtml) | |
/* Output: | |
"\n<img src=\"/\" />\n" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment