Content length restriction bypass can lead to DOS by reading large files on gip.rocks
The application checks the Content-Length header to limit upload size, but an attacker can send a larger file with a falsified smaller header value, causing the server to read the entire file into memory and potentially leading to denial of service.
- Triaged in 13 days
- Fixed in 53 days
- Disclosed after 55 days
Hello team,
Introduction
Since you mentioned in the rules that all libraries listed on your github repositories are in scope, I decided to take a look at http://gip.rocks
Problem:
The application reads an image file and convert it into smaller formats, zip it and let the users to download the updated file. But the problem here is the condition check before reading the file to the variable:
File: https://github.com/gratipay/gip.rocks/blob/master/www/v1.spt
if int(request.headers['Content-Length']) > 256 * 1024:
raise Response(413)
image_type = request.headers['Content-Type']
if image_type not in ('image/png', 'image/jpeg'):
raise Response(415)
# Load the image.
fp = StringIO(request.raw_body)
fp.seek(0)
image = Image.open(fp)
Here you can see that you are calculating the length of the incoming file from the content-length HTTP header and if it is less than 256 * 1024, you will accept the request. But this is not a correct way to check size of the incoming file.
POC:
-
Initiate a system wide proxy with burp suite
-
Try to send a curl request with a huge file and see the request in curl
-
The content length will be obviously greater than the max value application accepts but modify the
content-lengthheader to a value which is less than256 * 1024. -
Forward the request and you can see that the server will read the files to a variable and if the file is large enough, this is more than enough to DOS the server.
Now since this deals with DOS, I haven't actually tried out this attack but we can easily confirm this from the source code that this can be bypassed in the way I explained above. I also tried deploying locally but I had a hard time making the software run locally and I don't have enough free time to debug what is happening.
But I think the bug is very clear from the source code itself, which is why I really didn't test it but thought to report it.
Mitigation:
Putting your trust on HTTP headers may not be a good idea. But I am not really sure what is a solid method to find the proper length of the string in this case.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The application relies on the client-supplied Content-Length header to enforce a size limit instead of checking the actual size of the received body.
Impact
An attacker could cause a denial of service by exhausting server memory, though the reporter did not actually test the attack.
What the attacker needed
Ability to send HTTP requests
How it was found
- Set up a proxy to intercept requests.
- Send a request with a large file.
- Modify the Content-Length header to a value below the limit.
- Forward the request; the server reads the large file into memory.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
The server trusts a number the client sends (the Content-Length header) to decide if a file is small enough. A malicious client can lie about that number and send a huge file, which the server then loads into memory, possibly crashing it. This is like a bouncer trusting a fake ID to let in an oversized package.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.