From 3b3f352fa62cb5f5f012fb895646711596b05923 Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Wed, 5 Aug 2026 00:47:25 +0800 Subject: [PATCH] fix: limit request body size in BSON binding --- binding/bson.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/binding/bson.go b/binding/bson.go index 464890f0..09eccc73 100644 --- a/binding/bson.go +++ b/binding/bson.go @@ -18,8 +18,11 @@ func (bsonBinding) Name() string { } func (b bsonBinding) Bind(req *http.Request, obj any) error { - buf, err := io.ReadAll(req.Body) + buf, err := io.ReadAll(io.LimitReader(req.Body, DefaultMaxBodySize+1)) if err == nil { + if len(buf) > DefaultMaxBodySize { + return http.ErrBodyReadAfterClose + } err = b.BindBody(buf, obj) } return err