Unrestricted entity expansion can lead to a DoS vulnerability in REXML, like
["Entity expansion DoS vulnerability in REXML (XML bomb, CVE-2013-1821)"](https://www.ruby-lang.org/en/news/2013/02/22/rexml-dos-2013-02-22/)
and ["CVE-2014-8080: Parameter Entity expansion DoS vulnerability in REXML"](https://www.ruby-lang.org/en/news/2014/10/27/rexml-dos-cve-2014-8080/).
This vulnerability has been assigned the CVE identifier
[CVE-2014-8090](http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-8090).
We strongly recommend to upgrade Ruby.

## Details

This is an additional fix for
[CVE-2013-1821](https://www.ruby-lang.org/en/news/2013/02/22/rexml-dos-2013-02-22/)
and [CVE-2014-8080](https://www.ruby-lang.org/en/news/2014/10/27/rexml-dos-cve-2014-8080/).
The previous patches fixed recursive expansions in a number of places and
the total size of created Strings. However, they did not take into account the former
limit used for entity expansion. 100% CPU utilization can occur as a result
of recursive expansion with an empty String.
When reading text nodes from an XML document, the REXML parser can be coerced
into allocating extremely large string objects which can consume all of the
memory on a machine, causing a denial of service.

Impacted code will look something like this:

<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="nb">require</span> <span class="s1">'rexml/document'</span>

<span class="n">xml</span> <span class="o">=</span> <span class="o">&lt;&lt;</span><span class="no">XML</span><span class="sh">
&lt;!DOCTYPE root [
  # ENTITY expansion vector
]&gt;
&lt;cd&gt;&lt;/cd&gt;
</span><span class="no">XML</span>

<span class="nb">p</span> <span class="no">REXML</span><span class="o">::</span><span class="no">Document</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">xml</span><span class="p">)</span></code></pre></figure>

All users running an affected release should either upgrade or use one
of the workarounds immediately.

## Affected versions

* All Ruby 1.9 versions prior to Ruby 1.9.3 patchlevel 551
* All Ruby 2.0 versions prior to Ruby 2.0.0 patchlevel 598
* All Ruby 2.1 versions prior to Ruby 2.1.5
* prior to trunk revision 48402

## Workarounds

If you cannot upgrade Ruby, use this monkey patch as a workaround:

<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="k">class</span> <span class="nc">REXML::Document</span>
  <span class="k">def</span> <span class="nf">document</span>
    <span class="nb">self</span>
  <span class="k">end</span>
<span class="k">end</span></code></pre></figure>

## Credits

Thanks to Tomas Hoger for reporting this issue.

## History

* Originally published at 2014-11-13 12:00:00 UTC
