Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mime/multipart: Allow limiting maximum amount of part's header data #26339

Open
andrius4669 opened this issue Jul 11, 2018 · 2 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@andrius4669
Copy link
Contributor

This is feature request, to allow user of mime/multipart package's Reader to specify limit of header data loaded into memory when calling NewPart() function.
Reader.NewPart() calls net/textproto package's Reader.ReadMIMEHeader() function which without any limitation loads all header data into memory.
mime/multipart's Reader is also used in net/http package to parse multipart/form-data POST requests, which means that functions like Request.ParseMultipartForm, Request.FormValue, Request.FormFile, Request.MultipartReader are affected by this.
I believe this can be used as remote denial of service attack vector.
Possible solution for this would be limiting HTTP request body size (done by default in some servers like nginx), but this is unsuitable for cases where server needs to accept POST requests with big files (for example, file hosting service).
Similar case like this is net/http package's Server's MaxHeaderBytes field, which limits ammount of header data, but not body.

@andrius4669
Copy link
Contributor Author

To illustrate issue, example client code exploiting this weakness: https://www.zerobin.net/?8db1a70f1608fb27#TzogmA1w8sPRNSnByLRcRrwHY0D7urscLFil6AbDdQA=
And test server's code affected by it: https://www.zerobin.net/?6f1057f7dc78ba55#4/v39opPJuwZyqEF8xft8Iqvmkv0QPyhWC189EZy+HE=
This can cause out of memory conditions therefore I recommend turning off swap on machines which run test server and running test server with nice -19.

@ianlancetaylor ianlancetaylor changed the title mime/multipart: Allow limiting maximum ammount of part's header data mime/multipart: Allow limiting maximum amount of part's header data Jul 11, 2018
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 11, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Jul 11, 2018
@ianlancetaylor
Copy link
Contributor

See also #20169.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants