Skip to content

Commit

Permalink
Fix ReDoS by using repeated space characters inside `<!DOCTYPE name […
Browse files Browse the repository at this point in the history
…<!ATTLIST>]>` (#176)

Fix performance by removing unnecessary spaces.

This is occurred in Ruby 3.1 or earlier.
  • Loading branch information
Watson1978 authored Jul 16, 2024
1 parent 1cc1d9a commit 1f1e6e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def pull_event
contents = md[0]

pairs = {}
values = md[0].scan( ATTDEF_RE )
values = md[0].strip.scan( ATTDEF_RE )
values.each do |attdef|
unless attdef[3] == "#IMPLIED"
attdef.compact!
Expand Down
17 changes: 17 additions & 0 deletions test/parse/test_attlist.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "test/unit"
require "core_assertions"

require "rexml/document"

module REXMLTests
class TestParseAttlist < Test::Unit::TestCase
include Test::Unit::CoreAssertions

def test_gt_linear_performance
seq = [10000, 50000, 100000, 150000, 200000]
assert_linear_performance(seq, rehearsal: 10) do |n|
REXML::Document.new('<!DOCTYPE schema SYSTEM "foo.dtd" [<!ATTLIST ' + " " * n + ' root v CDATA #FIXED "test">]>')
end
end
end
end

0 comments on commit 1f1e6e9

Please sign in to comment.