Skip to content

Commit f1e593c

Browse files
committed
fix(llm): trim whitespace from secrets loaded via Secret Manager
Secrets stored without an explicit printf may carry a trailing newline, which Go's net/http rejects as an invalid header field value.
1 parent 55dd932 commit f1e593c

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- **Anthropic API key trailing newline** — secrets loaded from Secret Manager are now trimmed of surrounding whitespace before use, preventing `invalid header field value` errors when the secret was stored with a trailing newline.
12+
913
## [v0.4.0] - 2026-05-02
1014

1115
### Added

services/github_auth.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"net/http"
1111
"os"
12+
"strings"
1213
"time"
1314

1415
secretmanager "cloud.google.com/go/secretmanager/apiv1"
@@ -124,7 +125,7 @@ func getWebhookSecretFromSecretManager(ctx context.Context, secretName string) (
124125
if err != nil {
125126
return "", fmt.Errorf("%w: %v", ErrSecretAccess, err)
126127
}
127-
return string(result.Payload.Data), nil
128+
return strings.TrimSpace(string(result.Payload.Data)), nil
128129
}
129130

130131
// LoadWebhookSecret loads the webhook secret from Secret Manager or environment variable
@@ -200,7 +201,7 @@ func getSecretFromSecretManager(ctx context.Context, secretName, envVarName stri
200201
if err != nil {
201202
return "", fmt.Errorf("%w: %v", ErrSecretAccess, err)
202203
}
203-
return string(result.Payload.Data), nil
204+
return strings.TrimSpace(string(result.Payload.Data)), nil
204205
}
205206

206207
// getInstallationAccessToken exchanges a JWT for a GitHub App installation access token.

services/llm_anthropic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func newAnthropicClient(baseURL, model, apiKey string) *anthropicClient {
4848
return &anthropicClient{
4949
baseURL: strings.TrimSuffix(baseURL, "/"),
5050
model: model,
51-
apiKey: apiKey,
51+
apiKey: strings.TrimSpace(apiKey),
5252
http: &http.Client{Timeout: 60 * time.Second},
5353
}
5454
}

0 commit comments

Comments
 (0)