由 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
end
Ruby 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) 初版