Skip to content

Commit 329a070

Browse files
authored
Document security considerations for XMLParser usage
Add security note regarding prototype pollution vulnerabilities in XML parsing.
1 parent 44af544 commit 329a070

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

docs/v4/Security.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
As many security vulnerability has been raised for prototype pollution, this is an important note that the following code is not the security vulnerability
2+
3+
```js
4+
const { XMLParser } = require("fast-xml-parser");
5+
6+
const xml = `<root>
7+
<constructor>pwned</constructor>
8+
</root>`;
9+
10+
const parser = new XMLParser();
11+
const result = parser.parse(xml);
12+
13+
const rootObj = result.root;
14+
console.log(rootObj.constructor); // "pwned" (should be [Function: Object])
15+
console.log(rootObj.constructor === Object); // false
16+
17+
// downstream impact:
18+
try {
19+
console.log(rootObj.constructor.name); // throws TypeError
20+
} catch (e) {
21+
console.log(e.message); // Cannot read properties of undefined
22+
}
23+
```
24+
25+
- Unreasonable use of the library
26+
- Don't let user to inject any malicious code or information
27+
- Don't leak any sensitive information like server detail, user data, app data etc.
28+

0 commit comments

Comments
 (0)