Skip to content

Commit

Permalink
Merge pull request #298 from hypersign-protocol/add-gosec-git-workflow
Browse files Browse the repository at this point in the history
Add gosec git workflow
  • Loading branch information
arnabghose997 authored Nov 25, 2023
2 parents ba6e487 + c205b6e commit bbe698d
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 14 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/gosec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Gosec
on:
pull_request:

jobs:
tests:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Checkout Source
uses: actions/checkout@v2

- name: Run Gosec Security Scanner
uses: cosmos/gosec@master
with:
args: -exclude=G705 ./...
5 changes: 2 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ import (
ibcclientclient "github.com/cosmos/ibc-go/v4/modules/core/02-client/client"
ibcclienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
ibcporttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types"
porttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"

Expand Down Expand Up @@ -476,7 +475,7 @@ func NewHidnodeApp(
transferModule := transfer.NewAppModule(app.TransferKeeper)

// Create Transfer Stack
var transferStack porttypes.IBCModule
var transferStack ibcporttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)

Expand Down Expand Up @@ -533,7 +532,7 @@ func NewHidnodeApp(
)

// Create fee enabled wasm ibc Stack
var wasmStack porttypes.IBCModule
var wasmStack ibcporttypes.IBCModule
wasmStack = wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper)
wasmStack = ibcfee.NewIBCMiddleware(wasmStack, app.IBCFeeKeeper)

Expand Down
4 changes: 2 additions & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ func (app *HidnodeApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

defer iter.Close()

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
Expand All @@ -166,8 +168,6 @@ func (app *HidnodeApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr
counter++
}

iter.Close()

if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/hid-noded/cmd/debug_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"crypto/ed25519"
"crypto/rand"
"crypto/rand" /* #nosec G702 */
"crypto/sha256"
"encoding/base64"
"encoding/hex"
Expand Down
2 changes: 1 addition & 1 deletion x/ssi/ante/decorators.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b

// Determine the required fees by multiplying each required minimum gas
// price by the gas limit, where fee = ceil(minGasPrice * gasLimit).
glDec := sdk.NewDec(int64(gas))
glDec := sdk.NewDec(int64(gas)) /* #nosec G701 */
for i, gp := range minGasPrices {
fee := gp.Amount.Mul(glDec)
requiredFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt())
Expand Down
5 changes: 4 additions & 1 deletion x/ssi/keeper/msg_server_create_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ func (k msgServer) RegisterCredentialStatus(goCtx context.Context, msg *types.Ms
}

// Check if the created date before issuance date
currentDate, _ := time.Parse(time.RFC3339, msgCredProof.Created)
currentDate, err := time.Parse(time.RFC3339, msgCredProof.Created)
if err != nil {
return nil, err
}
if currentDate.Before(issuanceDateParsed) {
return nil, sdkerrors.Wrapf(types.ErrInvalidDate, "proof attached has a creation date before issuance date")
}
Expand Down
7 changes: 5 additions & 2 deletions x/ssi/keeper/msg_server_update_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper
import (
"context"
"fmt"
"reflect"
"reflect" /* #nosec G702 */
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -89,7 +89,10 @@ func (k msgServer) UpdateCredentialStatus(goCtx context.Context, msg *types.MsgU
}

// Check if the created date before issuance date
currentDate, _ := time.Parse(time.RFC3339, msgNewCredProof.Created)
currentDate, err := time.Parse(time.RFC3339, msgNewCredProof.Created)
if err != nil {
return nil, err
}
if currentDate.Before(newIssuanceDateParsed) {
return nil, sdkerrors.Wrapf(types.ErrInvalidDate, "proof attached has a creation date before issuance date")
}
Expand Down
2 changes: 1 addition & 1 deletion x/ssi/keeper/msg_server_update_did.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper
import (
"context"
"fmt"
"reflect"
"reflect" /* #nosec G702 */

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down
2 changes: 1 addition & 1 deletion x/ssi/ld-context/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func normalize(jsonLdDocument JsonLdDocument, algorithm string) (string, error)
}

// Convert JsonLdDid to interface
func jsonLdDocToInterface(jsonLd any) interface{} {
func jsonLdDocToInterface(jsonLd interface{}) interface{} {
var intf interface{}

jsonLdBytes, err := json.Marshal(jsonLd)
Expand Down
5 changes: 4 additions & 1 deletion x/ssi/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ func DefaultGenesis() *GenesisState {
func (gs GenesisState) Validate() error {
namespace := gs.ChainNamespace

regexPattern, _ := regexp.Compile("^[a-zA-Z0-9-]*$") // Matches string containing whitespaces and tabs
regexPattern, err := regexp.Compile("^[a-zA-Z0-9-]*$") // Matches string containing whitespaces and tabs
if err != nil {
return err
}
maxChainNamespaceLength := 10

if len(namespace) > maxChainNamespaceLength {
Expand Down
4 changes: 3 additions & 1 deletion x/ssi/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
// GetDidFromDidUrl returns didId from didURL.
// TODO: need to handle query and path
func GetElementsFromDidUrl(didUrl string) (string, string) {
didId, fragment, _ := strings.Cut(didUrl, "#")
didElements := strings.Split(didUrl, "#")
didId := didElements[0]
fragment := didElements[1]
return didId, fragment
}

Expand Down

0 comments on commit bbe698d

Please sign in to comment.