Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: (webapi) check offledger byte prefix before deserialization #2882

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/isc/requestimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ const (
requestKindOffLedgerEVMCall
)

func IsOffledgerKind(b byte) bool {
switch RequestKind(b) {
case requestKindOffLedgerISC, requestKindOffLedgerEVMTx:
return true
}
return false
}

func RequestFromBytes(data []byte) (Request, error) {
rr := rwutil.NewBytesReader(data)
return RequestFromReader(rr), rr.Err
Expand Down
4 changes: 4 additions & 0 deletions packages/webapi/services/offledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func NewOffLedgerService(chainService interfaces.ChainService, networkProvider p
}

func (c *OffLedgerService) ParseRequest(binaryRequest []byte) (isc.OffLedgerRequest, error) {
// check offledger kind (avoid deserialization otherwise)
if !isc.IsOffledgerKind(binaryRequest[0]) {
return nil, errors.New("error parsing request: off-ledger request expected")
}
request, err := isc.RequestFromBytes(binaryRequest)
if err != nil {
return nil, errors.New("error parsing request from payload")
Expand Down
2 changes: 1 addition & 1 deletion tools/wasp-cli/chain/governance.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func initDisableFeePolicyCmd() *cobra.Command {
var chain string

cmd := &cobra.Command{
Use: "disable-gas-policy",
Use: "disable-feepolicy",
Short: "set token charged by each gas to free.",
Run: func(cmd *cobra.Command, args []string) {
node = waspcmd.DefaultWaspNodeFallback(node)
Expand Down
Loading