This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Denial of service on http.server module with large request method.
Type: security Stage: patch review
Components: Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: demonia, jaswdr, rhettinger
Priority: normal Keywords: patch

Created on 2021-04-12 13:17 by demonia, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 26223 open demonia, 2021-05-18 23:08
Messages (3)
msg390849 - (view) Author: Mohammed Dief (demonia) * Date: 2021-04-12 13:17
- Hello there, 2 days ago i discovered a DoS on http.server in python that allows me to take any python http.server down using less than 1k requests. i reported it to PSRT but they said i should report it here since http.server isn't for production. so here's the issue, in server.py http.server library has a really big value on the validation. and check if the first line of the request (method /path HTTP/VERSION) have more than 65k characters inside of it using `len()` function.

- In this case, the user is able to provide a method with 65k characters long and the server will accept it, if you send one request with this number of characters inside of the request using cURL. you will notice that the server could handle it. but after creating a big loop of 1k requests with the same characters. the server was taken down and didn't response again since it was trying to process this amount of data.

- Such an attack could be used to take down any python server running using http.server module. but since it's not for production like the documentations said the attack surface isn't that wide.

- To proof this issue, you can use this command while running your server on port 8080 or any port you just need to modify the command: for i in $(python3 -c "print('A\n'*10000)"); do curl -X $(python3 -c "print('A'*10000)") 'http://localhost:8080/404' ; done

- Then the server should be taken down after many requests, also, i managed to fix this issue from my side by adding characters validation on the code to avoid interacting with the long data many times. should i submit it here. or should i create a PR? PS, my fix doesn't change the main requestline validation int.
msg393540 - (view) Author: Jonathan Schweder (jaswdr) * Date: 2021-05-12 18:02
@demonia you are more than welcome to send a PR, sent it and add a reference to this issue, so it could be reviewed.
msg393994 - (view) Author: Mohammed Dief (demonia) * Date: 2021-05-20 01:15
Hey there, sorry for the delay. i just submitted the fix on a PR to python source code.
History
Date User Action Args
2022-04-11 14:59:44adminsetgithub: 87979
2021-05-20 01:15:06demoniasetmessages: + msg393994
2021-05-18 23:08:09demoniasetkeywords: + patch
stage: patch review
pull_requests: + pull_request24840
2021-05-12 18:02:25jaswdrsetnosy: + jaswdr
messages: + msg393540
2021-04-14 03:36:46rhettingersetnosy: + rhettinger
2021-04-12 13:17:08demoniacreate