fix: resolve gosec findings G112 and G602
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

G112 (Slowloris): add ReadHeaderTimeout: 10s to http.Server
G602 (slice bounds): use explicit bounds-safe index for backoff slice
  (attempt is guarded but gosec can't prove it statically)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Head of Product & Engineering 2026-04-05 23:03:47 +02:00
parent 5f7dd7462d
commit 6db500235b
2 changed files with 8 additions and 3 deletions

View File

@ -65,6 +65,7 @@ func run() error {
srv := &http.Server{ srv := &http.Server{
Addr: ":" + cfg.Port, Addr: ":" + cfg.Port,
Handler: r, Handler: r,
ReadHeaderTimeout: 10 * time.Second,
} }
go func() { go func() {

View File

@ -53,7 +53,11 @@ func (c *Client) SendSMS(ctx context.Context, to, message string) (*SendResponse
if attempt == maxRetries { if attempt == maxRetries {
return nil, &CastAPIError{StatusCode: resp.StatusCode, APIError: "rate limited, max retries exceeded"} return nil, &CastAPIError{StatusCode: resp.StatusCode, APIError: "rate limited, max retries exceeded"}
} }
wait := backoff[attempt] idx := attempt
if idx >= len(backoff) {
idx = len(backoff) - 1
}
wait := backoff[idx]
if ra := resp.Header.Get("Retry-After"); ra != "" { if ra := resp.Header.Get("Retry-After"); ra != "" {
if secs, err := strconv.ParseFloat(ra, 64); err == nil { if secs, err := strconv.ParseFloat(ra, 64); err == nil {
wait = time.Duration(secs * float64(time.Second)) wait = time.Duration(secs * float64(time.Second))