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

ci: add gosec checker #69

Merged
merged 2 commits into from
Feb 21, 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
52 changes: 52 additions & 0 deletions .github/workflows/gosec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: gosec

on:
push:
branches:
- main
- develop
pull_request:
branches:
- master
- develop
jobs:
gosec:
name: gosec
strategy:
matrix:
go-version: [1.18.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
env:
GOPRIVATE: github.com/bnb-chain
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_SECRET }}
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- name: Setup GitHub Token
run: git config --global url.https://$GH_ACCESS_TOKEN@github.com/.insteadOf https://github.com/
- uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: |
go mod tidy
go mod download

- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: -quiet -confidence high -severity high ./...
3 changes: 3 additions & 0 deletions e2e/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"os"
"path/filepath"
)

type SPMnemonics struct {
Expand Down Expand Up @@ -53,10 +54,12 @@ func ParseSPMnemonics(i int) SPMnemonics {
}

func ParseMnemonicFromFile(fileName string) string {
fileName = filepath.Clean(fileName)
file, err := os.Open(fileName)
if err != nil {
panic(err)
}
// #nosec
defer file.Close()

scanner := bufio.NewScanner(file)
Expand Down
2 changes: 2 additions & 0 deletions e2e/core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ const (
)

func GenRandomAddr() sdk.AccAddress {
// #nosec
return sdk.AccAddress(crypto.AddressHash([]byte(fmt.Sprintf("%d", rand.Int()))))
}

func GenRandomHexString(len int) string {
b := make([]byte, len)
// #nosec
_, err := rand.Read(b)
if err != nil {
panic(err)
Expand Down
1 change: 1 addition & 0 deletions testutil/keeper/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func PaymentKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {

func GetRandomAddress() string {
b := make([]byte, 20)
// #nosec
_, err := rand.Read(b)
if err != nil {
panic(err)
Expand Down
1 change: 1 addition & 0 deletions testutil/sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func Checksum() []byte {

func RandStr(length int) []byte {
randBytes := make([]byte, length/2)
// #nosec
rand.Read(randBytes)
return randBytes
}
4 changes: 2 additions & 2 deletions x/payment/keeper/storage_fee_charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (k Keeper) MergeStreamRecordChanges(base *[]types.StreamRecordChange, newCh

// assume StreamRecordChange is unique by Addr
func (k Keeper) ApplyStreamRecordChanges(ctx sdk.Context, streamRecordChanges []types.StreamRecordChange) error {
for _, fc := range streamRecordChanges {
_, err := k.UpdateStreamRecordByAddr(ctx, &fc)
for i := 0; i < len(streamRecordChanges); i++ {
_, err := k.UpdateStreamRecordByAddr(ctx, &streamRecordChanges[i])
if err != nil {
return fmt.Errorf("update stream record failed: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion x/storage/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math"
"net/http"
"os"
"path/filepath"
"time"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -229,7 +230,7 @@ func CmdCreateObject() *cobra.Command {
}

// read file
f, err := os.OpenFile(argObjectPath, os.O_RDONLY, 0644)
f, err := os.OpenFile(filepath.Clean(argObjectPath), os.O_RDONLY, 0600)
if err != nil {
return err
}
Expand Down