Title: CGI DOS vulnerability via long post list
Type: security Stage: patch review
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6, Python 3.5, Python 3.4, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Matthew Belisle, miss-islington, xtreak
Priority: normal Keywords: patch

Created on 2018-10-01 21:23 by Matthew Belisle, last changed 2018-10-19 16:20 by Matthew Belisle.

File name Uploaded Description Edit Matthew Belisle, 2018-10-10 14:22
Pull Requests
URL Status Linked Edit
PR 9660 merged python-dev, 2018-10-01 21:27
PR 9965 merged miss-islington, 2018-10-19 10:53
PR 9966 merged miss-islington, 2018-10-19 10:53
PR 9969 open Matthew Belisle, 2018-10-19 16:20
Messages (5)
msg326831 - (view) Author: Matthew Belisle (Matthew Belisle) * Date: 2018-10-01 21:23
Copied from email to

I have been doing memory profiling on a few python web frameworks and I noticed this issue in the cgi.FieldStorage class.

$ python
Memory used: 523935744 bytes

The problem is there is no easy way to limit the number of MiniFieldStorage objects created by FieldStorage, so it goes unchecked in many frameworks like pyramid, pylons, webapp2, and flask. The end result is that on these frameworks, a 9MB request body (gzipped down to 9KB) can chew up ~500MB of memory on the server which is enough to effectively DOS it. The obvious way to prevent this currently is to check the content-length header and fail if it exceeds some value. But that solution has a major shortcoming because many frameworks want to allow large payloads, sometimes up to 10MB, as long as they contain a reasonable number of fields.

After talking with the
 team and pylons dev team about it, we think the best solution is to add a max_num_fields param to the FieldStorage class, defaulting to None, which throws an error if max_num_fields is exceeded.
msg327476 - (view) Author: Matthew Belisle (Matthew Belisle) * Date: 2018-10-10 14:22
Sorry, looks like I forgot to attach Attaching now.
msg328036 - (view) Author: miss-islington (miss-islington) Date: 2018-10-19 10:53
New changeset 209144831b0a19715bda3bd72b14a3e6192d9cc1 by Miss Islington (bot) (matthewbelisle-wf) in branch 'master':
bpo-34866: Adding max_num_fields to cgi.FieldStorage (GH-9660)
msg328037 - (view) Author: miss-islington (miss-islington) Date: 2018-10-19 11:11
New changeset a66f279a1381dd5c1c27232ccf9f210d575e1dcc by Miss Islington (bot) in branch '3.7':
bpo-34866: Adding max_num_fields to cgi.FieldStorage (GH-9660)
msg328038 - (view) Author: miss-islington (miss-islington) Date: 2018-10-19 11:17
New changeset 322a914965368ffd7e4f97ede50b351fdf48d870 by Miss Islington (bot) in branch '3.6':
bpo-34866: Adding max_num_fields to cgi.FieldStorage (GH-9660)
Date User Action Args
2018-10-19 16:20:11Matthew Belislesetpull_requests: + pull_request9314
2018-10-19 11:17:01miss-islingtonsetmessages: + msg328038
2018-10-19 11:11:20miss-islingtonsetmessages: + msg328037
2018-10-19 10:53:24miss-islingtonsetpull_requests: + pull_request9310
2018-10-19 10:53:17miss-islingtonsetpull_requests: + pull_request9309
2018-10-19 10:53:06miss-islingtonsetnosy: + miss-islington
messages: + msg328036
2018-10-10 14:22:13Matthew Belislesetfiles: +

messages: + msg327476
2018-10-02 09:56:12xtreaksetnosy: + xtreak
2018-10-01 21:27:55python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request9053
2018-10-01 21:23:27Matthew Belislecreate