CVE-2021-21341: XStream can cause a Denial of Service.

Affected Versions

All versions until and including version 1.4.15 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 a manipulated ByteArrayInputStream (or derived class), that can cause an endless loop resulting in a denial of service.

Steps to Reproduce

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

<java.util.PriorityQueue serialization='custom'>
      <comparator class='javafx.collections.ObservableList$1'/>
        <dataSource class='$XmlDataSource'>
          <is class=''>
    <com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data reference='../com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data'/>
XStream xstream = new XStream();

As soon as the XML gets unmarshalled, the 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.


The vulnerability was discovered and reported by threedr3am.