File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -566,7 +566,11 @@ def read_chunked(socket, block)
566
566
block . call ( data )
567
567
end while ( chunk_size -= sz ) > 0
568
568
569
- read_line ( socket ) # skip CRLF
569
+ line = read_line ( socket ) # skip CRLF
570
+ unless line == "\r \n "
571
+ raise HTTPStatus ::BadRequest , "extra data after chunk `#{ line } '."
572
+ end
573
+
570
574
chunk_size , = read_chunk_size ( socket )
571
575
end
572
576
read_header ( socket ) # trailer + CRLF
Original file line number Diff line number Diff line change @@ -312,6 +312,30 @@ def test_bad_chunked
312
312
end
313
313
end
314
314
315
+ def test_bad_chunked_extra_data
316
+ msg = <<-_end_of_message_
317
+ POST /path HTTP/1.1\r
318
+ Transfer-Encoding: chunked\r
319
+ \r
320
+ 3\r
321
+ ABCthis-all-gets-ignored\r
322
+ 0\r
323
+ \r
324
+ _end_of_message_
325
+ msg . gsub! ( /^ {6}/ , "" )
326
+ req = WEBrick ::HTTPRequest . new ( WEBrick ::Config ::HTTP )
327
+ req . parse ( StringIO . new ( msg ) )
328
+ assert_raise ( WEBrick ::HTTPStatus ::BadRequest ) { req . body }
329
+
330
+ # chunked req.body_reader
331
+ req = WEBrick ::HTTPRequest . new ( WEBrick ::Config ::HTTP )
332
+ req . parse ( StringIO . new ( msg ) )
333
+ dst = StringIO . new
334
+ assert_raise ( WEBrick ::HTTPStatus ::BadRequest ) do
335
+ IO . copy_stream ( req . body_reader , dst )
336
+ end
337
+ end
338
+
315
339
def test_null_byte_in_header
316
340
msg = <<-_end_of_message_
317
341
POST /path HTTP/1.1\r
You can’t perform that action at this time.
0 commit comments