Objects that parse or handle XML data can lead to XML external entity (XXE) attacks when they are not configured properly. Improper restriction of XML external entity processing can lead to server-side request forgery and information disclosure.
1var libxmljs = require("libxmljs");
2var fs = require('fs');
3function xmlExternalEntityNoncompliant() {
4 const xml = fs.readFileSync("foo.xml");
5 // Noncompliant: sets `noent` to true which enables the parsing of external entities.
6 const xmlDoc = libxmljs.parseXml(xml, { noent: true, noblanks: true });
7}
1var libxmljs = require("libxmljs");
2var fs = require('fs');
3function xmlExternalEntityCompliant() {
4 const xml = fs.readFileSync("foo.xml");
5 // Compliant: parsing of external entities is disabled by default.
6 const xmlDoc = libxmljs.parseXml(xml, { noblanks: true });
7}