Skip to content

Fix linter issues after golangci-lint bump#4814

Merged
thardeck merged 1 commit intomainfrom
fix_new_linter_issues
Mar 13, 2026
Merged

Fix linter issues after golangci-lint bump#4814
thardeck merged 1 commit intomainfrom
fix_new_linter_issues

Conversation

@thardeck
Copy link
Collaborator

Remove stale nolint directives for gosec codes that no longer trigger at those locations; they were flagged by nolintlint.

Add G122 nolint annotations on os.ReadFile calls inside WalkDir callbacks in loaddirectory.go and filereader.go; the paths are over controlled directories and the TOCTOU risk is negligible.

Replace rw.WriteHeader+rw.Write in logAndReturn with http.Error, which sets Content-Type and X-Content-Type-Options headers and avoids reflecting error details in the HTTP response (G705).

Replace httptest.NewRequest with NewRequestWithContext in the webhook test to satisfy noctx.

Remove stale nolint directives for gosec codes that no longer
trigger at those locations; they were flagged by nolintlint.

Add G122 nolint annotations on os.ReadFile calls inside WalkDir
callbacks in loaddirectory.go and filereader.go; the paths are
over controlled directories and the TOCTOU risk is negligible.

Replace rw.WriteHeader+rw.Write in logAndReturn with http.Error,
which sets Content-Type and X-Content-Type-Options headers and
avoids reflecting error details in the HTTP response (G705).

Replace httptest.NewRequest with NewRequestWithContext in the
webhook test to satisfy noctx.
@thardeck thardeck self-assigned this Mar 13, 2026
@thardeck thardeck requested a review from a team as a code owner March 13, 2026 10:43
Copilot AI review requested due to automatic review settings March 13, 2026 10:43
@thardeck thardeck moved this to 👀 In review in Fleet Mar 13, 2026
Copy link
Contributor

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 cleans up and adjusts code to satisfy updated golangci-lint checks after a linter bump, including removing now-stale //nolint directives, adding narrowly scoped suppressions where new gosec findings are expected, and addressing noctx/HTTP-response security findings.

Changes:

  • Remove stale //nolint:gosec / //nolint directives that are no longer needed (as flagged by nolintlint).
  • Add targeted //nolint:gosec annotations for os.ReadFile usage inside WalkDir callbacks (G122).
  • Harden webhook error responses by switching to http.Error, and update a webhook test request to include a context.

Reviewed changes

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

Show a summary per file
File Description
pkg/webhook/webhook_test.go Uses a context-aware request constructor to satisfy noctx in tests.
pkg/webhook/webhook.go Replaces manual WriteHeader/Write with http.Error to avoid reflecting internal errors and set safer headers.
pkg/git/vendor.go Removes a stale //nolint:gosec on client.Do(req).
internal/ocistorage/ociwrapper.go Removes a stale //nolint:gosec on an intentional Password field.
internal/config/config.go Removes a stale //nolint:gosec on Bootstrap.Secret (resource name, not credential).
internal/cmd/controller/imagescan/update/filereader.go Adds G122 gosec suppression for os.ReadFile within a WalkDir traversal.
internal/cmd/controller/agentmanagement/controllers/cluster/import.go Removes a stale //nolint:gosec on http.DefaultClient.Do(req).
internal/cmd/cli/dump/dump.go Removes a stale //nolint:gosec on an HTTP request used for locally forwarded metrics.
internal/cmd/cli/apply/apply.go Removes a stale //nolint:gosec on an intentional Password field in CLI options.
internal/cmd/cli/apply.go Removes a stale //nolint:gosec on os.WriteFile to a temp path.
internal/cmd/cli/analyze.go Removes stale //nolint:gosec annotations on CLI stdout writes.
internal/cmd/agent/register/register.go Removes a stale //nolint:gosec on http.DefaultClient.Do(req) used for CA-bypass detection.
internal/bundlereader/loaddirectory.go Adds G122 suppression for os.ReadFile in WalkDir and removes a stale //nolint:gosec on temp-file cleanup.
internal/bundlereader/charturl.go Removes a stale //nolint:gosec on client.Do(request) fetching helm repo indexes.
internal/bundlereader/auth.go Removes a stale //nolint:gosec on Auth.Password field.
cmd/docs/generate-cli-docs.go Removes a stale //nolint:gosec on a stdout usage message.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@thardeck thardeck merged commit 2856903 into main Mar 13, 2026
26 checks passed
@thardeck thardeck deleted the fix_new_linter_issues branch March 13, 2026 11:39
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Fleet Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants