Skip to content

Commit dfd846b

Browse files
committed
C++: Changes to the qhelp.
1 parent d83aea5 commit dfd846b

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

cpp/ql/src/Security/CWE/CWE-611/XXE.qhelp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,18 @@ so unless you have explicitly enabled entity expansion, no further action needs
2222

2323
<example>
2424
<p>
25-
The following example uses the <code>libxml</code> XML parser to parse a string <code>xmlSrc</code>.
25+
The following example uses the <code>Xerces-C++</code> XML parser to parse a string <code>data</code>.
2626
If that string is from an untrusted source, this code may be vulnerable to an XXE attack, since
27-
the parser is invoked with the <code>noent</code> option set to <code>true</code>:
27+
the parser is constructed in its default state with <code>setDisableDefaultEntityResolution</code>
28+
set to <code>false</code>:
2829
</p>
29-
<sample src="examples/Xxe.js"/>
30+
<sample src="XXEBad.cpp"/>
3031

3132
<p>
32-
To guard against XXE attacks, the <code>noent</code> option should be omitted or set to
33-
<code>false</code>. This means that no entity expansion is undertaken at all, not even for standard
34-
internal entities such as <code>&amp;amp;</code> or <code>&amp;gt;</code>. If desired, these
35-
entities can be expanded in a separate step using utility functions provided by libraries such
36-
as <a href="http://underscorejs.org/#unescape">underscore</a>,
37-
<a href="https://lodash.com/docs/4.17.15#unescape">lodash</a> or
38-
<a href="https://github.com/mathiasbynens/he">he</a>.
33+
To guard against XXE attacks, the <code>setDisableDefaultEntityResolution</code> option should be
34+
set to <code>true</code>.
3935
</p>
40-
<sample src="examples/XxeGood.js"/>
36+
<sample src="XXEGood.cpp"/>
4137
</example>
4238

4339
<references>
@@ -46,6 +42,10 @@ OWASP:
4642
<a href="https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing">XML External Entity (XXE) Processing</a>.
4743
</li>
4844
<li>
45+
OWASP:
46+
<a href="https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html">XML External Entity Prevention Cheat Sheet</a>.
47+
</li>
48+
<li>
4949
Timothy Morgen:
5050
<a href="https://research.nccgroup.com/2014/05/19/xml-schema-dtd-and-entity-attacks-a-compendium-of-known-techniques/">XML Schema, DTD, and Entity Attacks</a>.
5151
</li>
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
const app = require("express")(),
2-
libxml = require("libxmljs");
31

4-
app.post("upload", (req, res) => {
5-
let xmlSrc = req.body,
6-
doc = libxml.parseXml(xmlSrc, { noent: true });
7-
});
2+
XercesDOMParser *parser = new XercesDOMParser();
3+
4+
parser->parse(data); // BAD (parser is not correctly configured, may expand external entity references)
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
const app = require("express")(),
2-
libxml = require("libxmljs");
31

4-
app.post("upload", (req, res) => {
5-
let xmlSrc = req.body,
6-
doc = libxml.parseXml(xmlSrc);
7-
});
2+
XercesDOMParser *parser = new XercesDOMParser();
3+
4+
parser->setDisableDefaultEntityResolution(true);
5+
parser->parse(data);

0 commit comments

Comments
 (0)