Skip to content
DoS Disclosed report Intermediate CVE-2018-16470

Specially constructed multi-part requests cause multi-second response times; vulnerable to DoS

The multipart body parser in Rack, and therefore Rails, scales worse than linearly with the number of parts in a request. An attacker could send specially crafted multipart requests to make request handling take many seconds, tying up web serving resources and causing gateway timeouts.

bjeanes Follow

Originally disclosed on HackerOne

Medium 5.3 View original
  • Triaged in 45 hours
  • Fixed in 6 days
  • Paid in 6 days
  • Disclosed after 36 days

The multi-part body parsing in Rack and consequently Rails has a worse-than-linear performance relative to the number of parts in the request body.

In small scale (i.e. non-disruptive) tests on a variety of Rails applications on the internet, including my own, GitHub.com, Heroku API, Instacart, Shopify, Bugcrowd, and others, it was trivial to cause request servicing to take long enough to cause gateway timeouts. It would not be particularly difficult to generate enough of these requests to tie up the majority of web serving resources for a typical Rails application.

This vulnerability has also been separately disclosed to rack-core mailing list by me.

Steps To Reproduce:

I've created a script that can be run here against any Rack-based application: https://gist.github.com/bjeanes/63580e27c197885d4b07160fae132108

By default it generates a request body with 10,000 parts which, in my testing, was enough to cause GitHub API to take between 15-25 seconds to service the request once the request transfer had completed.

Addendum

Some benchmarking of Rack is included here, which was also sent to rack-core:

N = number of parts, 
boundary used is as generated by Chrome, but larger boundaries cause
higher impact

Rehearsal --------------------------------------------
N: 1       0.032670   0.006635   0.039305 (  0.044159)
N: 100     0.008245   0.001319   0.009564 (  0.009971)
N: 1000    0.149332   0.079087   0.228419 (  0.255769)
N: 2000    0.398711   0.276931   0.675642 (  0.691356)
N: 5000    2.254126   1.569181   3.823307 (  3.871649)
N: 10000   7.134949   4.350681  11.485630 ( 12.083888)
N: 20000  15.946187  10.491861  26.438048 ( 28.684177)
---------------------------------- total: 42.699915sec

               user     system      total        real
N: 1       0.000372   0.000003   0.000375 (  0.000371)
N: 100     0.004889   0.000021   0.004910 (  0.004977)
N: 1000    0.117571   0.015548   0.133119 (  0.192915)
N: 2000    0.468934   0.309703   0.778637 (  0.870675)
N: 5000    2.086055   1.482317   3.568372 (  3.830543)
N: 10000   7.110589   4.488229  11.598818 ( 12.110710)
N: 20000  14.559701   9.948678  24.508379 ( 25.537332)

This is not technically in the Rails codebase, but it is in a non-optional dependency of every Rails application. Furthermore, I did receive some feedback from core members that a Rack vulnerability is likely to be eligible for this bounty: https://twitter.com/_matthewd/status/1057266505056800768.

Discovered by Bo Jeanes (@bjeanes) and Jack Chen (@chendo) and vetted after the fact by Charlie Somerville (@charliesome).

Impact

Resource starvation of web request servicing, by causing multiple long-running requests. Attack can be constructed with just a HTML web form, making it literally click-button easy. That it can be generated from a form also has potential implications when combined with XSS or some other mechanism where an attacker could cause arbitrary user agents en masse to send such requests.

The original report as published on HackerOne, by bjeanes. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

Rack parses the body of incoming HTTP requests, and Rails applications inherit that parsing through Rack, which is a non-optional dependency of every Rails application. The feature at issue is multipart body parsing: the code that walks a multipart/form-data body and splits it into its individual parts. That is the same code path used whenever a browser submits a form containing a file upload or any other multipart form.

The report describes a denial of service: the time taken to parse a multipart body grows worse than linearly with the number of parts in the request. The researcher states that the vulnerable code is not technically in the Rails codebase itself, but in Rack, and that the issue was also disclosed separately to the rack-core mailing list.

Setup

No accounts, roles or specific versions are given. The only precondition is that the target is a Rack-based application, which includes any Rails application. The researcher tested against a variety of Rails applications on the internet, including his own, GitHub.com, the Heroku API, Instacart, Shopify and Bugcrowd, and describes those tests as small scale and non-disruptive.

A script accompanies the report, runnable against any Rack-based application:

Text
https://gist.github.com/bjeanes/[redacted]

By default the script generates a request body with 10,000 parts.

Finding it

The report states that multipart body parsing in Rack, and consequently in Rails, has worse-than-linear performance relative to the number of parts in the request body. In his testing, a body with 10,000 parts was enough to make the GitHub API take between 15 and 25 seconds to service the request once the request transfer had completed. He notes that it would not be particularly difficult to generate enough of these requests to tie up the majority of web serving resources for a typical Rails application.

