Skip to content

Commit d5d5b73

Browse files
committed
Fix linter issues after golangci-lint bump
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.
1 parent 07d14eb commit d5d5b73

File tree

16 files changed

+18
-19
lines changed

16 files changed

+18
-19
lines changed

cmd/docs/generate-cli-docs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,5 @@ sidebar_label: "%s"
153153
}
154154

155155
func usage() {
156-
fmt.Fprintln(os.Stdout, "Usage: ", os.Args[0], " <directory>") //nolint:gosec // G705 false positive: output goes to stdout, not an HTTP response writer
156+
fmt.Fprintln(os.Stdout, "Usage: ", os.Args[0], " <directory>")
157157
}

internal/bundlereader/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
type Auth struct {
1717
Username string `json:"username,omitempty"`
18-
Password string `json:"password,omitempty"` //nolint:gosec // G117 false positive: Password is an intentional field in the Helm chart auth config
18+
Password string `json:"password,omitempty"`
1919
CABundle []byte `json:"caBundle,omitempty"`
2020
SSHPrivateKey []byte `json:"sshPrivateKey,omitempty"`
2121
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`

internal/bundlereader/charturl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func getHelmRepoIndex(ctx context.Context, repoURL string, auth Auth) (helmRepoI
162162

163163
client := getHTTPClient(auth)
164164

165-
resp, err := client.Do(request) //nolint:gosec // G704 false positive: URL is the user-configured Helm chart repository
165+
resp, err := client.Do(request)
166166
if err != nil {
167167
return nil, fmt.Errorf("failed to fetch %q: %w", indexURL, err)
168168
}

internal/bundlereader/loaddirectory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func GetContent(ctx context.Context, base, source, version string, auth Auth, di
319319
return nil
320320
}
321321

322-
content, err := os.ReadFile(path)
322+
content, err := os.ReadFile(path) //nolint:gosec // G122: path is from WalkDir over a go-getter controlled temp directory
323323
if err != nil {
324324
return err
325325
}
@@ -432,7 +432,7 @@ func get(ctx context.Context, client Getter, req *getter.Request, auth Auth) err
432432
}
433433
defer func() {
434434
file.Close()
435-
os.Remove(file.Name()) //nolint:gosec // G703 false positive: path comes from os.CreateTemp, not user-controlled data
435+
os.Remove(file.Name())
436436
}()
437437

438438
if _, err := file.Write(auth.CABundle); err != nil {

internal/cmd/agent/register/register.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func createClientConfigFromSecret(ctx context.Context, secret *corev1.Secret, tr
301301
// NOTE(manno): client-go will use the system trust store even if a CA is configured. So, why do this?
302302
req, err := http.NewRequestWithContext(ctx, http.MethodGet, apiServerURL, nil)
303303
if err == nil {
304-
if resp, err := http.DefaultClient.Do(req); err == nil { //nolint:gosec // G704 false positive: URL is the Kubernetes API server from admin-configured kubeconfig
304+
if resp, err := http.DefaultClient.Do(req); err == nil {
305305
resp.Body.Close()
306306
apiServerCA = nil
307307
}

internal/cmd/cli/analyze.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ func (a *Analyze) compareFiles(cmd *cobra.Command, file1, file2 string) error {
206206
}
207207

208208
troubleshooting.PrintHeader(w, "COMPARING SNAPSHOTS")
209-
fmt.Fprintf(w, "Before: %s (%s)\n", file1, before.Timestamp) //nolint:gosec // G705 false positive: w is a CLI stdout writer, not an HTTP ResponseWriter
210-
fmt.Fprintf(w, "After: %s (%s)\n", file2, after.Timestamp) //nolint:gosec // G705 false positive: w is a CLI stdout writer, not an HTTP ResponseWriter
209+
fmt.Fprintf(w, "Before: %s (%s)\n", file1, before.Timestamp)
210+
fmt.Fprintf(w, "After: %s (%s)\n", file2, after.Timestamp)
211211

212212
troubleshooting.PrintSnapshotDiff(w, before, after)
213213

internal/cmd/cli/apply.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func writeTmpKnownHosts() (string, error) {
270270

271271
knownHostsPath := f.Name()
272272

273-
if err := os.WriteFile(knownHostsPath, []byte(knownHosts), 0600); err != nil { //nolint:gosec // G703 false positive: path is generated by os.CreateTemp, not user-controlled
273+
if err := os.WriteFile(knownHostsPath, []byte(knownHosts), 0600); err != nil {
274274
return "", fmt.Errorf(
275275
"failed to write value of %q env var to known_hosts file %s: %w",
276276
ssh.KnownHostsEnvVar,

internal/cmd/cli/apply/apply.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type Getter interface {
6363
type OCIRegistrySpec struct {
6464
Reference string
6565
Username string
66-
Password string //nolint:gosec // G117 false positive: Password is an intentional field in the apply options
66+
Password string
6767
BasicHTTP bool
6868
InsecureSkipTLS bool
6969
}

internal/cmd/cli/dump/dump.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ func addMetricsToArchive(ctx context.Context, c client.Client, logger logr.Logge
531531
return fmt.Errorf("failed to create request to metrics service: %w", err)
532532
}
533533

534-
resp, err := httpCli.Do(req) //nolint:gosec // G704 false positive: URL always targets localhost via kubectl port-forward, not an arbitrary server
534+
resp, err := httpCli.Do(req)
535535
if err != nil {
536536
return fmt.Errorf("failed to get response from metrics service: %w", err)
537537
}

internal/cmd/controller/agentmanagement/controllers/cluster/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ func (i *importHandler) restConfigFromKubeConfig(data []byte, agentTLSMode strin
549549
if raw.Clusters[cluster] != nil {
550550
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, raw.Clusters[cluster].Server, nil)
551551
if err == nil {
552-
if resp, err := http.DefaultClient.Do(req); err == nil { //nolint:gosec // G704 false positive: URL is the Kubernetes API server from admin-configured kubeconfig
552+
if resp, err := http.DefaultClient.Do(req); err == nil {
553553
resp.Body.Close()
554554
raw.Clusters[cluster].CertificateAuthorityData = nil
555555
}

0 commit comments

Comments
 (0)