CVE-2014-8080:拒绝服务 XML 扩展

不受限制的实体扩展可能导致 REXML 中出现 DoS 漏洞。此漏洞已被分配 CVE 标识符 CVE-2014-8080。我们强烈建议升级 Ruby。

详细信息

当从 XML 文档读取文本节点时,REXML 解析器可能会被强制分配非常大的字符串对象,这些对象可能会消耗机器上的所有内存,从而导致拒绝服务。

受影响的代码看起来像这样

require 'rexml/document'

xml = <<XML
<!DOCTYPE root [
  # ENTITY expansion vector
]>
<cd></cd>
XML

p REXML::Document.new(xml)

所有运行受影响版本的用户都应立即升级或使用其中一种解决方法。

受影响的版本

  • 所有 Ruby 1.9 版本,低于 Ruby 1.9.3 patchlevel 550
  • 所有 Ruby 2.0 版本,低于 Ruby 2.0.0 patchlevel 594
  • 所有 Ruby 2.1 版本,低于 Ruby 2.1.4
  • 早于 trunk 修订版 48161

解决方法

如果您无法升级 Ruby,请在 Ruby 2.1.0+ 版本上使用此猴子补丁作为解决方法

class REXML::Entity
  def value
      if @value
        matches = @value.scan(PEREFERENCE_RE)
        rv = @value.clone
        if @parent
          sum = 0
          matches.each do |entity_reference|
            entity_value = @parent.entity( entity_reference[0] )
            if sum + entity_value.bytesize > Security.entity_expansion_text_limit
              raise "entity expansion has grown too large"
            else
              sum += entity_value.bytesize
            end
            rv.gsub!( /%#{entity_reference.join};/um, entity_value )
          end
        end
        return rv
      end
      nil
   end
end

对于低于 2.1.0 的 Ruby 版本,您可以使用以下猴子补丁

class REXML::Entity
  def value
      if @value
        matches = @value.scan(PEREFERENCE_RE)
        rv = @value.clone
        if @parent
          sum = 0
          matches.each do |entity_reference|
            entity_value = @parent.entity( entity_reference[0] )
            if sum + entity_value.bytesize > Document.entity_expansion_text_limit
              raise "entity expansion has grown too large"
            else
              sum += entity_value.bytesize
            end
            rv.gsub!( /%#{entity_reference.join};/um, entity_value )
          end
        end
        return rv
      end
      nil
   end
end

鸣谢

感谢 Willis Vandevanter 报告此问题。

历史

  • 最初发布于 2014-10-27 12:00:00 (UTC)