Skip to content

Commit 57ee375

Browse files
committed
security fixes
1 parent 2e9da20 commit 57ee375

8 files changed

Lines changed: 19 additions & 19 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Data file with modules for [exporter_exporter](https://github.com/QubitProducts/
8282
}
8383
```
8484

85-
Prometheus SD config with
85+
Prometheus SD config with
8686
[relabel_config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config) example
8787
```yaml
8888
scrape_configs:
@@ -133,7 +133,7 @@ docker build -t ghcr.io/code-tool/inventor/inventor:$(cat VERSION.txt) --build-a
133133
```
134134
pulling image:
135135
```bash
136-
ghcr.io/code-tool/inventor/inventor:0.2.0
136+
ghcr.io/code-tool/inventor/inventor:0.3.0
137137
```
138138

139139
## License

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.0
1+
0.3.0

charts/inventor/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apiVersion: v2
22
name: inventor
3-
version: 0.2.0
3+
version: 0.3.0
44
sources:
55
- https://github.com/shcherbak/inventor

charts/inventor/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ secret:
1313
SD_TOKEN: 'ChangeMe'
1414

1515
main:
16-
image: "ghcr.io/code-tool/inventor/inventor:0.2.0"
16+
image: "ghcr.io/code-tool/inventor/inventor:0.3.0"
1717
pullPolicy: "IfNotPresent"
1818

1919
redis:
2020
enabled: true
21-
image: "redis:8.2.3"
21+
image: "redis:8.2.5"
2222
pullPolicy: "IfNotPresent"
2323

2424
service:

docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
FROM golang:1.25.5-trixie AS builder
2-
ARG BUILD_VERSION='0.2.0'
1+
FROM golang:1.25.9-trixie AS builder
2+
ARG BUILD_VERSION='0.3.0'
33
ENV LISTEN_PORT=9101
44
WORKDIR /opt/inventor/
55
COPY go.mod ./

src/handler/middleware.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"strings"
1010
"sync"
11+
"crypto/subtle"
1112

1213
"github.com/google/uuid"
1314
"github.com/redis/go-redis/v9"
@@ -140,6 +141,7 @@ func (s *SDTargetsMiddleware) handleGetByGroupName(w http.ResponseWriter, r *htt
140141
}
141142

142143
func (s *SDTargetsMiddleware) handleInsert(w http.ResponseWriter, r *http.Request) {
144+
r.Body = http.MaxBytesReader(w, r.Body, 64*1024) // 64 KB
143145
var req StaticConfigDocument
144146
var res IDDocument
145147
err := json.NewDecoder(r.Body).Decode(&req)
@@ -162,6 +164,7 @@ func (s *SDTargetsMiddleware) handleInsert(w http.ResponseWriter, r *http.Reques
162164
}
163165

164166
func (s *SDTargetsMiddleware) handleDelete(w http.ResponseWriter, r *http.Request) {
167+
r.Body = http.MaxBytesReader(w, r.Body, 64*1024)
165168
var req IDDocument
166169
err := json.NewDecoder(r.Body).Decode(&req)
167170
if err != nil {
@@ -181,6 +184,7 @@ func (s *SDTargetsMiddleware) handleDelete(w http.ResponseWriter, r *http.Reques
181184
}
182185

183186
func (s *SDTargetsMiddleware) handleGetByID(w http.ResponseWriter, r *http.Request) {
187+
r.Body = http.MaxBytesReader(w, r.Body, 64*1024)
184188
var req IDDocument
185189
err := json.NewDecoder(r.Body).Decode(&req)
186190
if err != nil {
@@ -212,20 +216,12 @@ func (s *SDTargetsMiddleware) HealthCheck(w http.ResponseWriter, r *http.Request
212216

213217
func (s *SDTargetsMiddleware) isApiTokenValid(r *http.Request) bool {
214218
token := r.Header.Get("x-api-token")
215-
if token != s.ApiToken {
216-
return false
217-
} else {
218-
return true
219-
}
219+
return subtle.ConstantTimeCompare([]byte(token), []byte(s.ApiToken)) == 1
220220
}
221221

222222
func (s *SDTargetsMiddleware) isSdTokenValid(r *http.Request) bool {
223223
token := r.Header.Get("x-sd-token")
224-
if token != s.SdToken {
225-
return false
226-
} else {
227-
return true
228-
}
224+
return subtle.ConstantTimeCompare([]byte(token), []byte(s.SdToken)) == 1
229225
}
230226

231227
func (s *SDTargetsMiddleware) forbiddenResponse(w http.ResponseWriter) {

src/handler/targets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (c *SDTargets) Scan(ctx context.Context, con *redis.Client) (SDTargets, err
8686
}
8787
}
8888
if err := iter.Err(); err != nil {
89-
panic(err)
89+
return targets, err
9090
}
9191
return targets, nil
9292
}

src/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strconv"
1414
"sync"
1515
"syscall"
16+
"time"
1617

1718
"github.com/google/uuid"
1819
"github.com/prometheus/client_golang/prometheus"
@@ -76,6 +77,9 @@ func configureServer() {
7677
server = &http.Server{
7778
Addr: fmt.Sprintf(":%s", config.GetConfig().LISTEN_PORT),
7879
Handler: nil,
80+
ReadTimeout: 10 * time.Second,
81+
WriteTimeout: 30 * time.Second,
82+
IdleTimeout: 60 * time.Second,
7983
}
8084
server.RegisterOnShutdown(func() {
8185
log.Println("Shutting down server.")

0 commit comments

Comments
 (0)