File tree 2 files changed +14
-0
lines changed
2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -475,6 +475,9 @@ def read_header(socket)
475
475
if ( @request_bytes += line . bytesize ) > MAX_HEADER_LENGTH
476
476
raise HTTPStatus ::RequestEntityTooLarge , 'headers too large'
477
477
end
478
+ if line . include? ( "\x00 " )
479
+ raise HTTPStatus ::BadRequest , 'null byte in header'
480
+ end
478
481
@raw_header << line
479
482
end
480
483
end
Original file line number Diff line number Diff line change @@ -312,6 +312,17 @@ def test_bad_chunked
312
312
end
313
313
end
314
314
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
+
315
326
def test_forwarded
316
327
msg = <<-_end_of_message_
317
328
GET /foo HTTP/1.1
You can’t perform that action at this time.
0 commit comments