Exploitation

Step 1: Generate a multipart body with many parts

Run the published script against a Rack-based application. It builds a multipart request body containing 10,000 parts by default. The cost is in the parsing that happens after the body has arrived, so the request transfer completing is not the end of the work: the server then spends seconds walking the parts.

Step 2: Observe the response time

Against the GitHub API, the 10,000-part body caused request servicing to take between 15 and 25 seconds once the request transfer had completed. On the applications tested, this was enough to cause gateway timeouts.

Step 3: Scale up the number of requests

The researcher states that generating enough of these requests to tie up the majority of web serving resources for a typical Rails application would not be particularly difficult.

Benchmark data

The report includes benchmarking of Rack, also sent to rack-core. The number of parts is N, and the boundary used is as generated by Chrome, with the note that larger boundaries cause higher impact:

Text
N = number of parts,
boundary used is as generated by Chrome, but larger boundaries cause
higher impact

Rehearsal --------------------------------------------
N: 1       0.032670   0.006635   0.039305 (  0.044159)
N: 100     0.008245   0.001319   0.009564 (  0.009971)
N: 1000    0.149332   0.079087   0.228419 (  0.255769)
N: 2000    0.398711   0.276931   0.675642 (  0.691356)
N: 5000    2.254126   1.569181   3.823307 (  3.871649)
N: 10000   7.134949   4.350681  11.485630 ( 12.083888)
N: 20000  15.946187  10.491861  26.438048 ( 28.684177)
---------------------------------- total: 42.699915sec

               user     system      total        real
N: 1       0.000372   0.000003   0.000375 (  0.000371)
N: 100     0.004889   0.000021   0.004910 (  0.004977)
N: 1000    0.117571   0.015548   0.133119 (  0.192915)
N: 2000    0.468934   0.309703   0.778637 (  0.870675)
N: 5000    2.086055   1.482317   3.568372 (  3.830543)
N: 10000   7.110589   4.488229  11.598818 ( 12.110710)
N: 20000  14.559701   9.948678  24.508379 ( 25.537332)

The real times rise steeply with N: roughly 0.19 seconds at 1,000 parts, 0.87 seconds at 2,000, 3.83 seconds at 5,000, 12.11 seconds at 10,000 and 25.54 seconds at 20,000. The growth is worse than linear, which is the core of the finding.

Root cause

The parsing cost in Rack's multipart body handling grows worse than linearly with the number of parts in the body. The report does not describe the internal algorithm, so the precise reason for the superlinear behaviour is not stated here. The important structural point is that the vulnerable code sits in Rack, a non-optional dependency of every Rails application, so Rails applications inherit the behaviour regardless of their own code. The researcher also notes feedback from core members that a Rack vulnerability is likely to be eligible for the bounty, linking to a public statement to that effect.

The report credits discovery to Bo Jeanes (@bjeanes) and Jack Chen (@chendo), with vetting after the fact by Charlie Somerville (@charliesome).

Impact

The impact is resource starvation of web request servicing, caused by multiple long-running requests. Because the body can be constructed with just an HTML web form, the researcher describes the attack as literally click-button easy. That it can be generated from a form also has potential implications when combined with XSS or another mechanism through which an attacker could cause arbitrary user agents en masse to send such requests.

The report does not give a figure for how many requests are needed to exhaust a given deployment; it says only that generating enough to tie up the majority of web serving resources for a typical Rails application would not be particularly difficult.

Fix

It was disclosed to the rack-core mailing list as well as through the bounty programme, and the write-up stops at the impact analysis.

Variants to test

  1. Send a multipart body with a large number of small parts to any Rack-based endpoint that accepts multipart/form-data. A positive result is response time that grows faster than the part count, for example a jump from under a second at 2,000 parts to many seconds at 10,000.
  2. Increase the boundary length while keeping the part count fixed. The report notes that larger boundaries cause higher impact, so a positive result is a measurable increase in parse time for the same N.
  3. Deliver the same body from a plain HTML form. The report says the attack can be constructed with just an HTML web form, making it click-button easy and potentially usable alongside XSS.
  4. Watch for gateway timeouts rather than application errors. A positive result is a gateway timeout, which the researcher says the tested applications produced.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

Every Rails application depends on a piece of software called Rack. Rack is the layer that sits between the web server and the Rails application and takes care of reading incoming requests, including the body of the request. One of the things Rack can read is a multipart/form-data body: the format a browser uses when it submits a form that contains a file upload or any other kind of form data split into several pieces.

The researcher found that when a request body is split into many pieces (called "parts"), Rack takes a surprisingly long time to read it. The time does not grow in proportion to the number of parts: it grows faster than that. A body with 10,000 parts was enough to keep the GitHub API busy for between 15 and 25 seconds after the body had fully arrived. If an attacker sends many such requests at once, the server can run out of capacity to answer anyone, which is a denial of service (DoS).

