fix: limit request body size in Protobuf binding

This commit is contained in:
water 2026-08-05 00:47:28 +08:00
parent 3b3f352fa6
commit 0d0009ed1f

View File

@ -19,10 +19,13 @@ func (protobufBinding) Name() string {
}
func (b protobufBinding) 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 {
return err
}
if len(buf) > DefaultMaxBodySize {
return http.ErrBodyReadAfterClose
}
return b.BindBody(buf, obj)
}