MM-22057: Limit incoming request bodies (#13827)

* MM-22057: Limit incoming request bodies

Set the max request body size to be equal to MaxFileSize.
Ideally, non-file request bodies should be smaller than file request bodies,
but we don't have a clean way to identify all file upload handlers.

There shouldn't be any valid request which exceeds the max file upload size.
So this is a safe global limit to apply.

* Fix tests

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2020-02-08 01:29:59 +05:30
коммит произвёл GitHub
родитель 94af9cc92c
Коммит 73ce92400b
2 изменённых файлов: 14 добавлений и 0 удалений

Просмотреть файл

@@ -647,6 +647,11 @@ func (a *App) UploadFileX(channelId, name string, input io.Reader,
func (t *uploadFileTask) readAll() *model.AppError {
_, err := t.buf.ReadFrom(t.limitedInput)
if err != nil {
// Ugly hack: the error is not exported from net/http.
if err.Error() == "http: request body too large" {
return t.newAppError("api.file.upload_file.too_large_detailed.app_error",
"", http.StatusRequestEntityTooLarge, "Length", t.buf.Len(), "Limit", t.limit)
}
return t.newAppError("api.file.upload_file.read_request.app_error",
err.Error(), http.StatusBadRequest)
}