File tree 2 files changed +28
-1
lines changed 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -574,7 +574,11 @@ def read_chunked(socket, block)
574
574
block . call ( data )
575
575
end while ( chunk_size -= sz ) > 0
576
576
577
- read_line ( socket ) # skip CRLF
577
+ line = read_line ( socket ) # skip CRLF
578
+ unless line == "\r \n "
579
+ raise HTTPStatus ::BadRequest , "extra data after chunk `#{ line } '."
580
+ end
581
+
578
582
chunk_size , = read_chunk_size ( socket )
579
583
end
580
584
read_header ( socket ) # trailer + CRLF
Original file line number Diff line number Diff line change @@ -423,6 +423,29 @@ def test_bad_chunked
423
423
end
424
424
end
425
425
426
+ def test_bad_chunked_extra_data
427
+ msg = <<~HTTP
428
+ POST /path HTTP/1.1\r
429
+ Transfer-Encoding: chunked\r
430
+ \r
431
+ 3\r
432
+ ABCthis-all-gets-ignored\r
433
+ 0\r
434
+ \r
435
+ HTTP
436
+ req = WEBrick ::HTTPRequest . new ( WEBrick ::Config ::HTTP )
437
+ req . parse ( StringIO . new ( msg ) )
438
+ assert_raise ( WEBrick ::HTTPStatus ::BadRequest ) { req . body }
439
+
440
+ # chunked req.body_reader
441
+ req = WEBrick ::HTTPRequest . new ( WEBrick ::Config ::HTTP )
442
+ req . parse ( StringIO . new ( msg ) )
443
+ dst = StringIO . new
444
+ assert_raise ( WEBrick ::HTTPStatus ::BadRequest ) do
445
+ IO . copy_stream ( req . body_reader , dst )
446
+ end
447
+ end
448
+
426
449
def test_null_byte_in_header
427
450
msg = <<~HTTP . gsub ( "\n " , "\r \n " )
428
451
POST /path HTTP/1.1\r
You can’t perform that action at this time.
0 commit comments