Skip to content

Commit 83f1562

Browse files
authored
Security improvements (#234)
1 parent 0f2abc5 commit 83f1562

File tree

16 files changed

+344
-253
lines changed

16 files changed

+344
-253
lines changed

.github/workflows/claude-code-review.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ jobs:
9292
repository: ${{ steps.pr.outputs.repo_full_name }}
9393
ref: ${{ steps.pr.outputs.head_sha }}
9494
fetch-depth: 0
95+
persist-credentials: false # Security: Don't store git credentials for fork code
9596

9697
- name: Run Claude Code Review
9798
if: steps.pr.outputs.is_draft == 'false'

.github/workflows/cleanup_gh_cache.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: cleanup-gh-cache
22
on: workflow_dispatch
3+
4+
permissions:
5+
actions: write # Required for gh cache list and delete
6+
37
jobs:
48
cleanup:
59
runs-on: ubuntu-latest

.github/workflows/long_tests.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
required: false
88
type: string
99

10+
permissions:
11+
contents: read # Required for checkout
12+
1013
env:
1114
REPO: teranode
1215
SETTINGS_CONTEXT_DEFAULT: test

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ require (
8585
github.com/bsv-blockchain/go-bc v1.0.2 // indirect
8686
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
8787
github.com/containerd/containerd/api v1.9.0 // indirect
88-
github.com/containerd/containerd/v2 v2.1.4 // indirect
88+
github.com/containerd/containerd/v2 v2.1.5 // indirect
8989
github.com/containerd/errdefs v1.0.0 // indirect
9090
github.com/containerd/errdefs/pkg v0.3.0 // indirect
9191
github.com/containerd/platforms v1.0.0-rc.2 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ github.com/containerd/console v1.0.5 h1:R0ymNeydRqH2DmakFNdmjR2k0t7UPuiOV/N/27/q
213213
github.com/containerd/console v1.0.5/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
214214
github.com/containerd/containerd/api v1.9.0 h1:HZ/licowTRazus+wt9fM6r/9BQO7S0vD5lMcWspGIg0=
215215
github.com/containerd/containerd/api v1.9.0/go.mod h1:GhghKFmTR3hNtyznBoQ0EMWr9ju5AqHjcZPsSpTKutI=
216-
github.com/containerd/containerd/v2 v2.1.4 h1:/hXWjiSFd6ftrBOBGfAZ6T30LJcx1dBjdKEeI8xucKQ=
217-
github.com/containerd/containerd/v2 v2.1.4/go.mod h1:8C5QV9djwsYDNhxfTCFjWtTBZrqjditQ4/ghHSYjnHM=
216+
github.com/containerd/containerd/v2 v2.1.5 h1:pWSmPxUszaLZKQPvOx27iD4iH+aM6o0BoN9+hg77cro=
217+
github.com/containerd/containerd/v2 v2.1.5/go.mod h1:8C5QV9djwsYDNhxfTCFjWtTBZrqjditQ4/ghHSYjnHM=
218218
github.com/containerd/continuity v0.4.5 h1:ZRoN1sXq9u7V6QoHMcVWGhOwDFqZ4B9i5H6un1Wh0x4=
219219
github.com/containerd/continuity v0.4.5/go.mod h1:/lNJvtJKUQStBzpVQ1+rasXO1LAWtUQssk28EZvJ3nE=
220220
github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=

services/asset/httpimpl/GetBlocks.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ func (h *HTTP) GetBlocks(c echo.Context) error {
124124
}
125125

126126
latestBlockHeight := blockMeta.Height
127-
fromHeight := latestBlockHeight - uint32(offset) //nolint:gosec
127+
128+
// Validate offset doesn't exceed block height to prevent underflow
129+
if uint32(offset) > latestBlockHeight {
130+
return echo.NewHTTPError(http.StatusBadRequest, errors.NewInvalidArgumentError("offset exceeds block height").Error())
131+
}
132+
133+
fromHeight := latestBlockHeight - uint32(offset)
128134

129135
h.logger.Debugf("[Asset_http] GetBlockChain for %s with offset = %d, limit = %d and fromHeight = %d", c.Request().RemoteAddr, offset, limit, fromHeight)
130136

services/asset/httpimpl/helpers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ func (h *HTTP) getLimitOffset(c echo.Context) (int, int, error) {
8080
}
8181
}
8282

83+
// Validate offset is non-negative to prevent underflow issues
84+
if offset < 0 {
85+
return 0, 0, echo.NewHTTPError(http.StatusBadRequest, errors.NewInvalidArgumentError("offset must be non-negative").Error())
86+
}
87+
8388
limit := 20
8489
limitStr := c.QueryParam("limit")
8590

@@ -90,6 +95,11 @@ func (h *HTTP) getLimitOffset(c echo.Context) (int, int, error) {
9095
}
9196
}
9297

