From f815b4d6c20fa62a9048d1564ae4e33a8faffd8e Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Wed, 6 Mar 2024 19:40:13 +0900 Subject: [PATCH] fix wasm hook to disallow unknown fields --- app/hook/wasm.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/hook/wasm.go b/app/hook/wasm.go index 4dfc5fe..ab3c7a7 100644 --- a/app/hook/wasm.go +++ b/app/hook/wasm.go @@ -3,6 +3,7 @@ package hook import ( "context" "encoding/json" + "strings" sdk "github.com/cosmos/cosmos-sdk/types" @@ -20,8 +21,10 @@ func NewWasmBridgeHook(wasmKeeper *wasmkeeper.Keeper) WasmBridgeHook { } func (mbh WasmBridgeHook) Hook(ctx context.Context, sender sdk.AccAddress, msgBytes []byte) error { - msg := wasmtypes.MsgExecuteContract{} - err := json.Unmarshal(msgBytes, &msg) + var msg wasmtypes.MsgExecuteContract + decoder := json.NewDecoder(strings.NewReader(string(msgBytes))) + decoder.DisallowUnknownFields() + err := decoder.Decode(&msg) if err != nil { return err }