Skip to content

Commit

Permalink
Fix a bug that invalid element start may be accepted
Browse files Browse the repository at this point in the history
HackerOne: HO-1104077

It's caused by ignoring garbage before "\n<NAME...".

Reported by Juho Nurminen. Thanks!!!
  • Loading branch information
kou authored and mame committed Apr 5, 2021
1 parent 2fe62e2 commit 6a250d2
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -61,7 +61,7 @@ class BaseParser
XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>/um
INSTRUCTION_START = /\A<\?/u
INSTRUCTION_PATTERN = /<\?#{NAME}(\s+.*?)?\?>/um
TAG_MATCH = /^<((?>#{QNAME_STR}))/um
TAG_MATCH = /\A<((?>#{QNAME_STR}))/um
CLOSE_MATCH = /^\s*<\/(#{QNAME_STR})\s*>/um

VERSION = /\bversion\s*=\s*["'](.*?)['"]/um
Expand Down
13 changes: 13 additions & 0 deletions test/parse/test_element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ def test_empty_namespace_attribute_name
DETAIL
end

def test_garbage_less_than_before_root_element_at_line_start
exception = assert_raise(REXML::ParseException) do
parse("<\n<x/>")
end
assert_equal(<<-DETAIL.chomp, exception.to_s)
malformed XML: missing tag start
Line: 2
Position: 6
Last 80 unconsumed characters:
< <x/>
DETAIL
end
end
end
end

0 comments on commit 6a250d2

Please sign in to comment.