Browse Source

caddyhttp: Reject absurd methods (#4538)

* caddyhttp: Reject absurdly long methods

* Limit method to 32 chars and truncate

* Just reject the request and debug-log it

* Log remote address
master
Matt Holt 3 years ago
committed by GitHub
parent
commit
bf380d00ab
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      modules/caddyhttp/server.go

11
modules/caddyhttp/server.go

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

Loading…
Cancel
Save