Skip to content

Commit 6c2b18e

Browse files
committed
terminal: disable HTTP timeouts except header read
To make sure that long-running calls and indefinitely opened streaming connections aren't terminated by the internal proxy, we need to disable all timeouts except the one for reading the HTTP headers. That timeout shouldn't be removed as we would otherwise be prone to the slowloris attack where an attacker takes too long to send the headers and uses up connections that way. Once the headers are read, we either know it's a static resource and can deliver that very cheaply or check the authentication for other calls. Fixes #140 and #144.
1 parent 815d533 commit 6c2b18e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

terminal.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,20 @@ func (g *LightningTerminal) startMainWebServer() error {
555555
// Create and start our HTTPS server now that will handle both gRPC web
556556
// and static file requests.
557557
g.httpServer = &http.Server{
558-
WriteTimeout: defaultServerTimeout,
559-
ReadTimeout: defaultServerTimeout,
560-
Handler: http.HandlerFunc(httpHandler),
558+
// To make sure that long-running calls and indefinitely opened
559+
// streaming connections aren't terminated by the internal
560+
// proxy, we need to disable all timeouts except the one for
561+
// reading the HTTP headers. That timeout shouldn't be removed
562+
// as we would otherwise be prone to the slowloris attack where
563+
// an attacker takes too long to send the headers and uses up
564+
// connections that way. Once the headers are read, we either
565+
// know it's a static resource and can deliver that very cheaply
566+
// or check the authentication for other calls.
567+
WriteTimeout: 0,
568+
IdleTimeout: 0,
569+
ReadTimeout: 0,
570+
ReadHeaderTimeout: defaultServerTimeout,
571+
Handler: http.HandlerFunc(httpHandler),
561572
}
562573
httpListener, err := net.Listen("tcp", g.cfg.HTTPSListen)
563574
if err != nil {

0 commit comments

Comments
 (0)