Skip to content

Commit

Permalink
Merge pull request #1045 from skrashevich/sec-fix-slowloris
Browse files Browse the repository at this point in the history
fix(api): potential Slow Loris Attacks in API Server
  • Loading branch information
AlexxIT committed Apr 22, 2024
2 parents fffb22d + 905ef9b commit 12a7503
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"sync"
"syscall"
"time"

"github.com/AlexxIT/go2rtc/internal/app"
"github.com/AlexxIT/go2rtc/pkg/shell"
Expand Down Expand Up @@ -96,7 +97,10 @@ func listen(network, address string) {
Port = ln.Addr().(*net.TCPAddr).Port
}

server := http.Server{Handler: Handler}
server := http.Server{
Handler: Handler,
ReadHeaderTimeout: 5 * time.Second, // Example: Set to 5 seconds
}
if err = server.Serve(ln); err != nil {
log.Fatal().Err(err).Msg("[api] serve")
}
Expand Down Expand Up @@ -126,8 +130,9 @@ func tlsListen(network, address, certFile, keyFile string) {
log.Info().Str("addr", address).Msg("[api] tls listen")

server := &http.Server{
Handler: Handler,
TLSConfig: &tls.Config{Certificates: []tls.Certificate{cert}},
Handler: Handler,
TLSConfig: &tls.Config{Certificates: []tls.Certificate{cert}},
ReadHeaderTimeout: 5 * time.Second,
}
if err = server.ServeTLS(ln, "", ""); err != nil {
log.Fatal().Err(err).Msg("[api] tls serve")
Expand Down

0 comments on commit 12a7503

Please sign in to comment.