Skip to content

Commit 649604e

Browse files
authored
Merge pull request #114 from ooooooo-q/fix/redos
Fix/redos
2 parents 5510186 + 9e32248 commit 649604e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/webrick/httputils.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ def parse_header(raw)
157157
field = nil
158158
raw.each_line{|line|
159159
case line
160-
when /^([A-Za-z0-9!\#$%&'*+\-.^_`|~]+):\s*(.*?)\s*\z/om
161-
field, value = $1, $2
160+
when /^([A-Za-z0-9!\#$%&'*+\-.^_`|~]+):(.*?)\z/om
161+
field, value = $1, $2.strip
162162
field.downcase!
163163
header[field] = [] unless header.has_key?(field)
164164
header[field] << value
165-
when /^\s+(.*?)\s*\z/om
166-
value = $1
165+
when /^\s+(.*?)/om
166+
value = line.strip
167167
unless field
168168
raise HTTPStatus::BadRequest, "bad header '#{line}'."
169169
end
@@ -183,7 +183,7 @@ def parse_header(raw)
183183
# Splits a header value +str+ according to HTTP specification.
184184

185185
def split_header_value(str)
186-
str.scan(%r'\G((?:"(?:\\.|[^"])+?"|[^",]+)+)
186+
str.scan(%r'\G((?:"(?:\\.|[^"])+?"|[^",]++)+)
187187
(?:,\s*|\Z)'xn).flatten
188188
end
189189
module_function :split_header_value

0 commit comments

Comments
 (0)