Skip to content

Commit caf6852

Browse files
committed
fix: resolve remaining golangci-lint 2.10.1 taint-analysis findings
Suppress false-positive gosec G703 (path traversal) and G704 (SSRF) findings from stricter taint analysis in golangci-lint 2.10.1. Also exclude modernize/newexpr check globally — it incorrectly suggests replacing ptr(true) with new(bool), but new(T) only produces zero-value pointers.
1 parent f0ca0ea commit caf6852

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

.golangci.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,8 @@ linters:
8686
- linters:
8787
- staticcheck
8888
text: 'ST1005:'
89+
# modernize newexpr false positives: ptr(true) cannot be simplified to new(bool)
90+
# because new(T) only produces zero-value pointers
91+
- linters:
92+
- modernize
93+
text: 'newexpr:'

integration-tests/harness/harness.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ func (h *Harness) cmdCurl(ts *testscript.TestScript, neg bool, args []string) {
521521
req.Header.Set(h[0], h[1])
522522
}
523523

524-
resp, err := client.Do(req)
524+
resp, err := client.Do(req) //nolint:gosec // G704: URL from test harness, not user input
525525
if err != nil {
526526
lastErr = err
527527
time.Sleep(retryDelay)

pkg/dockerfile/cacert.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func ReadCACert() ([]byte, error) {
4444
value = strings.TrimSpace(value)
4545

4646
// Check if it's a file path
47-
if info, err := os.Stat(value); err == nil {
47+
if info, err := os.Stat(value); err == nil { //nolint:gosec // G703: path from trusted COG_CA_CERT env var
4848
if info.IsDir() {
4949
return readCACertDirectory(value)
5050
}
@@ -67,7 +67,7 @@ func ReadCACert() ([]byte, error) {
6767

6868
// readCACertFile reads a single certificate file
6969
func readCACertFile(path string) ([]byte, error) {
70-
data, err := os.ReadFile(path)
70+
data, err := os.ReadFile(path) //nolint:gosec // G703: path from trusted COG_CA_CERT env var
7171
if err != nil {
7272
return nil, fmt.Errorf("%s: failed to read file %s: %w", CACertEnvVar, path, err)
7373
}
@@ -93,7 +93,7 @@ func readCACertDirectory(dir string) ([]byte, error) {
9393
}
9494

9595
path := filepath.Join(dir, entry.Name())
96-
data, err := os.ReadFile(path)
96+
data, err := os.ReadFile(path) //nolint:gosec // G703: path from trusted COG_CA_CERT env var directory
9797
if err != nil {
9898
return nil, fmt.Errorf("%s: failed to read file %s: %w", CACertEnvVar, path, err)
9999
}

pkg/model/image_pusher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ func (p *ImagePusher) ociPush(ctx context.Context, imageRef string, opt imagePus
129129
if err != nil {
130130
return fmt.Errorf("create temp tar file: %w", err)
131131
}
132-
defer func() { _ = os.Remove(tmpTar.Name()) }()
133-
defer tmpTar.Close() //nolint:errcheck
132+
defer func() { _ = os.Remove(tmpTar.Name()) }() //nolint:gosec // G703: path from os.CreateTemp, not user input
133+
defer tmpTar.Close() //nolint:errcheck
134134

135135
if _, err := io.Copy(tmpTar, rc); err != nil {
136136
return fmt.Errorf("write image tar: %w", err)

pkg/predict/predictor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (p *Predictor) waitForContainerReady(ctx context.Context, timeout time.Dura
127127
return nil, fmt.Errorf("Failed to create HTTP request to %s: %w", url, err)
128128
}
129129

130-
resp, err := http.DefaultClient.Do(req)
130+
resp, err := http.DefaultClient.Do(req) //nolint:gosec // G704: URL from localhost health check
131131
if err != nil {
132132
return nil, nil
133133
}
@@ -190,7 +190,7 @@ func (p *Predictor) Predict(inputs Inputs, context RequestContext) (*Response, e
190190
req.Close = true
191191

192192
httpClient := &http.Client{}
193-
resp, err := httpClient.Do(req)
193+
resp, err := httpClient.Do(req) //nolint:gosec // G704: URL from localhost prediction endpoint
194194
if err != nil {
195195
return nil, fmt.Errorf("Failed to POST HTTP request to %s: %w", url, err)
196196
}

pkg/registry/registry_client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ func (c *RegistryClient) checkBlobExists(ctx context.Context, client *http.Clien
592592
return false, err
593593
}
594594

595-
resp, err := client.Do(req)
595+
resp, err := client.Do(req) //nolint:gosec // G704: URL from registry reference, not user input
596596
if err != nil {
597597
return false, err
598598
}
@@ -660,7 +660,7 @@ func (c *RegistryClient) initiateUpload(ctx context.Context, client *http.Client
660660
}
661661
req.Header.Set("Content-Type", "application/json")
662662

663-
resp, err := client.Do(req)
663+
resp, err := client.Do(req) //nolint:gosec // G704: URL from registry reference, not user input
664664
if err != nil {
665665
return uploadSession{}, err
666666
}
@@ -864,7 +864,7 @@ func (c *RegistryClient) uploadBlobSingle(ctx context.Context, client *http.Clie
864864
req.Header.Set("Content-Type", "application/octet-stream")
865865
req.ContentLength = totalSize
866866

867-
resp, err := client.Do(req)
867+
resp, err := client.Do(req) //nolint:gosec // G704: URL from registry upload session, not user input
868868
if err != nil {
869869
return "", err
870870
}
@@ -924,7 +924,7 @@ func (c *RegistryClient) uploadChunk(ctx context.Context, client *http.Client, l
924924
req.Header.Set("Content-Length", strconv.FormatInt(int64(len(chunk)), 10))
925925
req.Header.Set("Content-Range", fmt.Sprintf("%d-%d", start, end))
926926

927-
resp, err := client.Do(req)
927+
resp, err := client.Do(req) //nolint:gosec // G704: URL from registry upload session, not user input
928928
if err != nil {
929929
return "", err
930930
}
@@ -988,7 +988,7 @@ func (c *RegistryClient) commitUpload(ctx context.Context, client *http.Client,
988988

989989
req.Header.Set("Content-Type", "application/octet-stream")
990990

991-
resp, err := client.Do(req)
991+
resp, err := client.Do(req) //nolint:gosec // G704: URL from registry upload session, not user input
992992
if err != nil {
993993
return err
994994
}

pkg/web/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (c *Client) FetchAPIToken(ctx context.Context, entity string) (string, erro
225225
return "", err
226226
}
227227

228-
tokenResp, err := c.client.Do(req)
228+
tokenResp, err := c.client.Do(req) //nolint:gosec // G704: URL from configured endpoint
229229
if err != nil {
230230
return "", err
231231
}
@@ -421,7 +421,7 @@ func (c *Client) doSingleFileChallenge(ctx context.Context, file File, fileType
421421
if err != nil {
422422
return answer, util.WrapError(err, "build HTTP request")
423423
}
424-
resp, err := c.client.Do(req)
424+
resp, err := c.client.Do(req) //nolint:gosec // G704: URL from configured endpoint
425425
if err != nil {
426426
return answer, util.WrapError(err, "do HTTP request")
427427
}

0 commit comments

Comments
 (0)