The vulnerable code is not in Rails itself but in Rack, which every Rails application uses and cannot easily remove. The researcher also reported the issue separately to the rack-core mailing list, the discussion list for the people who maintain Rack.

Background: the words you need

Before the details, a few everyday explanations:

  • HTTP request: what your browser sends to a website when you open a page or submit a form. It has a header (information about the request) and a body (the data being sent).
  • Request body: the data part of the request. For a simple page view it is often empty; for a form submission it contains what you typed or uploaded.
  • multipart/form-data: a way of packing a form into a request body when the form has several fields or a file. The body is divided into sections called parts, each with its own small header and content, and the parts are separated by a marker string called a boundary. Think of it as several letters put into one envelope, with a coloured strip of paper between them so the recipient knows where one letter ends and the next begins.
  • Rack: a Ruby library that sits between the web server and a Ruby web application. It reads the raw request and hands the application a tidy version of it. Rails uses Rack and cannot run without it.
  • Rails: a popular framework for building web applications in the Ruby programming language.
  • API: a way for one program to talk to another over the network, usually by sending requests to specific addresses and getting structured answers back. The GitHub API, for example, lets other software ask GitHub for information.
  • Denial of service (DoS): an attack that does not steal data but makes a service unavailable to its normal users, usually by exhausting its capacity.
  • Gateway timeout: an error a front-end server (a proxy or load balancer) returns when the application behind it takes too long to answer. The user sees an error page even though the application may still be working.
  • Benchmark: a timed test that measures how long a piece of software takes to do something.
  • XSS (cross-site scripting): a flaw that lets an attacker run their own code in other people's browsers on a website. It can be used to make many visitors' browsers do something without their knowledge.

The setup

The report gives no accounts, no roles and no specific software versions. The only requirement is that the target is a Rack-based application, which includes every Rails application.

The researcher tested against a range of Rails applications on the internet, including his own, GitHub.com, the Heroku API, Instacart, Shopify and Bugcrowd. He describes these tests as small scale and non-disruptive, meaning he did not try to take anyone down.

A script accompanies the report and can be run against any Rack-based application:

Text
https://gist.github.com/bjeanes/[redacted]

This is a link to a short program published on a code-sharing site. By default the script builds a request body containing 10,000 parts.

Finding it

The researcher noticed that Rack's multipart parsing, and therefore Rails' parsing, gets slower faster than the number of parts grows. In his testing, a body with 10,000 parts made the GitHub API take between 15 and 25 seconds to service the request once the request transfer had completed. The phrase "once the request transfer had completed" matters: the 15 to 25 seconds is the time to service the request after the body has arrived.

He adds that it would not be particularly difficult to generate enough of these requests to tie up the majority of web serving resources for a typical Rails application. In other words, one slow request is a nuisance; many at the same time can stop the site serving anyone.

Exploitation

Step 1: Generate a multipart body with many parts

Run the published script against a Rack-based application. It builds a multipart request body containing 10,000 parts by default. The cost is in the parsing that happens after the body has arrived, so the request transfer completing is not the end of the work: the server then spends seconds walking the parts.

The server accepts it happily and then works through it slowly.

Step 2: Observe the response time

Against the GitHub API, the 10,000-part body caused request servicing to take between 15 and 25 seconds once the request transfer had completed. On the applications tested, this was enough to cause gateway timeouts.

Why this step: measuring the response time is how you confirm the problem. A gateway timeout is the visible symptom: the front-end server gives up waiting while the application is still busy parsing.

Step 3: Scale up the number of requests

The researcher states that generating enough of these requests to tie up the majority of web serving resources for a typical Rails application would not be particularly difficult.

Why this step: a web server can only handle a limited number of requests at the same time.

Benchmark data

The report includes benchmarking of Rack, also sent to rack-core. The number of parts is N, and the boundary used is as generated by Chrome, with the note that larger boundaries cause higher impact:

Text
N = number of parts,
boundary used is as generated by Chrome, but larger boundaries cause
higher impact

Rehearsal --------------------------------------------
N: 1       0.032670   0.006635   0.039305 (  0.044159)
N: 100     0.008245   0.001319   0.009564 (  0.009971)
N: 1000    0.149332   0.079087   0.228419 (  0.255769)
N: 2000    0.398711   0.276931   0.675642 (  0.691356)
N: 5000    2.254126   1.569181   3.823307 (  3.871649)
N: 10000   7.134949   4.350681  11.485630 ( 12.083888)
N: 20000  15.946187  10.491861  26.438048 ( 28.684177)
---------------------------------- total: 42.699915sec

               user     system      total        real
