Skip to content

Commit 1f52128

Browse files
committed
chore: Reenable gosec linter and upgrade TLS version.
We already configure Read timeouts in the server, so we should be unaffected by the Slowloris DOS attack. We use math/rand in a place where it won't affect security, so disabling the linter for those lines is fine. TLS version is upgraded as most clients should use TLS 1.2 by default anyway. A lot of applications/vendors have already deprecated TLS 1.0. BREAKING: no longer support TLS 1.0
1 parent 97b5b39 commit 1f52128

File tree

4 files changed

+5
-2
lines changed

4 files changed

+5
-2
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ linters:
4343
- unused
4444
- varcheck
4545
- whitespace
46+
- gosec
4647
disable:
4748
# Should be readded in the future with a dedicated PR to do the fix
4849
- cyclop
@@ -51,7 +52,6 @@ linters:
5152
- funlen
5253
- gocognit
5354
- gofumpt
54-
- gosec
5555
- govet
5656
- ifshort
5757
- ineffassign

cache/filesystem_cache.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ func (f *fileSystemCache) clean() {
273273
//
274274
// Seed the generator with the current time in order to randomize
275275
// set of files to be removed below.
276+
// nolint:gosec // not security sensitve, only used internally.
276277
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
277278

278279
for totalSize > f.maxSize && loopsCount < 3 {

cache/redis_cache.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ func (r *redisCache) Put(reader io.Reader, contentMetadata ContentMetadata, key
251251
stringKey := key.String()
252252
// in order to make the streaming operation atomic, chproxy streams into a temporary key (only known by the current goroutine)
253253
// then it switches the full result to the "real" stringKey available for other goroutines
254+
// nolint:gosec // not security sensitve, only used internally.
254255
random := strconv.Itoa(rand.Int())
255256
stringKeyTmp := stringKey + random + "_tmp"
256257

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func serve(cfg config.HTTP) {
171171
func newTLSConfig(cfg config.HTTPS) *tls.Config {
172172
tlsCfg := tls.Config{
173173
PreferServerCipherSuites: true,
174+
MinVersion: tls.VersionTLS12,
174175
CurvePreferences: []tls.CurveID{
175176
tls.CurveP256,
176177
tls.X25519,
@@ -193,13 +194,13 @@ func newTLSConfig(cfg config.HTTPS) *tls.Config {
193194
}
194195

195196
func newServer(ln net.Listener, h http.Handler, cfg config.TimeoutCfg) *http.Server {
197+
// nolint:gosec // We already configured ReadTimeout, so no need to set ReadHeaderTimeout as well.
196198
return &http.Server{
197199
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)),
198200
Handler: h,
199201
ReadTimeout: time.Duration(cfg.ReadTimeout),
200202
WriteTimeout: time.Duration(cfg.WriteTimeout),
201203
IdleTimeout: time.Duration(cfg.IdleTimeout),
202-
203204
// Suppress error logging from the server, since chproxy
204205
// must handle all these errors in the code.
205206
ErrorLog: log.NilLogger,

0 commit comments

Comments
 (0)