Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
fix(security): add timeouts to HTTP servers to mitigate Slowloris DoS
Antonio Ojeaedc61ea71ce7
diff --git a/cmd/sam-console/main.go b/cmd/sam-console/main.goindex de64687c..0a54d26c 100644--- a/cmd/sam-console/main.go+++ b/cmd/sam-console/main.go@@ -45,6 +45,11 @@ func main() {httpSrv := &http.Server{Addr: *bindAddr,Handler: srv.Handler(),+ // Mitigate Slowloris-style resource exhaustion from slow/malicious clients.+ ReadHeaderTimeout: 10 * time.Second,+ ReadTimeout: 30 * time.Second,+ WriteTimeout: 30 * time.Second,+ IdleTimeout: 120 * time.Second,}go func() {diff --git a/internal/controlplane/server.go b/internal/controlplane/server.goindex 7abab35a..2a8ab291 100644--- a/internal/controlplane/server.go+++ b/internal/controlplane/server.go@@ -171,6 +171,11 @@ func (s *Server) Start() error {s.httpServer = &http.Server{Handler: mux,+ // Mitigate Slowloris-style resource exhaustion from slow/malicious clients.+ ReadHeaderTimeout: 10 * time.Second,+ ReadTimeout: 30 * time.Second,+ WriteTimeout: 30 * time.Second,+ IdleTimeout: 120 * time.Second,}s.wg.Add(1)diff --git a/internal/node/node.go b/internal/node/node.goindex 543b18df..c7e18bb3 100644--- a/internal/node/node.go+++ b/internal/node/node.go@@ -1799,6 +1799,9 @@ func (n *SamNode) StartIngressServer(ctx context.Context) error {}server := &http.Server{+ // Bound header-read time only: proxied backend responses can stream.+ ReadHeaderTimeout: 10 * time.Second,+ IdleTimeout: 120 * time.Second,Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {rc := &readCloserWithCount{ReadCloser: r.Body}r.Body = rcdiff --git a/internal/node/oidc.go b/internal/node/oidc.goindex 130b6acb..181e7edc 100644--- a/internal/node/oidc.go+++ b/internal/node/oidc.go@@ -198,7 +198,7 @@ func (n *SamNode) InteractiveLogin(ctx context.Context, authURL, tokenURL, clien}})- srv = &http.Server{Handler: mux}+ srv = &http.Server{Handler: mux, ReadHeaderTimeout: 10 * time.Second}go func() {if err := srv.Serve(listener); err != nil && err != http.ErrServerClosed {select {diff --git a/internal/node/sidecar.go b/internal/node/sidecar.goindex 6416a2b6..7c362f45 100644--- a/internal/node/sidecar.go+++ b/internal/node/sidecar.go@@ -80,6 +80,10 @@ func StartSidecarServer(node *SamNode, addr, token, certFile, keyFile, caFile stserver := &http.Server{Handler: mux,+ // Bound header-read time only: bodies/responses can legitimately stream+ // (MCP sessions, inference completions), so no ReadTimeout/WriteTimeout.+ ReadHeaderTimeout: 10 * time.Second,+ IdleTimeout: 120 * time.Second,}listener, err := net.Listen("tcp", addr)@@ -151,6 +155,9 @@ func StartUnauthSidecarServer(controlPlaneURL, addr, certFile, keyFile string) (server := &http.Server{Handler: mux,+ // Bound header-read time only: MCP sessions can legitimately stream.+ ReadHeaderTimeout: 10 * time.Second,+ IdleTimeout: 120 * time.Second,}listener, err := net.Listen("tcp", addr)diff --git a/internal/sambox/gateway.go b/internal/sambox/gateway.goindex 5f62e3e0..81f00839 100644--- a/internal/sambox/gateway.go+++ b/internal/sambox/gateway.go@@ -254,6 +254,9 @@ func (g *Gateway) Serve(listener net.Listener) error {server := &http.Server{Handler: proxy,+ // Bound header-read time only: proxied backend responses can stream.+ ReadHeaderTimeout: 10 * time.Second,+ IdleTimeout: 120 * time.Second,}var serverErr error