From 5f068499fa8a2916c9b48a6cc81fb12fb8835331 Mon Sep 17 00:00:00 2001 From: Al Cutter Date: Wed, 11 Nov 2026 14:55:17 +0000 Subject: [PATCH] Limit number of body bytes the handler will read Signed-off-by: Al Cutter --- cmd/internal/http/server.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/internal/http/server.go b/cmd/internal/http/server.go index ac252ef..4f95813 100644 --- a/cmd/internal/http/server.go +++ b/cmd/internal/http/server.go @@ -30,6 +30,10 @@ import ( "google.golang.org/grpc/status" ) +// maxCheckpointBodyBytes bounds the size of an uploaded checkpoint. Real +// checkpoints are a few hundred bytes; 100 KiB is a generous upper limit. +const maxCheckpointBodyBytes = 100 << 10 + // Distributor persists witnessed checkpoints and allows querying of them. type Distributor interface { // GetLogs returns a list of all log IDs the distributor is aware of, sorted @@ -65,6 +69,7 @@ func (s *Server) update(w http.ResponseWriter, r *http.Request) { v := mux.Vars(r) logID := v["logid"] witID := v["witid"] + r.Body = http.MaxBytesReader(w, r.Body, maxCheckpointBodyBytes) body, err := io.ReadAll(r.Body) if err != nil { http.Error(w, fmt.Sprintf("cannot read request body: %v", err.Error()), http.StatusBadRequest)