Skip to content

Commit

Permalink
Validate the request
Browse files Browse the repository at this point in the history
The patchset adds validation to the request before using it.

This can help protect from mal-formed request.

Change-Id: Ic6a7a65d6da289d84fe82c3f6e048e396b1f1a0e
Signed-off-by: Baohua Yang <yangbaohua@gmail.com>
Signed-off-by: Baohua Yang <baohua.yang@oracle.com>
  • Loading branch information
yeasy committed Jan 5, 2024
1 parent cf07d0e commit e35180f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/pkg/gateway/commitstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ func (gs *Server) CommitStatus(ctx context.Context, signedRequest *gp.SignedComm
return nil, status.Errorf(codes.InvalidArgument, "invalid status request: %v", err)
}

// Validate the request has valid channel id and transaction id
switch {
case request.GetIdentity() == nil:
return nil, status.Error(codes.InvalidArgument, "request must have valid identity")
case request.GetChannelId() == "":
return nil, status.Error(codes.InvalidArgument, "request must have valid channel ID")
case request.GetTransactionId() == "":
return nil, status.Error(codes.InvalidArgument, "request must have valid transaction ID")
}

signedData := &protoutil.SignedData{
Data: signedRequest.GetRequest(),
Identity: request.GetIdentity(),
Expand Down

0 comments on commit e35180f

Please sign in to comment.