Skip to content

Commit

Permalink
add max body size check
Browse files Browse the repository at this point in the history
  • Loading branch information
technicallyty committed Jan 11, 2025
1 parent 617de22 commit 8223989
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/v2/api/grpcgateway/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"cosmossdk.io/server/v2/appmanager"
)

const MaxBodySize = 1 << 20 // 1 MB

var _ http.Handler = &gatewayInterceptor[transaction.Tx]{}

// queryMetadata holds information related to handling gateway queries.
Expand Down Expand Up @@ -141,6 +143,9 @@ func (g *gatewayInterceptor[T]) ServeHTTP(writer http.ResponseWriter, request *h
}

func (g *gatewayInterceptor[T]) createMessageFromPostRequest(_ context.Context, marshaler runtime.Marshaler, req *http.Request, input gogoproto.Message) (gogoproto.Message, error) {
if req.ContentLength > MaxBodySize {
return nil, status.Errorf(codes.InvalidArgument, "request body too large: %d bytes, max=%d", req.ContentLength, MaxBodySize)
}
newReader, err := utilities.IOReaderFactory(req.Body)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "%v", err)
Expand Down

0 comments on commit 8223989

Please sign in to comment.