net/http: multipart form parsing is hazardous and difficult to configure #58529
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
http.Request
helpfully parsesmultipart/form-data
requests, not just explicitly inreq.ParseMultipartForm
but also implicitly inreq.FormFile
,req.FormValue
, andreq.PostFormValue
.Multipart form parsing uses
mime/multipart.Reader.ReadForm
, which has few limits on resource consumption:ReadForm
takes amaxMemory
parameter, but will allocate up to 10MiB of memory over and above this limit.ReadForm
will write file form parts to disk, with no limit on the amount of disk consumed.The defaults here are hazardous: A caller of
req.FormValue
may not intend to handlemultipart/form-data
forms at all, and will be surprised that the function can consume large amounts of memory and/or disk. The mechanisms for adjusting the defaults are inadequate: There is no simple way to disable multipart form parsing, to disable the use of disk temporary files, or to limit the memory consumption ofParseMultipartForm
to less than 10MiB.Compatibility may make it impossible to change the defaults, but at a minimum we should make it easy to configure reasonable limits.
The text was updated successfully, but these errors were encountered: