-
Notifications
You must be signed in to change notification settings - Fork 207
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 gosec issues and add gosec action #124
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and the tests passed for me! Added the gosec install instructions to the PR description and a few comments throughout. Two main Qs:
- should we be using
cast
in more places than the changes shown in this PR? - nit: can we condense the utils.go by using interfaces (see the go playground example in my comment)
Please check whether we need to sort app.go:849 before merging |
I don't think we need to sort in app.go:849 because it returns another map (the order of which is non-deterministic anyway) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, discussed in person!
fix gosec issues and add gosec action
Summary
gosec
andci
target to the Makefilegosec fixes
There were two main types of changes raised by gosec
First, ints were being cast unsafely and could overflow. This was fixed by switching to using
cast...
https://github.com/spf13/castSecond, non-deterministic map iteration was fixed
In Go, iterating over maps is intentionally non-deterministic as the runtime defines. Unfortunately for us, in the Cosmos-SDK, we encountered an issue with non-deterministic upgrades in Issue cosmos-sdk#10188 PR cosmos-sdk#10189 that resulted from exactly this non-deterministic iteration. To ensure determinism, we only permit an iteration to retrieve the map keys and then those keys can then be sorted, so instead of
the requested pattern is
go doesn't support generics, so I added a number of files in utils to handle different map types
Test plan
Install gosec locally with
go install github.com/securego/gosec/v2/cmd/gosec@latest
Then, make sure gosec action passes:
make gosec