fix: limit request body size in BSON binding

This commit is contained in:
water 2026-08-05 00:47:25 +08:00
parent 6010158337
commit 3b3f352fa6

View File

@ -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