-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathXXE.qhelp
More file actions
76 lines (67 loc) · 3.3 KB
/
XXE.qhelp
File metadata and controls
76 lines (67 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
<qhelp>
<overview>
<p>
Parsing untrusted XML files with a weakly configured XML parser may lead to an XML External Entity (XXE) attack. This type of attack
uses external entity references to access arbitrary files on a system, carry out denial of service, or server side
request forgery. Even when the result of parsing is not returned to the user, out-of-band
data retrieval techniques may allow attackers to steal sensitive data. Denial of services can also be
carried out in this situation.
</p>
<p>
There are many XML parsers for Java, and most of them are vulnerable to XXE because their default settings enable parsing of
external entities. This query currently identifies vulnerable XML parsing from the following parsers: <code>javax.xml.parsers.DocumentBuilder</code>,
<code>javax.xml.stream.XMLStreamReader</code>, <code>org.jdom.input.SAXBuilder</code>/<code>org.jdom2.input.SAXBuilder</code>,
<code>javax.xml.parsers.SAXParser</code>,<code>org.dom4j.io.SAXReader</code>, <code>org.xml.sax.XMLReader</code>,
<code>javax.xml.transform.sax.SAXSource</code>, <code>javax.xml.transform.TransformerFactory</code>,
<code>javax.xml.transform.sax.SAXTransformerFactory</code>, <code>javax.xml.validation.SchemaFactory</code>,
<code>javax.xml.bind.Unmarshaller</code> and <code>javax.xml.xpath.XPathExpression</code>.
</p>
</overview>
<recommendation>
<p>
The best way to prevent XXE attacks is to disable the parsing of any Document Type Declarations (DTDs) in untrusted data.
If this is not possible you should disable the parsing of external general entities and external parameter entities.
This improves security but the code will still be at risk of denial of service and server side request forgery attacks.
Protection against denial of service attacks may also be implemented by setting entity expansion limits, which is done
by default in recent JDK and JRE implementations.
</p>
</recommendation>
<example>
<p>
The following example calls <code>parse</code> on a <code>DocumentBuilder</code> that is not safely configured on
untrusted data, and is therefore inherently unsafe.
</p>
<sample src="XXEBad.java" />
<p>
In this example, the <code>DocumentBuilder</code> is created with DTD disabled, securing it against XXE attack.
</p>
<sample src="XXEGood.java" />
</example>
<references>
<li>
OWASP vulnerability description:
<a href="https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing">XML External Entity (XXE) Processing</a>.
</li>
<li>
OWASP guidance on parsing xml files:
<a href="https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet#Java">XXE Prevention Cheat Sheet</a>.
</li>
<li>
Paper by Timothy Morgen:
<a href="https://www.vsecurity.com//download/publications/XMLDTDEntityAttacks.pdf">XML Schema, DTD, and Entity Attacks</a>
</li>
<li>
Out-of-band data retrieval: Timur Yunusov & Alexey Osipov, Black hat EU 2013:
<a href="https://media.blackhat.com/eu-13/briefings/Osipov/bh-eu-13-XML-data-osipov-slides.pdf">XML Out-Of-Band Data Retrieval</a>.
</li>
<li>
Denial of service attack (Billion laughs):
<a href="https://en.wikipedia.org/wiki/Billion_laughs">Billion Laughs.</a>
</li>
<li>
The Java Tutorials:
<a href="https://docs.oracle.com/javase/tutorial/jaxp/limits/limits.html">Processing Limit Definitions.</a>
</li>
</references>
</qhelp>