Improper Input Validation Affecting xmldom package, versions *
Threat Intelligence
Do your applications use this vulnerable package?
In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.
Test your applications- Snyk ID SNYK-JS-XMLDOM-3092935
- published 2 Nov 2022
- disclosed 1 Nov 2022
- credit frumioj, karfau
Introduced: 1 Nov 2022
CVE-2022-39353 Open this link in a new tabHow to fix?
There is no fixed version for xmldom
.
Overview
xmldom is an A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.
Affected versions of this package are vulnerable to Improper Input Validation due to parsing XML that is not well-formed, and contains multiple top-level elements. All the root nodes are being added to the childNodes
collection of the Document
, without reporting or throwing any error.
Workarounds
One of the following approaches might help, depending on your use case:
Instead of searching for elements in the whole DOM, only search in the
documentElement
.Reject a document with a document that has more than 1
childNode
.
PoC
var DOMParser = require('xmldom').DOMParser;
var xmlData = '<?xml version="1.0" encoding="UTF-8"?>\n' +
'<root>\n' +
' <branch girth="large">\n' +
' <leaf color="green" />\n' +
' </branch>\n' +
'</root>\n' +
'<root>\n' +
' <branch girth="twig">\n' +
' <leaf color="gold" />\n' +
' </branch>\n' +
'</root>\n';
var xmlDOM = new DOMParser().parseFromString(xmlData);
console.log(xmlDOM.toString());
This will result with the following output:
<?xml version="1.0" encoding="UTF-8"?><root>
<branch girth="large">
<leaf color="green"/>
</branch>
</root>
<root>
<branch girth="twig">
<leaf color="gold"/>
</branch>
</root>