Skip to content

Commit

Permalink
Set ReadTimeout on profiling and OCSP HTTP servers, `ReadHeaderTime…
Browse files Browse the repository at this point in the history
…out` on monitoring HTTP server

Reported-by: Trail of Bits <https://www.trailofbits.com>
Signed-off-by: Neil Twigg <[email protected]>
  • Loading branch information
neilalexander committed Aug 15, 2024
1 parent c0c23c3 commit 46ec35a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions internal/ocsp/ocsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ func NewOCSPResponderBase(t *testing.T, issuerCertPEM, respCertPEM, respKeyPEM s
})

srv := &http.Server{
Addr: addr,
Handler: mux,
Addr: addr,
Handler: mux,
ReadTimeout: time.Second * 5,
}
go srv.ListenAndServe()
time.Sleep(1 * time.Second)
Expand Down
10 changes: 6 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2826,6 +2826,7 @@ func (s *Server) StartProfiler() {
Addr: hp,
Handler: http.DefaultServeMux,
MaxHeaderBytes: 1 << 20,
ReadTimeout: time.Second * 5,
}
s.profiler = l
s.profilingServer = srv
Expand Down Expand Up @@ -3025,10 +3026,11 @@ func (s *Server) startMonitoring(secure bool) error {
// to return empty response or unable to display page if the
// server needs more time to build the response.
srv := &http.Server{
Addr: hp,
Handler: mux,
MaxHeaderBytes: 1 << 20,
ErrorLog: log.New(&captureHTTPServerLog{s, "monitoring: "}, _EMPTY_, 0),
Addr: hp,
Handler: mux,
MaxHeaderBytes: 1 << 20,
ErrorLog: log.New(&captureHTTPServerLog{s, "monitoring: "}, _EMPTY_, 0),
ReadHeaderTimeout: time.Second * 5,
}
s.mu.Lock()
s.http = httpListener
Expand Down
2 changes: 1 addition & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ func TestProfilingNoTimeout(t *testing.T) {
if srv == nil {
t.Fatalf("Profiling server not set")
}
if srv.ReadTimeout != 0 {
if srv.ReadTimeout != time.Second*5 {
t.Fatalf("ReadTimeout should not be set, was set to %v", srv.ReadTimeout)
}
if srv.WriteTimeout != 0 {
Expand Down

0 comments on commit 46ec35a

Please sign in to comment.