CVE-2021-39140: XStream is vulnerable to a Denial of Service attack.

Affected Versions

All versions until and including version 1.4.17 are affected, if using the version out of the box. No user is affected, who followed the recommendation to setup XStream's security framework with a whitelist limited to the minimal required types.


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 an endless loop probably causing a denial of service.

Steps to Reproduce

Create a simple TreeSet and use XStream to marshal it to XML. Replace the XML with following snippet and unmarshal it again with XStream:

  <sun.reflect.annotation.AnnotationInvocationHandler serialization='custom'>
        <memberValues class='javax.script.SimpleBindings'>
          <map class='javax.script.SimpleBindings' reference='..'/>
XStream xstream = new XStream();

As soon as the XML gets unmarshalled, an endless loop is entered and the executing thread consumes maximum CPU time and will never return.

Note, this example uses XML, but the attack can be performed for any supported format. e.g. JSON.


The vulnerability may allow a remote attacker to allocate 100% CPU time on the target system depending on CPU type or parallel execution of such a payload resulting in a denial of service only by manipulating the processed input stream.


See workarounds for the different versions covering all CVEs.


Lai Han of nsfocus security team found and reported the issue to XStream and provided the required information to reproduce it.