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 authored and denyeart committed Feb 8, 2024
1 parent e4db781 commit 74cece9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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, "no identity provided")
case request.GetChannelId() == "":
return nil, status.Error(codes.InvalidArgument, "no channel ID provided")
case request.GetTransactionId() == "":
return nil, status.Error(codes.InvalidArgument, "transaction ID should not be empty")
}

signedData := &protoutil.SignedData{
Data: signedRequest.GetRequest(),
Identity: request.GetIdentity(),
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/gateway/commitstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestCommitStatus(t *testing.T) {

request := &pb.CommitStatusRequest{
ChannelId: testChannel,
Identity: tt.identity,
Identity: []byte("IDENTITY"),
TransactionId: "TX_ID",
}
requestBytes, err := proto.Marshal(request)
Expand Down

0 comments on commit 74cece9

Please sign in to comment.