feat: harden HTTP server with rate limiting, request timeouts, and sanitized error messages

This commit is contained in:
2026-06-12 00:55:09 +02:00
parent 02c5b4ae40
commit 7b8202b50b
4 changed files with 107 additions and 11 deletions
+9 -1
View File
@@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"os"
"time"
"github.com/spf13/cobra"
)
@@ -38,7 +39,14 @@ var serveCmd = &cobra.Command{
os.Exit(1)
}
fmt.Fprintf(os.Stdout, "listening on %s\n", addr)
if err := http.ListenAndServe(addr, handler); err != nil {
srv := &http.Server{
Addr: addr,
Handler: handler,
ReadTimeout: 5 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 120 * time.Second,
}
if err := srv.ListenAndServe(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}