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 14, 2024
1 parent f2726b4 commit d022325
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 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

0 comments on commit d022325

Please sign in to comment.