From c88a6cd923c2666de425df5634c06f0a61530992 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Tue, 17 Nov 2026 09:43:32 -0600 Subject: [PATCH] fix(mcpx): bound ask abandon request bodies --- pkgs/mcpx/internal/daemon/body_limits_test.go | 24 +++++++++++++++++++ pkgs/mcpx/internal/daemon/routes_proto.go | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pkgs/mcpx/internal/daemon/body_limits_test.go b/pkgs/mcpx/internal/daemon/body_limits_test.go index 29f106d087..6d3c28a012 100644 --- a/pkgs/mcpx/internal/daemon/body_limits_test.go +++ b/pkgs/mcpx/internal/daemon/body_limits_test.go @@ -1,6 +1,7 @@ package daemon import ( + "io" "net/http" "net/http/httptest" "os" @@ -80,6 +81,29 @@ func TestBodyLimitsUnderLimitUnchanged(t *testing.T) { } } +type countedBody struct { + io.Reader + read int +} + +func (b *countedBody) Read(p []byte) (int, error) { + n, err := b.Reader.Read(p) + b.read += n + return n, err +} + +func TestAskAbandonBodyReadIsBounded(t *testing.T) { + s := &Server{set: bodyLimitSet(t)} + body := &countedBody{Reader: strings.NewReader(strings.Repeat(" ", 1024))} + req := httptest.NewRequest(http.MethodPost, "/v1/ask/missing/abandon", nil) + req.Body = io.NopCloser(body) + w := httptest.NewRecorder() + s.handleAskAbandon(w, req) + if body.read > 65 { // configured 64-byte ceiling, plus MaxBytesReader's probe byte + t.Fatalf("read %d bytes from an oversized abandon body; want at most 65", body.read) + } +} + // TestNoUnboundedBodyReaders is the #2082 guard: a non-test daemon source // file may touch r.Body only through a ceiling (MaxBytesReader / // LimitReader) or a bounded handoff (the artifact store enforces its own diff --git a/pkgs/mcpx/internal/daemon/routes_proto.go b/pkgs/mcpx/internal/daemon/routes_proto.go index 7617201938..80bc914125 100644 --- a/pkgs/mcpx/internal/daemon/routes_proto.go +++ b/pkgs/mcpx/internal/daemon/routes_proto.go @@ -906,8 +906,8 @@ func (s *Server) handleAskAbandon(w http.ResponseWriter, r *http.Request) { var body struct { TaskCancelled bool `json:"taskCancelled"` } - if r.Body != nil { - _ = json.NewDecoder(r.Body).Decode(&body) + if bodyReader := http.MaxBytesReader(w, r.Body, s.bodyBytes("http.controlBodyLimit", defaults.HTTPControlBodyLimit)); r.Body != nil { + _ = json.NewDecoder(bodyReader).Decode(&body) } if body.TaskCancelled { s.reg.markAskTaskCancelled(id)