-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle stack overflow of CVE-2022-41966.
- Loading branch information
Showing
6 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<html> | ||
<!-- | ||
Copyright (C) 2022 XStream committers. | ||
All rights reserved. | ||
The software in this package is published under the terms of the BSD | ||
style license a copy of which has been included with this distribution in | ||
the LICENSE.txt file. | ||
Created on 24. November 2022 by Joerg Schaible | ||
--> | ||
<head> | ||
<title>CVE-2022-41966</title> | ||
</head> | ||
<body> | ||
|
||
<h2 id="vulnerability">Vulnerability</h2> | ||
|
||
<p>CVE-2022-41966: XStream is vulnerable to a Denial of Service attack due to stack overflow.</p> | ||
|
||
<h2 id="affected_versions">Affected Versions</h2> | ||
|
||
<p>All versions until and including version 1.4.19 are affected, if using the version out of the box.</p> | ||
|
||
<h2 id="description">Description</h2> | ||
|
||
<p>The processed stream at unmarshalling time contains type information to recreate the formerly written objects. | ||
XStream creates therefore new instances based on these type information. An attacker can manipulate the processed | ||
input stream and replace or inject objects, that result in a stack overflow calculating a recursive hash set causing a | ||
denial of service.</p> | ||
|
||
<h2 id="reproduction">Steps to Reproduce</h2> | ||
|
||
<p>Create a simple HashSet and use XStream to marshal it to XML. Replace the XML with following snippet and | ||
unmarshal it with XStream:</p> | ||
<div class="Source XML"><pre><set> | ||
<set> | ||
<set> | ||
<set> | ||
<set> | ||
<set> | ||
<set> | ||
<string>a</string> | ||
</set> | ||
<set> | ||
<string>b</string> | ||
</set> | ||
</set> | ||
<set> | ||
<string>c</string> | ||
<set reference='../../../set/set[2]'/> | ||
</set> | ||
</set> | ||
</set> | ||
</set> | ||
</set> | ||
</set> | ||
</pre></div> | ||
<div class="Source Java"><pre>XStream xstream = new XStream(); | ||
xstream.fromXML(xml); | ||
</pre></div> | ||
|
||
<p>As soon as the XML gets unmarshalled, the recursive hash calculation is entered and the executing thread is | ||
aborted with a stack overflow error.</p> | ||
|
||
<h2 id="impact">Impact</h2> | ||
|
||
<p>The vulnerability may allow a remote attacker to terminate the application with a stack overflow error resulting | ||
in a denial of service only by manipulating the processed input stream.</p> | ||
|
||
<h2 id="workarounds">Workarounds</h2> | ||
|
||
<p>A simple solution is to catch the StackOverflowError in the client code calling XStream.</p> | ||
|
||
<p>If your object graph does not use referenced elements at all, you may simply set the NO_REFERENCE mode:</p> | ||
|
||
<div class="Source Java"><pre>XStream xstream = new XStream(); | ||
xstream.setMode(XStream.NO_REFERENCES); | ||
</pre></div> | ||
|
||
<p>If your object graph contains neither a Hashtable, HashMap nor a HashSet (or one of the linked variants of it) then you | ||
can use the security framework to deny the usage of these types:</p> | ||
|
||
<div class="Source Java"><pre>XStream xstream = new XStream(); | ||
xstream.denyTypes(new Class[]{ | ||
java.util.HashMap.class, java.util.HashSet.class, java.util.Hashtable.class, java.util.LinkedHashMap.class, java.util.LinkedHashSet.class | ||
}); | ||
</pre></div> | ||
|
||
<p>Unfortunately these types are very common. If you only use HashMap or HashSet and your XML refers these only as default | ||
map or set, you may additionally change the default implementation of java.util.Map and java.util.Set at unmarshalling time:</p> | ||
|
||
<div class="Source Java"><pre>xstream.addDefaultImplementation(java.util.TreeMap.class, java.util.Map.class); | ||
xstream.addDefaultImplementation(java.util.TreeSet.class, java.util.Set.class); | ||
</pre></div> | ||
|
||
<p>However, this implies that your application does not care about the implementation of the map and all elements are comparable.</p> | ||
|
||
<p>There is no known workaround to prevent this error except by catching the error in the code calling XStream.</p> | ||
|
||
<h2 id="credits">Credits</h2> | ||
|
||
<p>Lai Han of nsfocus security team found and reported the issue to XStream and provided the required information to reproduce it.</p> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters