Skip to content

Fix all gosec linter warnings#43

Merged
JamieMagee merged 1 commit intomainfrom
jamiemagee/fix-gosec-issues
Feb 10, 2026
Merged

Fix all gosec linter warnings#43
JamieMagee merged 1 commit intomainfrom
jamiemagee/fix-gosec-issues

Conversation

@JamieMagee
Copy link
Copy Markdown
Member

@JamieMagee JamieMagee commented Feb 10, 2026

The gosec linter was reporting 27 warnings across the codebase. This PR fixes all of them.

What changed

Security hardening (source files):

  • main.go: Added ReadHeaderTimeout to the HTTP server to prevent Slowloris attacks (G112)
  • proxy.go: Set MinVersion: tls.VersionTLS12 on the TLS config (G402)
  • internal/cache/handlers.go: Tightened directory permissions from 0755 to 0750 (G301), and wrapped file paths with filepath.Clean before opening (G304)
  • internal/config/config.go: Wrapped file path with filepath.Clean before opening (G304)
  • internal/oidc/actions_oidc.go: Added overflow guard for uint-to-int64 conversion when computing token expiry (G115)

Test file cleanup:

  • Added ReadHeaderTimeout and MinVersion to test servers in proxy_test.go (G112, G402)
  • Tightened WriteFile permissions from 0644 to 0600 in config_test.go (G306)
  • Wrapped os.ReadFile path with filepath.Clean in logging_test.go (G304)
  • Added //nolint:gosec annotations to test variables flagged as hardcoded credentials -- these are fake tokens used only in tests (G101)

- Set ReadHeaderTimeout on http.Server to prevent Slowloris attacks (G112)
- Set TLS MinVersion to 1.2 on tls.Config (G402)
- Tighten directory permissions from 0755 to 0750 (G301)
- Tighten file write permissions from 0644 to 0600 in tests (G306)
- Sanitize file paths with filepath.Clean before opening (G304)
- Guard uint-to-int64 conversion with overflow check (G115)
- Add nolint annotations for false-positive credential detections in
  test data and env var constant names (G101)
Copilot AI review requested due to automatic review settings February 10, 2026 21:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses all 27 gosec linter warnings across the codebase by implementing security hardening measures in source files and cleaning up test files.

Changes:

  • Added security hardening to production code: ReadHeaderTimeout for HTTP servers, TLS 1.2 minimum version enforcement, tightened file permissions, filepath cleaning, and overflow guards for type conversions
  • Updated test infrastructure with the same security settings (ReadHeaderTimeout, TLS MinVersion)
  • Added nolint annotations for legitimate test fixtures flagged as hardcoded credentials

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
main.go Added ReadHeaderTimeout to production HTTP server to prevent Slowloris attacks
proxy.go Set MinVersion to TLS 1.2 in TLS client config to prevent use of insecure TLS versions
proxy_test.go Added ReadHeaderTimeout to test HTTP servers and MinVersion to test TLS client config
internal/oidc/actions_oidc.go Added overflow guard for uint-to-int64 conversion when computing token expiry, plus nolint annotations for false positive gosec warnings on constant strings
internal/config/config.go Wrapped file path with filepath.Clean before opening to prevent path traversal
internal/config/config_test.go Tightened file permissions from 0644 to 0600 for test config files
internal/cache/handlers.go Tightened directory permissions from 0755 to 0750 and wrapped file paths with filepath.Clean before operations
logging_test.go Wrapped os.ReadFile path with filepath.Clean
internal/handlers/python_index_test.go Added nolint annotations for test credential variables
internal/handlers/pub_repository_test.go Added nolint annotations for test credential variables
internal/handlers/oidc_handling_test.go Added nolint annotation for test URL variable
internal/handlers/github_api_test.go Added nolint annotations for test credential variables
internal/handlers/git_server_test.go Added nolint annotations for test credential variables
internal/handlers/cargo_registry_test.go Added nolint annotations for test credential variables
internal/apiclient/client_test.go Added nolint annotation for test credential constant

@JamieMagee JamieMagee merged commit 2308f4c into main Feb 10, 2026
97 of 100 checks passed
@JamieMagee JamieMagee deleted the jamiemagee/fix-gosec-issues branch February 10, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants