Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security: Enable gosec G112 rule #10333

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ linters-settings:
includes:
- G108
- G109
- G112
- G114

run:
Expand Down
10 changes: 9 additions & 1 deletion pkg/frontend/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func TestFrontend_RequestHostHeaderWhenDownstreamURLIsConfigured(t *testing.T) {
_, err := w.Write([]byte(responseBody))
require.NoError(t, err)
}),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}

defer downstreamServer.Shutdown(context.Background()) //nolint:errcheck
Expand Down Expand Up @@ -111,6 +113,8 @@ func TestFrontend_LogsSlowQueriesFormValues(t *testing.T) {
_, err := w.Write([]byte(responseBody))
require.NoError(t, err)
}),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}

defer downstreamServer.Shutdown(context.Background()) //nolint:errcheck
Expand Down Expand Up @@ -173,6 +177,8 @@ func TestFrontend_ReturnsRequestBodyTooLargeError(t *testing.T) {
_, err := w.Write([]byte(responseBody))
require.NoError(t, err)
}),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}

defer downstreamServer.Shutdown(context.Background()) //nolint:errcheck
Expand Down Expand Up @@ -260,7 +266,9 @@ func testFrontend(t *testing.T, config CombinedFrontendConfig, handler http.Hand
).Wrap(transport.NewHandler(config.Handler, rt, logger, nil, nil)))

httpServer := http.Server{
Handler: r,
Handler: r,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
defer httpServer.Shutdown(context.Background()) //nolint:errcheck

Expand Down
4 changes: 3 additions & 1 deletion pkg/frontend/v1/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ func testFrontend(t *testing.T, config Config, handler http.Handler, test func(a
).Wrap(transport.NewHandler(handlerCfg, rt, logger, nil, nil)))

httpServer := http.Server{
Handler: r,
Handler: r,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
defer httpServer.Shutdown(context.Background()) //nolint:errcheck

Expand Down
5 changes: 4 additions & 1 deletion pkg/util/gziphandler/gzip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"os"
"strconv"
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -279,7 +280,9 @@ func TestGzipHandlerContentLength(t *testing.T) {
}
defer ln.Close()
srv := &http.Server{
Handler: nil,
Handler: nil,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
go func() { _ = srv.Serve(ln) }()

Expand Down
5 changes: 4 additions & 1 deletion pkg/util/instrumentation/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"net"
"net/http"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand Down Expand Up @@ -45,7 +46,9 @@ func (s *MetricsServer) Start() error {
router.Handle("/metrics", promhttp.HandlerFor(s.registry, promhttp.HandlerOpts{}))

s.srv = &http.Server{
Handler: router,
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}

go func() {
Expand Down
Loading