fix(phase-1): redact API key query params from log output and add mutex thread-safety to providers map

This commit is contained in:
newkirk
2026-07-21 13:18:31 -04:00
parent 84a18f5866
commit 42b70621a1
6 changed files with 277 additions and 17 deletions
+2 -2
View File
@@ -375,7 +375,7 @@ func (p *GeminiProvider) ChatCompletion(ctx context.Context, req *models.Unified
}
url := fmt.Sprintf("%s/models/%s:generateContent?key=%s", baseURL, req.Model, p.apiKey)
fmt.Printf("[Gemini] POST %s\n", url)
fmt.Printf("[Gemini] POST %s\n", SanitizeURL(url))
resp, err := p.client.R().
SetContext(ctx).
@@ -633,7 +633,7 @@ func (p *GeminiProvider) ChatCompletionStream(ctx context.Context, req *models.U
// Use streamGenerateContent for streaming
url := fmt.Sprintf("%s/models/%s:streamGenerateContent?key=%s", baseURL, req.Model, p.apiKey)
fmt.Printf("[Gemini-Stream] POST %s\n", url)
fmt.Printf("[Gemini-Stream] POST %s\n", SanitizeURL(url))
resp, err := p.client.R().
SetContext(ctx).
+9
View File
@@ -5,11 +5,20 @@ import (
"encoding/json"
"fmt"
"io"
"regexp"
"strings"
"gophergate/internal/models"
)
var keySanitizeRegex = regexp.MustCompile(`(?i)(key|api_key|secret)=[^&]+`)
// SanitizeURL strips sensitive key query parameters from URLs before logging.
func SanitizeURL(rawURL string) string {
return keySanitizeRegex.ReplaceAllString(rawURL, "$1=REDACTED")
}
func sanitizeFunctionName(name string) string {
var sb strings.Builder
for _, ch := range name {