Merge pull request #11821 from hashicorp/error-if-get-request-has-body
http: error if GET request has non-empty body
This commit is contained in:
commit
038fd90925
|
@ -0,0 +1,3 @@
|
|||
```release-note:improvement
|
||||
http: if a GET request has a non-empty body, log a warning that suggests a possible problem (parameters were meant for the query string, but accidentally placed in the body)
|
||||
```
|
|
@ -544,6 +544,17 @@ func (s *HTTPHandlers) wrap(handler endpoint, methods []string) http.HandlerFunc
|
|||
} else {
|
||||
err = s.checkWriteAccess(req)
|
||||
|
||||
// Give the user a hint that they might be doing something wrong if they issue a GET request
|
||||
// with a non-empty body (e.g., parameters placed in body rather than query string).
|
||||
if req.Method == http.MethodGet {
|
||||
if req.ContentLength > 0 {
|
||||
httpLogger.Warn("GET request has a non-empty body that will be ignored; "+
|
||||
"check whether parameters meant for the query string were accidentally placed in the body",
|
||||
"url", logURL,
|
||||
"from", req.RemoteAddr)
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
// Invoke the handler
|
||||
obj, err = handler(resp, req)
|
||||
|
|
Loading…
Reference in New Issue