CVE-2022-40151
Vulnerability
CVE-2022-40151: XStream is vulnerable to a Denial of Service attack due to stack overflow.
Affected Versions
All versions until and including version 1.4.19 are affected, if using the version out of the box.
Description
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 due to deeply nested objects causing a denial of service.
Steps to Reproduce
Create a simple HashSet and use XStream to marshal it to XML. Replace the XML with generated with the following code snippet and unmarshal it with XStream:
String xml = new String(); int i = 0; for( ; i < 10000; ++i) { xml += "<set>"; } for( ; i > 0; --i) { xml += "</set>"; }
XStream xstream = new XStream(); xstream.fromXML(xml);
As soon as the XML gets unmarshalled, the recursion is too deep and the executing thread is aborted with a stack overflow error.
Impact
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.
Workarounds
The only solution is to catch the StackOverflowError in the client code calling XStream.
Credits
Henry Lin of the Google OSS-Fuzz team found and reported the issue to XStream and provided the required information to reproduce it.