Skip to content

Commit d6ae537

Browse files
grokifyclaude
andcommitted
fix: add nolint directives for gosec false positives
Silence gosec warnings for expected behavior in an HTTP client library: - G704 (SSRF): HTTP requests to caller-specified URLs are by design - G703 (path traversal): CLI tools reading/writing user-specified paths - G705 (XSS): CLI stderr output and Twilio callback responses Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cbaf2f3 commit d6ae537

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (c *authHTTPClient) Do(req *http.Request) (*http.Response, error) {
138138
req.Header.Set("X-ElevenLabs-SDK-Version", Version)
139139
req.Header.Set("X-ElevenLabs-SDK-Lang", "go")
140140

141-
return c.client.Do(req)
141+
return c.client.Do(req) //nolint:gosec // G704: HTTP client library, URL is caller-controlled by design
142142
}
143143

144144
// API returns the underlying ogen-generated API client for advanced usage.

cmd/openapi-convert/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import (
1313

1414
func main() {
1515
if len(os.Args) != 3 {
16-
fmt.Fprintf(os.Stderr, "Usage: %s <input-v3.1.json> <output-v3.0.json>\n", os.Args[0])
16+
fmt.Fprintf(os.Stderr, "Usage: %s <input-v3.1.json> <output-v3.0.json>\n", os.Args[0]) //nolint:gosec // G705: CLI tool writing to stderr, not browser context
1717
os.Exit(1)
1818
}
1919

2020
inputFile := os.Args[1]
2121
outputFile := os.Args[2]
2222

2323
// Read raw JSON
24-
data, err := os.ReadFile(inputFile)
24+
data, err := os.ReadFile(inputFile) //nolint:gosec // G703: CLI tool, user-specified path is expected
2525
if err != nil {
2626
fmt.Fprintf(os.Stderr, "Error reading file: %v\n", err)
2727
os.Exit(1)
@@ -54,7 +54,7 @@ func main() {
5454
}
5555

5656
// Write output
57-
if err := os.WriteFile(outputFile, output, 0600); err != nil {
57+
if err := os.WriteFile(outputFile, output, 0600); err != nil { //nolint:gosec // G703: CLI tool, user-specified path is expected
5858
fmt.Fprintf(os.Stderr, "Error writing file: %v\n", err)
5959
os.Exit(1)
6060
}

examples/speech-to-speech/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func main() {
6565
logInfo(ctx, "Converting to voice", "name", targetVoice.Name, "id", targetVoice.VoiceID)
6666

6767
// Open input file
68-
inputFile, err := os.Open(inputPath)
68+
inputFile, err := os.Open(inputPath) //nolint:gosec // G703: Example CLI, user-specified path is expected
6969
if err != nil {
7070
logError(ctx, "Failed to open input file", err, "path", inputPath)
7171
os.Exit(1)
@@ -101,7 +101,7 @@ func main() {
101101
}
102102

103103
// Save output
104-
outputFile, err := os.Create(outputPath)
104+
outputFile, err := os.Create(outputPath) //nolint:gosec // G703: Example CLI, user-specified path is expected
105105
if err != nil {
106106
logError(ctx, "Failed to create output file", err, "path", outputPath)
107107
os.Exit(1)

examples/twilio/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func handleIncomingCall(w http.ResponseWriter, r *http.Request) {
154154

155155
// Return TwiML to Twilio
156156
w.Header().Set("Content-Type", "application/xml")
157-
if _, err := w.Write([]byte(resp.TwiML)); err != nil {
157+
if _, err := w.Write([]byte(resp.TwiML)); err != nil { //nolint:gosec // G705: TwiML XML response to Twilio callback, not browser
158158
logError(ctx, "Failed to write TwiML response", err)
159159
}
160160
}

examples/websocket-stt/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func main() {
5858
defer conn.Close()
5959

6060
// Open audio file
61-
audioFile, err := os.Open(audioPath)
61+
audioFile, err := os.Open(audioPath) //nolint:gosec // G703: Example CLI, user-specified path is expected
6262
if err != nil {
6363
logError(ctx, "Failed to open audio file", err, "path", audioPath)
6464
os.Exit(1)

speechtospeech.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (s *SpeechToSpeechService) Convert(ctx context.Context, req *SpeechToSpeech
160160
httpReq.Header.Set("Content-Type", writer.FormDataContentType())
161161
httpReq.Header.Set("xi-api-key", s.client.apiKey)
162162

163-
resp, err := http.DefaultClient.Do(httpReq)
163+
resp, err := http.DefaultClient.Do(httpReq) //nolint:gosec // G704: API client, URL is fixed ElevenLabs endpoint
164164
if err != nil {
165165
return nil, fmt.Errorf("request failed: %w", err)
166166
}
@@ -255,7 +255,7 @@ func (s *SpeechToSpeechService) ConvertStream(ctx context.Context, req *SpeechTo
255255
httpReq.Header.Set("Content-Type", writer.FormDataContentType())
256256
httpReq.Header.Set("xi-api-key", s.client.apiKey)
257257

258-
resp, err := http.DefaultClient.Do(httpReq)
258+
resp, err := http.DefaultClient.Do(httpReq) //nolint:gosec // G704: API client, URL is fixed ElevenLabs endpoint
259259
if err != nil {
260260
return nil, fmt.Errorf("request failed: %w", err)
261261
}

twilio.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (s *TwilioService) postJSON(ctx context.Context, path string, req any, resu
3131
httpReq.Header.Set("Content-Type", "application/json")
3232
httpReq.Header.Set("xi-api-key", s.client.apiKey)
3333

34-
resp, err := http.DefaultClient.Do(httpReq)
34+
resp, err := http.DefaultClient.Do(httpReq) //nolint:gosec // G704: API client, URL is fixed ElevenLabs endpoint
3535
if err != nil {
3636
return fmt.Errorf("request failed: %w", err)
3737
}
@@ -238,7 +238,7 @@ func (s *PhoneNumberService) List(ctx context.Context) ([]PhoneNumber, error) {
238238

239239
httpReq.Header.Set("xi-api-key", s.client.apiKey)
240240

241-
resp, err := http.DefaultClient.Do(httpReq)
241+
resp, err := http.DefaultClient.Do(httpReq) //nolint:gosec // G704: API client, URL is fixed ElevenLabs endpoint
242242
if err != nil {
243243
return nil, fmt.Errorf("request failed: %w", err)
244244
}
@@ -275,7 +275,7 @@ func (s *PhoneNumberService) Get(ctx context.Context, phoneNumberID string) (*Ph
275275

276276
httpReq.Header.Set("xi-api-key", s.client.apiKey)
277277

278-
resp, err := http.DefaultClient.Do(httpReq)
278+
resp, err := http.DefaultClient.Do(httpReq) //nolint:gosec // G704: API client, URL is fixed ElevenLabs endpoint
279279
if err != nil {
280280
return nil, fmt.Errorf("request failed: %w", err)
281281
}
@@ -327,7 +327,7 @@ func (s *PhoneNumberService) Update(ctx context.Context, phoneNumberID string, r
327327
httpReq.Header.Set("Content-Type", "application/json")
328328
httpReq.Header.Set("xi-api-key", s.client.apiKey)
329329

330-
resp, err := http.DefaultClient.Do(httpReq)
330+
resp, err := http.DefaultClient.Do(httpReq) //nolint:gosec // G704: API client, URL is fixed ElevenLabs endpoint
331331
if err != nil {
332332
return nil, fmt.Errorf("request failed: %w", err)
333333
}
@@ -364,7 +364,7 @@ func (s *PhoneNumberService) Delete(ctx context.Context, phoneNumberID string) e
364364

365365
httpReq.Header.Set("xi-api-key", s.client.apiKey)
366366

367-
resp, err := http.DefaultClient.Do(httpReq)
367+
resp, err := http.DefaultClient.Do(httpReq) //nolint:gosec // G704: API client, URL is fixed ElevenLabs endpoint
368368
if err != nil {
369369
return fmt.Errorf("request failed: %w", err)
370370
}

0 commit comments

Comments
 (0)