Skip to content

Commit cd0b1dd

Browse files
committed
Reject null bytes in header lines
Fixes #126
1 parent abf2bc3 commit cd0b1dd

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/webrick/httprequest.rb

+3
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,9 @@ def read_header(socket)
475475
if (@request_bytes += line.bytesize) > MAX_HEADER_LENGTH
476476
raise HTTPStatus::RequestEntityTooLarge, 'headers too large'
477477
end
478+
if line.include?("\x00")
479+
raise HTTPStatus::BadRequest, 'null byte in header'
480+
end
478481
@raw_header << line
479482
end
480483
end

test/webrick/test_httprequest.rb

+11
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,17 @@ def test_bad_chunked
312312
end
313313
end
314314

315+
def test_null_byte_in_header
316+
msg = <<-_end_of_message_
317+
POST /path HTTP/1.1\r
318+
Evil: evil\x00\r
319+
\r
320+
_end_of_message_
321+
msg.gsub!(/^ {6}/, "")
322+
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
323+
assert_raise(WEBrick::HTTPStatus::BadRequest){ req.parse(StringIO.new(msg)) }
324+
end
325+
315326
def test_forwarded
316327
msg = <<-_end_of_message_
317328
GET /foo HTTP/1.1

0 commit comments

Comments
 (0)