Issue 26005: Denial of Service in SimpleHTTPServer and BaseHTTPServer (original) (raw)

Created on 2016-01-04 08:54 by Richard Clifford, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
basehttpdos.c Richard Clifford,2016-01-04 08:54 SimpleHTTPServer Dos POC
Pull Requests
URL Status Linked Edit
PR 9720 merged fbidu,2018-10-05 17:38
PR 9794 merged miss-islington,2018-10-11 02:44
PR 9795 merged miss-islington,2018-10-11 02:44
Messages (9)
msg257446 - (view) Author: Richard Clifford (Richard Clifford) Date: 2016-01-04 08:54
The issue comes when there is a malformed HTTP request not ending in a new line, it causes the server to hang, not timeout and causes a DoS. The request that I sent to the server was as follows: const char *headers = "GET / HTTP/1.1\r\nHost: localhost:8000\r\n"; Which should have been: const char *headers = "GET / HTTP/1.1\r\nHost: localhost:8000\r\n\r\n"; This causes a the application to await the second set of new-line sequences and hang until they are received which prevents any further connections from being made. I have just tested this against the latest versions of the library and I can supply a proof of concept code if that would be useful - just let me know. A recommended fix would be to ensure that all HTTP requests are received in full and in the correct manor prior to being parsed.
msg257447 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-01-04 09:28
I expect the server _is_ waiting for the end of the headers before handling the response. The problem is if you do not send the blank line, the server cannot know if you have ended the headers or if there are more to come. Perhaps you could set a socket timeout in the server. But an attacker could still send little bits of the header very slowly (called Slow Loris attack or something I think). I think a server robust against that sort of stuff would be out of scope for SimpleHTTPServer.
msg257448 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-01-04 09:35
"I think a server robust against that sort of stuff would be out of scope for SimpleHTTPServer." We can probably enhance SimpleHTTPServer but I agree that the server should remain simple. Maybe we should be more explicit in the documentation that the server requires to trust users?
msg257474 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-01-04 17:43
A warning directive at the start of http.server about needing to trust users would work?
msg257517 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2016-01-05 05:30
SimpleHTTPServer is never meant to be used in production. I was of the understanding that we already inform users about it in the documentation, but I do not find any such note. Only in wsgiref's simple_server.py example, we state that in the module header https://hg.python.org/cpython/file/tip/Lib/wsgiref/simple_server.py#l1 For SimpleHTTPServer, we could add a similar warning in docs. "SimpleHTTPServer is meant for demo purposes and does not implement the stringent security checks needed of real HTTP server. We do not recommend using this module directly in production." If an alternate wording is desired, please suggest in that in comments.
msg327087 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2018-10-04 21:20
Issue 34576 was recently opened about adding a security warning.
msg327505 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2018-10-11 02:43
New changeset 1d26c72e6a9c5b28b27c158f2f196217707dbb0f by Senthil Kumaran (Felipe Rodrigues) in branch 'master': bpo-34576 warn users on security for http.server (#9720) https://github.com/python/cpython/commit/1d26c72e6a9c5b28b27c158f2f196217707dbb0f
msg327510 - (view) Author: miss-islington (miss-islington) Date: 2018-10-11 03:31
New changeset 3baee3b39765f5e8ec616b2b71b731b140486394 by Miss Islington (bot) in branch '3.6': bpo-34576 warn users on security for http.server (GH-9720) https://github.com/python/cpython/commit/3baee3b39765f5e8ec616b2b71b731b140486394
msg327513 - (view) Author: miss-islington (miss-islington) Date: 2018-10-11 03:55
New changeset 57038bcb24407abbbb46e6d278d0ab4b6ad25bbf by Miss Islington (bot) in branch '3.7': bpo-34576 warn users on security for http.server (GH-9720) https://github.com/python/cpython/commit/57038bcb24407abbbb46e6d278d0ab4b6ad25bbf
History
Date User Action Args
2022-04-11 14:58:25 admin set github: 70193
2018-10-11 03:55:37 miss-islington set messages: +
2018-10-11 03:31:34 miss-islington set nosy: + miss-islingtonmessages: +
2018-10-11 02:44:28 miss-islington set pull_requests: + <pull%5Frequest9179>
2018-10-11 02:44:21 miss-islington set pull_requests: + <pull%5Frequest9177>
2018-10-11 02:43:46 orsenthil set messages: +
2018-10-05 17:38:17 fbidu set pull_requests: + <pull%5Frequest9104>
2018-10-04 21:20:11 martin.panter set status: open -> closedsuperseder: [EASY doc] http.server, SimpleHTTPServer: warn users on securitymessages: + resolution: duplicatestage: resolved
2016-09-24 19:54:37 christian.heimes set versions: + Python 3.7, - Python 3.2, Python 3.3, Python 3.4nosy: + docs@pythonassignee: docs@pythoncomponents: + Documentation, - Extension Modulestype: security -> enhancement
2016-01-05 05:30:14 orsenthil set nosy: + orsenthilmessages: +
2016-01-04 18:10:14 ethan.furman set nosy: + ethan.furman
2016-01-04 17:43:41 brett.cannon set nosy: + brett.cannonmessages: +
2016-01-04 09:35:07 vstinner set nosy: + vstinnermessages: +
2016-01-04 09:28:06 martin.panter set nosy: + martin.pantermessages: +
2016-01-04 08:54:10 Richard Clifford create