-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow some messages and mark v1.15.2. (#1576)
* Update the validate-go-version make target to only allow go 1.18. * Add a msg type blacklist antehandler. * Add changelog entry and update release changelog. Mark v1.15.2.
- Loading branch information
1 parent
9ffd48f
commit 7c9a616
Showing
6 changed files
with
209 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package antewrapper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" | ||
) | ||
|
||
// MsgTypeBlacklistContextDecorator is (hopefully) a temporary hard-coded antehandler that disallows certain messages. | ||
// Once the circuit breaker module is added to provenance, this should be removed. | ||
type MsgTypeBlacklistContextDecorator struct { | ||
Blacklist []string | ||
} | ||
|
||
func NewMsgTypeBlacklistContextDecorator() MsgTypeBlacklistContextDecorator { | ||
return MsgTypeBlacklistContextDecorator{ | ||
Blacklist: []string{ | ||
// Disallow vesting account creation due to barberry: https://forum.cosmos.network/t/cosmos-sdk-security-advisory-barberry/10825 | ||
// Once that fix is in the SDK that we pull in, these can be removed. | ||
// MsgCreatePeriodicVestingAccount is specific to barberry, the other two are due to extra caution. | ||
sdk.MsgTypeURL(&vestingtypes.MsgCreatePeriodicVestingAccount{}), | ||
sdk.MsgTypeURL(&vestingtypes.MsgCreateVestingAccount{}), | ||
sdk.MsgTypeURL(&vestingtypes.MsgCreatePermanentLockedAccount{}), | ||
}, | ||
} | ||
} | ||
|
||
var _ sdk.AnteDecorator = MsgTypeBlacklistContextDecorator{} | ||
|
||
func (b MsgTypeBlacklistContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { | ||
for _, msg := range tx.GetMsgs() { | ||
msgT := sdk.MsgTypeURL(msg) | ||
for _, nope := range b.Blacklist { | ||
if msgT == nope { | ||
return ctx, sdkerrors.ErrInvalidRequest.Wrapf("%s messages are not allowed", msgT) | ||
} | ||
} | ||
} | ||
return next(ctx, tx, simulate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package antewrapper_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
"github.com/provenance-io/provenance/internal/antewrapper" | ||
) | ||
|
||
type TestTx struct { | ||
Msgs []sdk.Msg | ||
} | ||
|
||
func NewTestTx(msgs ...sdk.Msg) TestTx { | ||
return TestTx{Msgs: msgs} | ||
} | ||
|
||
var ( | ||
_ sdk.Tx = (*TestTx)(nil) | ||
_ ante.GasTx = (*TestTx)(nil) | ||
) | ||
|
||
// GetMsgs satisfies sdk.Tx interface. | ||
func (t TestTx) GetMsgs() []sdk.Msg { | ||
return t.Msgs | ||
} | ||
|
||
// ValidateBasic satisfies sdk.Tx interface. | ||
func (t TestTx) ValidateBasic() error { | ||
return nil | ||
} | ||
|
||
// GetGas satisfies ante.GasTx interface. | ||
func (t TestTx) GetGas() uint64 { | ||
return 1_000_000_000 | ||
} | ||
|
||
const AllGood = "terminator called" | ||
|
||
func terminator(ctx sdk.Context, _ sdk.Tx, _ bool) (newCtx sdk.Context, err error) { | ||
return ctx, errors.New(AllGood) | ||
} | ||
|
||
func badMsgErr(msg sdk.Msg) string { | ||
return sdk.MsgTypeURL(msg) + " messages are not allowed: invalid request" | ||
} | ||
|
||
func TestMsgTypeBlacklistContextDecorator_AnteHandle(t *testing.T) { | ||
goodMsg := &banktypes.MsgSend{} | ||
|
||
perVMsg := &vestingtypes.MsgCreatePeriodicVestingAccount{} | ||
perVMsgErr := badMsgErr(perVMsg) | ||
vMsg := &vestingtypes.MsgCreateVestingAccount{} | ||
vMsgErr := badMsgErr(vMsg) | ||
permLVMsg := &vestingtypes.MsgCreatePermanentLockedAccount{} | ||
permLVMsgErr := badMsgErr(permLVMsg) | ||
|
||
tests := []struct { | ||
name string | ||
tx sdk.Tx | ||
exp string | ||
}{ | ||
{ | ||
name: "good", | ||
tx: NewTestTx(goodMsg), | ||
exp: AllGood, | ||
}, | ||
{ | ||
name: "periodic vesting", | ||
tx: NewTestTx(perVMsg), | ||
exp: perVMsgErr, | ||
}, | ||
{ | ||
name: "standard vesting", | ||
tx: NewTestTx(vMsg), | ||
exp: vMsgErr, | ||
}, | ||
{ | ||
name: "permanent locked", | ||
tx: NewTestTx(permLVMsg), | ||
exp: permLVMsgErr, | ||
}, | ||
{ | ||
name: "good good", | ||
tx: NewTestTx(goodMsg, goodMsg), | ||
exp: AllGood, | ||
}, | ||
{ | ||
name: "bad good", | ||
tx: NewTestTx(perVMsg, goodMsg), | ||
exp: perVMsgErr, | ||
}, | ||
{ | ||
name: "good bad", | ||
tx: NewTestTx(goodMsg, perVMsg), | ||
exp: perVMsgErr, | ||
}, | ||
{ | ||
name: "bad bad", | ||
tx: NewTestTx(permLVMsg, vMsg), | ||
exp: permLVMsgErr, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
bl := antewrapper.NewMsgTypeBlacklistContextDecorator() | ||
_, err := bl.AnteHandle(sdk.Context{}, tc.tx, false, terminator) | ||
assert.EqualError(t, err, tc.exp, "MsgTypeBlacklistContextDecorator.AnteHandle") | ||
}) | ||
} | ||
} | ||
|
||
func (s *AnteTestSuite) TestBlacklistedMsgs() { | ||
s.SetupTest(true) | ||
badMsgs := []sdk.Msg{ | ||
&vestingtypes.MsgCreatePeriodicVestingAccount{}, | ||
&vestingtypes.MsgCreateVestingAccount{}, | ||
&vestingtypes.MsgCreatePeriodicVestingAccount{}, | ||
} | ||
|
||
for _, msg := range badMsgs { | ||
name := sdk.MsgTypeURL(msg) | ||
exp := badMsgErr(msg) | ||
s.Run(name, func() { | ||
_, err := s.anteHandler(s.ctx, NewTestTx(msg), true) | ||
s.Assert().EqualError(err, exp, "anteHandler") | ||
}) | ||
} | ||
} |