mirror of
https://github.com/pgsty/minio.git
synced 2026-08-11 00:33:28 +03:00
Limit POST form fields and file size + Generic Request Size limiter (#2317)
* Use less memory when receiving a file via multipart * Add generic http request maximum size limiter to secure against malicious clients
This commit is contained in:
committed by
Harshavardhana
parent
7850d17f48
commit
dcc3463e48
@@ -39,6 +39,27 @@ func registerHandlers(mux *router.Router, handlerFns ...HandlerFunc) http.Handle
|
||||
return f
|
||||
}
|
||||
|
||||
// Adds limiting body size middleware
|
||||
|
||||
// Set the body size limit to 6 Gb = Maximum object size + other possible data
|
||||
// in the same request
|
||||
const requestMaxBodySize = 1024 * 1024 * 1024 * (5 + 1)
|
||||
|
||||
type requestSizeLimitHandler struct {
|
||||
handler http.Handler
|
||||
maxBodySize int64
|
||||
}
|
||||
|
||||
func setRequestSizeLimitHandler(h http.Handler) http.Handler {
|
||||
return requestSizeLimitHandler{handler: h, maxBodySize: requestMaxBodySize}
|
||||
}
|
||||
|
||||
func (h requestSizeLimitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// Restricting read data to a given maximum length
|
||||
r.Body = http.MaxBytesReader(w, r.Body, h.maxBodySize)
|
||||
h.handler.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// Adds redirect rules for incoming requests.
|
||||
type redirectHandler struct {
|
||||
handler http.Handler
|
||||
|
||||
Reference in New Issue
Block a user