Skip to content

Commit

Permalink
caddyhttp: Reject absurd methods (#4538)
Browse files Browse the repository at this point in the history
* caddyhttp: Reject absurdly long methods

* Limit method to 32 chars and truncate

* Just reject the request and debug-log it

* Log remote address
  • Loading branch information
mholt authored Jan 19, 2022
1 parent 94035c1 commit bf380d0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/caddyhttp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

// reject very long methods; probably a mistake or an attack
if len(r.Method) > 32 {
if s.shouldLogRequest(r) {
s.accessLogger.Debug("rejecting request with long method",
zap.String("method_trunc", r.Method[:32]),
zap.String("remote_addr", r.RemoteAddr))
}
w.WriteHeader(http.StatusMethodNotAllowed)
return
}

repl := caddy.NewReplacer()
r = PrepareRequest(r, repl, w, s)

Expand Down

0 comments on commit bf380d0

Please sign in to comment.