Browse Source

Merge pull request #11821 from hashicorp/error-if-get-request-has-body

http: error if GET request has non-empty body
pull/12572/head
Jared Kirschner 3 years ago committed by GitHub
parent
commit
6c84083307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .changelog/11821.txt
  2. 11
      agent/http.go

3
.changelog/11821.txt

@ -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)
```

11
agent/http.go

@ -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…
Cancel
Save