CVE-2014-8080:XML 擴張的阻斷攻擊
由 zzak 發表於 2014-10-27
翻譯: Juanito Fatas
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 patchlevel 在 550 以前的版本
- 所有 Ruby 2.0 patchlevel 在 594 以前的版本
- 所有 Ruby 2.1 在 2.1.4 以前的版本
- 主幹 revision 48161 以前的版本
因應措施
若無法升級 Ruby,可以給 2.1.0+ 的 Ruby 使用下面的 monkey patch:
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
endRuby 2.1.0 之前的版本,可以使用下面這個 monkey patch:
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) 初版
最新消息
Ruby 4.0.0 preview2 發布
我們很高興宣布 Ruby 4.0.0-preview2 發布了。 Ruby 4.0 將 Unicode 版本更新至 17.0.0,以及其他更新。
由 naruse 發表於 2025-11-17
Ruby 3.3.10 發布
Ruby 3.3.10 已經發布了。
由 nagachika 發表於 2025-10-23
移交 RubyGems 程式碼儲存庫的所有權
親愛的 Ruby 社群
由 matz 發表於 2025-10-17
Ruby 3.4.7 發布
Ruby 3.4.7 已經發布了。
由 k0kubun 發表於 2025-10-07