Skip to content

Commit 8aa2c23

Browse files
authored
Merge pull request github#11700 from JLLeitschuh/doc/JLL/improve-java-unsafe-deserialization-documentation
[Java] Document fixes for deserialization vulnerabilities by framework
2 parents aefb433 + 09d8a50 commit 8aa2c23

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

java/ql/src/Security/CWE/CWE-502/UnsafeDeserialization.qhelp

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,52 @@ for example JSON or XML. However, these formats should not be deserialized
2828
into complex objects because this provides further opportunities for attack.
2929
For example, XML-based deserialization attacks
3030
are possible through libraries such as XStream and XmlDecoder.
31-
31+
</p>
32+
<p>
3233
Alternatively, a tightly controlled whitelist can limit the vulnerability of code, but be aware
3334
of the existence of so-called Bypass Gadgets, which can circumvent such
3435
protection measures.
3536
</p>
37+
<p>
38+
Recommendations specific to particular frameworks supported by this query:
39+
</p>
40+
<p><b>FastJson</b> - <code>com.alibaba:fastjson</code></p>
41+
<ul>
42+
<li><b>Secure by Default</b>: Partially</li>
43+
<li><b>Recommendation</b>: Call <code>com.alibaba.fastjson.parser.ParserConfig#setSafeMode</code> with the argument <code>true</code> before deserializing untrusted data.</li>
44+
</ul>
45+
<p></p>
46+
<p><b>FasterXML</b> - <code>com.fasterxml.jackson.core:jackson-databind</code></p>
47+
<ul>
48+
<li><b>Secure by Default</b>: Yes</li>
49+
<li><b>Recommendation</b>: Don't call <code>com.fasterxml.jackson.databind.ObjectMapper#enableDefaultTyping</code> and don't annotate any object fields with <code>com.fasterxml.jackson.annotation.JsonTypeInfo</code> passing either the <code>CLASS</code> or <code>MINIMAL_CLASS</code> values to the annotation.
50+
Read <a href="https://cowtowncoder.medium.com/jackson-2-10-safe-default-typing-2d018f0ce2ba">this guide</a>.</li>
51+
</ul>
52+
<p></p>
53+
<p><b>Kryo</b> - <code>com.esotericsoftware:kryo</code> and <code>com.esotericsoftware:kryo5</code></p>
54+
<ul>
55+
<li><b>Secure by Default</b>: Yes for <code>com.esotericsoftware:kryo5</code> and for <code>com.esotericsoftware:kryo</code> >= v5.0.0</li>
56+
<li><b>Recommendation</b>: Don't call <code>com.esotericsoftware.kryo(5).Kryo#setRegistrationRequired</code> with the argument <code>false</code> on any <code>Kryo</code> instance that may deserialize untrusted data.</li>
57+
</ul>
58+
<p></p>
59+
<p><b>ObjectInputStream</b> - <code>Java Standard Library</code></p>
60+
<ul>
61+
<li><b>Secure by Default</b>: No</li>
62+
<li><b>Recommendation</b>: Use a validating input stream, such as <code>org.apache.commons.io.serialization.ValidatingObjectInputStream</code>.</li>
63+
</ul>
64+
<p></p>
65+
<p><b>SnakeYAML</b> - <code>org.yaml:snakeyaml</code></p>
66+
<ul>
67+
<li><b>Secure by Default</b>: No</li>
68+
<li><b>Recommendation</b>: Pass an instance of <code>org.yaml.snakeyaml.constructor.SafeConstructor</code> to <code>org.yaml.snakeyaml.Yaml</code>'s constructor before using it to deserialize untrusted data.</li>
69+
</ul>
70+
<p></p>
71+
<p><b>XML Decoder</b> - <code>Standard Java Library</code></p>
72+
<ul>
73+
<li><b>Secure by Default</b>: No</li>
74+
<li><b>Recommendation</b>: Do not use with untrusted user input.</li>
75+
</ul>
76+
<p></p>
3677
</recommendation>
3778

3879
<example>
@@ -74,7 +115,7 @@ Alvaro Muñoz &amp; Christian Schneider, RSAConference 2016:
74115
</li>
75116
<li>
76117
SnakeYaml documentation on deserialization:
77-
<a href="https://bitbucket.org/asomov/snakeyaml/wiki/Documentation#markdown-header-loading-yaml">SnakeYaml deserialization</a>.
118+
<a href="https://bitbucket.org/snakeyaml/snakeyaml/wiki/Documentation#markdown-header-loading-yaml">SnakeYaml deserialization</a>.
78119
</li>
79120
<li>
80121
Hessian deserialization and related gadget chains:

0 commit comments

Comments
 (0)