diff --git a/cpp/ql/src/Security/CWE/CWE-611/XXE.qhelp b/cpp/ql/src/Security/CWE/CWE-611/XXE.qhelp index 1e859eb121f..a3121c2aebb 100644 --- a/cpp/ql/src/Security/CWE/CWE-611/XXE.qhelp +++ b/cpp/ql/src/Security/CWE/CWE-611/XXE.qhelp @@ -22,22 +22,18 @@ so unless you have explicitly enabled entity expansion, no further action needs

-The following example uses the libxml XML parser to parse a string xmlSrc. +The following example uses the Xerces-C++ XML parser to parse a string data. If that string is from an untrusted source, this code may be vulnerable to an XXE attack, since -the parser is invoked with the noent option set to true: +the parser is constructed in its default state with setDisableDefaultEntityResolution +set to false:

- +

-To guard against XXE attacks, the noent option should be omitted or set to -false. This means that no entity expansion is undertaken at all, not even for standard -internal entities such as & or >. If desired, these -entities can be expanded in a separate step using utility functions provided by libraries such -as underscore, -lodash or -he. +To guard against XXE attacks, the setDisableDefaultEntityResolution option should be +set to true.

- +
@@ -46,6 +42,10 @@ OWASP: XML External Entity (XXE) Processing.
  • +OWASP: +XML External Entity Prevention Cheat Sheet. +
  • +
  • Timothy Morgen: XML Schema, DTD, and Entity Attacks.
  • diff --git a/cpp/ql/src/Security/CWE/CWE-611/XXEBad.cpp b/cpp/ql/src/Security/CWE/CWE-611/XXEBad.cpp index 99fa02cc42f..9cfbbc49f05 100644 --- a/cpp/ql/src/Security/CWE/CWE-611/XXEBad.cpp +++ b/cpp/ql/src/Security/CWE/CWE-611/XXEBad.cpp @@ -1,7 +1,4 @@ -const app = require("express")(), - libxml = require("libxmljs"); -app.post("upload", (req, res) => { - let xmlSrc = req.body, - doc = libxml.parseXml(xmlSrc, { noent: true }); -}); +XercesDOMParser *parser = new XercesDOMParser(); + +parser->parse(data); // BAD (parser is not correctly configured, may expand external entity references) diff --git a/cpp/ql/src/Security/CWE/CWE-611/XXEGood.cpp b/cpp/ql/src/Security/CWE/CWE-611/XXEGood.cpp index 8317dcac98f..731d818aba9 100644 --- a/cpp/ql/src/Security/CWE/CWE-611/XXEGood.cpp +++ b/cpp/ql/src/Security/CWE/CWE-611/XXEGood.cpp @@ -1,7 +1,5 @@ -const app = require("express")(), - libxml = require("libxmljs"); -app.post("upload", (req, res) => { - let xmlSrc = req.body, - doc = libxml.parseXml(xmlSrc); -}); +XercesDOMParser *parser = new XercesDOMParser(); + +parser->setDisableDefaultEntityResolution(true); +parser->parse(data);