N: 1       0.000372   0.000003   0.000375 (  0.000371)
N: 100     0.004889   0.000021   0.004910 (  0.004977)
N: 1000    0.117571   0.015548   0.133119 (  0.192915)
N: 2000    0.468934   0.309703   0.778637 (  0.870675)
N: 5000    2.086055   1.482317   3.568372 (  3.830543)
N: 10000   7.110589   4.488229  11.598818 ( 12.110710)
N: 20000  14.559701   9.948678  24.508379 ( 25.537332)

How to read this table:

  • The first lines are a note: N is the number of parts, and the boundary was the kind Chrome generates. The researcher adds that a longer boundary makes the impact worse.
  • Each row is one test with a given number of parts, from 1 up to 20,000.
  • The four numbers in each row are timings in seconds: time spent by the processor running the program's own instructions (user), time spent by the operating system on its behalf (system), their sum (total), and the actual elapsed time in brackets (real).
  • The first block, labelled Rehearsal, is a warm-up run. The second block is the measured run.
  • The total: 42.699915sec line is the sum of the rehearsal times.

The real times rise steeply with N: roughly 0.19 seconds at 1,000 parts, 0.87 seconds at 2,000, 3.83 seconds at 5,000, 12.11 seconds at 10,000 and 25.54 seconds at 20,000. The growth is worse than linear, which is the core of the finding. If the time grew in proportion to the parts, doubling the parts would double the time; here it grows much faster, so each extra part costs more than the one before.

Root cause

The parsing cost in Rack's multipart body handling grows worse than linearly with the number of parts in the body. The report does not describe the internal algorithm, so the precise reason for the superlinear behaviour is not stated here. The important structural point is that the vulnerable code sits in Rack, a non-optional dependency of every Rails application, so Rails applications inherit the behaviour regardless of their own code. The researcher also notes feedback from core members that a Rack vulnerability is likely to be eligible for the bounty, linking to a public statement to that effect.

The report credits discovery to Bo Jeanes (@bjeanes) and Jack Chen (@chendo), with vetting after the fact by Charlie Somerville (@charliesome).

Impact

The impact is resource starvation of web request servicing, caused by multiple long-running requests. Because the body can be constructed with just an HTML web form, the researcher describes the attack as literally click-button easy. That it can be generated from a form also has potential implications when combined with XSS or another mechanism through which an attacker could cause arbitrary user agents en masse to send such requests.

In plain terms: an attacker does not need special tools. A simple web page with a form can produce the harmful request, so a victim only has to click a button. And if an attacker can already run code in other people's browsers through an XSS flaw, they could make many visitors' browsers send these requests at the same time without anyone noticing.

The report does not give a figure for how many requests are needed to exhaust a given deployment; it says only that generating enough to tie up the majority of web serving resources for a typical Rails application would not be particularly difficult.

Fix

It was disclosed to the rack-core mailing list as well as through the bounty programme, and the write-up stops at the impact analysis.

Variants to test

  1. Send a multipart body with a large number of small parts to any Rack-based endpoint that accepts multipart/form-data. A positive result is response time that grows faster than the part count, for example a jump from under a second at a few thousand parts to many seconds at ten thousand.
  2. Increase the boundary length while keeping the part count fixed. The report notes that larger boundaries cause higher impact, so a positive result is a measurable increase in parse time for the same N.
  3. Deliver the same body from a plain HTML form. The report says the attack can be constructed with just an HTML web form, making it click-button easy and potentially usable alongside XSS.
  4. Watch for gateway timeouts rather than application errors. A positive result is a gateway timeout, which the researcher says the tested applications produced.

Glossary

  • API: a way for one program to talk to another over a network, usually by sending requests to specific addresses and receiving structured answers.
  • Benchmark: a timed test that measures how long software takes to perform a task.
  • Boundary: the marker string that separates the parts inside a multipart/form-data body.
  • Denial of service (DoS): an attack that makes a service unavailable to normal users, usually by exhausting its capacity.
  • Gateway timeout: an error returned by a front-end server when the application behind it takes too long to respond.
  • HTTP request: the message a browser or other client sends to a server, made of headers and an optional body.
  • Multipart body parsing: the process of reading a multipart/form-data body and splitting it into its individual parts.
  • multipart/form-data: a format for sending form data, including file uploads, as a body divided into parts separated by a boundary.
  • Part: one section of a multipart body, with its own small header and content.
  • Rack: a Ruby library that sits between the web server and a Ruby web application and prepares incoming requests for the application.
  • Rails: a framework for building web applications in the Ruby programming language.
  • Request body: the data portion of an HTTP request, such as the contents of a submitted form.
  • Resource starvation: a situation where long-running tasks use up a limited pool of server resources so that other requests cannot be served.
  • Reverse proxy: a server in front of an application that forwards requests to it and can return errors such as gateway timeouts.
  • Superlinear (worse than linear): growing faster than in direct proportion, so doubling the input more than doubles the cost.

More from Ruby on Rails

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.