Configure timeouts for http.Server
#1
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Go's
net/http
serve functions may be vulnerable to resource consumption attacks if timeoutsare not properly configured
prior to starting the HTTP server. An adversary may open up thousands of connections but never
complete sending all data,
or never terminate the connections. This may lead to the server no longer accepting new
connections.
To protect against this style of resource consumption attack, timeouts should be set in the
net/http
server prior to callingthe listen or serve functions. What this means is that the default
http.ListenAndServe
andhttp.Serve
functions should notbe used in a production setting as they are unable to have timeouts configured. Instead a
custom
http.Server
object must becreated with the timeouts configured.
Example setting timeouts on a
net/http
server:For more information on the
http.Server
timeouts, see: https://pkg.go.dev/net/http#ServerFor information on setting request based timeouts, see:
https://pkg.go.dev/net/http#TimeoutHandler
For more information on the Slowloris attack see:
https://en.wikipedia.org/wiki/Slowloris_(computer_security)
closed by merge