An HTTP server is started without a timeout for reading requests
What it finds
http.ListenAndServe(addr, h) serves with an http.Server whose timeouts are all zero, so a client that sends its request headers one byte at a time holds a connection and a goroutine for as long as it likes, and enough such clients exhaust the server. An http.Server with ReadHeaderTimeout, or ReadTimeout, set bounds that.
Reported are calls of ListenAndServe and ListenAndServeTLS of net/http, resolved through the imports, and composite literals of http.Server that set neither ReadHeaderTimeout nor ReadTimeout, unless the file assigns one of those fields elsewhere. Servers in tests are reported like others.
From the rule's source, server_without_timeouts.rs.
package p import ( "net/http" "time") func f(h http.Handler) error { if err := http.ListenAndServe(":8080", h); err != nil {tx0 reports: http.ListenAndServe serves without a timeout for reading requests return err } srv := &http.Server{Addr: ":8080", Handler: h}tx0 reports: this http.Server has no timeout for reading requests ok := &http.Server{Addr: ":8081", Handler: h, ReadHeaderTimeout: 5 * time.Second} go ok.ListenAndServe() return srv.ListenAndServe()} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/go:server-without-timeouts" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:server-without-timeouts] reason="..."tx0 explain tx0/go:server-without-timeouts shows the same in the terminal. Found a false positive? Report it.