Skip to content

Commit ecc4f29

Browse files
fix issues reported by go-sec (#11) (#12)
* fix issues reported by go-sec
1 parent 9864220 commit ecc4f29

File tree

7 files changed

+27
-8
lines changed

7 files changed

+27
-8
lines changed

cmd/createUnbondingTxCmd.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ var (
2323

2424
FlagStakerWalletAddressHost = "staker-wallet-address-host"
2525
FlagStakerWalletRpcUser = "staker-wallet-rpc-user"
26-
FlagStakerWalletRpcPass = "staker-wallet-rpc-pass"
27-
FlagWalletPassphrase = "staker-wallet-passphrase"
26+
//#nosec G101 - false positive
27+
FlagStakerWalletRpcPass = "staker-wallet-rpc-pass"
28+
FlagWalletPassphrase = "staker-wallet-passphrase"
2829
)
2930

3031
func init() {

cmd/timestampFileCmd.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"os"
10+
"path/filepath"
1011

1112
"github.com/btcsuite/btcd/btcutil"
1213
"github.com/btcsuite/btcd/chaincfg"
@@ -119,6 +120,9 @@ func CreateTimestampTx(
119120
}
120121
fundingTxHash := fundingTx.TxHash()
121122
fundingInput := wire.NewTxIn(
123+
//#nosec G115 - in theory this function can be called with bogus transactions
124+
// with more than math.MaxUint32 outputs, but in practic caller would be shoting
125+
// himself in the foot.
122126
wire.NewOutPoint(&fundingTxHash, uint32(fundingOutputIdx)),
123127
nil,
124128
nil,
@@ -151,7 +155,9 @@ func CreateTimestampTx(
151155
}
152156

153157
func txOutTimestampFile(filePath string) (txOut *wire.TxOut, fileHash []byte, err error) {
154-
fileHash, err = hashFromFile(filePath)
158+
fileHash, err = hashFromFile(
159+
filepath.Clean(filePath),
160+
)
155161
if err != nil {
156162
return nil, nil, fmt.Errorf("failed to generate hash from file %s: %w", filePath, err)
157163
}
@@ -167,7 +173,9 @@ func txOutTimestampFile(filePath string) (txOut *wire.TxOut, fileHash []byte, er
167173
func hashFromFile(filePath string) ([]byte, error) {
168174
h := sha256.New()
169175

170-
f, err := os.Open(filePath)
176+
f, err := os.Open(
177+
filepath.Clean(filePath),
178+
)
171179
if err != nil {
172180
return nil, fmt.Errorf("failed to open the file %s: %w", filePath, err)
173181
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.22.4
66

77
require (
88
github.com/babylonlabs-io/babylon v0.9.0
9-
github.com/babylonlabs-io/covenant-signer v0.2.9
9+
github.com/babylonlabs-io/covenant-signer v0.2.11
1010
github.com/babylonlabs-io/networks/parameters v0.2.2
1111
github.com/btcsuite/btcd v0.24.2
1212
github.com/btcsuite/btcd/btcec/v2 v2.3.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8
279279
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
280280
github.com/babylonlabs-io/babylon v0.9.0 h1:dHZ9wUrI5XLaO4UIwJRgiCdnzFdi5yv7dpibbu6TDv0=
281281
github.com/babylonlabs-io/babylon v0.9.0/go.mod h1:t7B4e+ooD2oYvAxkegtNKDL9bXe+vU29a8xnCQh+UKo=
282-
github.com/babylonlabs-io/covenant-signer v0.2.9 h1:3euelxnA7OYCDWSPsczTiTCjKulJBRnIfU3kNqYX6VE=
283-
github.com/babylonlabs-io/covenant-signer v0.2.9/go.mod h1:ju9+U2wtIhklSOwTxp+3NA+S/sC4gak9+DeyK9qQi80=
282+
github.com/babylonlabs-io/covenant-signer v0.2.11 h1:lQiT5TR2ob0Sky99URhpqrfqImJw14gP63ASd2UJwaE=
283+
github.com/babylonlabs-io/covenant-signer v0.2.11/go.mod h1:ju9+U2wtIhklSOwTxp+3NA+S/sC4gak9+DeyK9qQi80=
284284
github.com/babylonlabs-io/networks/parameters v0.2.2 h1:TCu39fZvjX5f6ZZrjhYe54M6wWxglNewuKu56yE+zrc=
285285
github.com/babylonlabs-io/networks/parameters v0.2.2/go.mod h1:iEJVOzaLsE33vpP7J4u+CRGfkSIfErUAwRmgCFCBpyI=
286286
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=

internal/config/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import (
1111
"github.com/spf13/viper"
1212
)
1313

14+
const (
15+
folderPermissions = 0750
16+
)
17+
1418
type Config struct {
1519
Db DbConfig `mapstructure:"db-config"`
1620
Btc BtcConfig `mapstructure:"btc-config"`
@@ -104,7 +108,7 @@ func WriteConfigToFile(pathToConfFile string, conf *Config) error {
104108
dirPath, _ := filepath.Split(pathToConfFile)
105109

106110
if _, err := os.Stat(pathToConfFile); os.IsNotExist(err) {
107-
if err := os.MkdirAll(dirPath, os.ModePerm); err != nil {
111+
if err := os.MkdirAll(dirPath, folderPermissions); err != nil {
108112
return fmt.Errorf("couldn't make config: %v", err)
109113
}
110114

internal/services/persistent_store.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ func documentToData(d *model.UnbondingDocument) (*UnbondingTxData, error) {
121121
}
122122

123123
// TODO: Check if there are better types at mongo level
124+
//#nosec G115 - safe conversion, data is coming from the database and
125+
// data in db is always validated
124126
stakingValue := btcutil.Amount(int64(d.StakingAmount))
127+
//#nosec G115 - safe conversion, data is coming from the database and
128+
// data in db is always validated
125129
stakingTime := uint16(d.StakingTimelock)
126130

127131
si := &StakingInfo{
@@ -183,6 +187,7 @@ func (s *PersistentUnbondingStorage) AddTxWithSignature(
183187
stakingtTxData.StakingOutputIdx,
184188
stakingTxHashHex,
185189
uint64(info.StakingTimelock),
190+
//#nosec G115 - safe conversion, staking amoutn will always be positive
186191
uint64(info.StakingAmount),
187192
)
188193

internal/services/unbonding_pipeline.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ func (up *UnbondingPipeline) processUnbondingTransactions(
409409
utx.UnbondingTransaction.TxIn[0].Witness = witness
410410

411411
// TODO do we need to check the mempool?
412+
//#nosec G115 - data is coming from the database, so this is valid staking transaction
412413
spendable, err := up.sender.CheckTxOutSpendable(&stakingTxHash, uint32(utx.StakingTransactionData.StakingOutputIdx), true)
413414
if err != nil {
414415
up.logger.Error("Failed to check whether the staking output is spendable", "error", err)

0 commit comments

Comments
 (0)