98+
// Validate limit bounds to prevent allocation issues
99+
if limit < 1 {
100+
limit = 1
101+
}
102+
93103
if limit > 100 {
94104
limit = 100
95105
}

services/legacy/addrmgr/addrmanager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ func (a *AddrManager) AddAddressByIP(addrIP string) error {
774774
return fmt.Errorf("invalid ip address %s", addr)
775775
}
776776

777-
port, err := strconv.ParseUint(portStr, 10, 0)
777+
port, err := strconv.ParseUint(portStr, 10, 16)
778778
if err != nil {
779779
return fmt.Errorf("invalid port %s: %v", portStr, err)
780780
}

services/legacy/connmgr/seed.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ func SeedFromDNS(chainParams *chaincfg.Params, reqServices wire.ServiceFlag,
5858
}
5959

6060
addresses := make([]*wire.NetAddress, len(seedpeers))
61-
// if this errors then we have *real* problems
62-
intPort, _ := strconv.Atoi(chainParams.DefaultPort)
61+
// Parse port as uint16 directly to avoid integer conversion issues
62+
port, err := strconv.ParseUint(chainParams.DefaultPort, 10, 16)
63+
if err != nil {
64+
// Invalid port configuration, skip this seed
65+
return
66+
}
6367

6468
for i, peer := range seedpeers {
6569
randSource := mrand.NewPCG(uint64(time.Now().UnixNano()), uint64(secondsIn4Days))
@@ -70,7 +74,7 @@ func SeedFromDNS(chainParams *chaincfg.Params, reqServices wire.ServiceFlag,
7074
// a time randomly selected between 3
7175
// and 7 days ago.
7276
time.Now().Add(-1*time.Second*time.Duration(secondsIn3Days+rand.Int32N(secondsIn4Days))),
73-
0, peer, uint16(intPort))
77+
0, peer, uint16(port))
7478
}
7579

7680
seedFn(addresses)

stores/blob/factory.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ func createDAHStore(storeURL *url.URL, logger ulogger.Logger, opts []options.Sto
167167
// - error: Any error that occurred during creation, particularly if the batcher
168168
// cannot be properly configured with the provided parameters
169169
func createBatchedStore(storeURL *url.URL, store Store, logger ulogger.Logger) (Store, error) {
170-
sizeInBytes := int64(4 * 1024 * 1024)
170+
sizeInBytes := 4 * 1024 * 1024
171171

172172
sizeString := storeURL.Query().Get("sizeInBytes")
173173
if sizeString != "" {
174174
var err error
175175

176-
sizeInBytes, err = strconv.ParseInt(sizeString, 10, 64)
176+
sizeInBytes, err = strconv.Atoi(sizeString)
177177
if err != nil {
178178
return nil, errors.NewConfigurationError("error parsing batch size", err)
179179
}
@@ -184,7 +184,7 @@ func createBatchedStore(storeURL *url.URL, store Store, logger ulogger.Logger) (
184184
writeKeys = true
185185
}
186186

187-
store = batcher.New(logger, store, int(sizeInBytes), writeKeys)
187+
store = batcher.New(logger, store, sizeInBytes, writeKeys)
188188

189189
return store, nil
190190
}

0 commit comments

Comments
 (0)