Skip to content

Commit 8c7e2f9

Browse files
OtterpohlTristan-Otterpohl-Forter
authored andcommitted
Parse URL to safely format error message without exposing credentials in indices and snapshot collectors
1 parent 2c91a65 commit 8c7e2f9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

collector/util.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"io"
2020
"log/slog"
2121
"net/http"
22+
"net/url"
2223
)
2324

2425
func getURL(ctx context.Context, hc *http.Client, log *slog.Logger, u string) ([]byte, error) {
@@ -29,7 +30,13 @@ func getURL(ctx context.Context, hc *http.Client, log *slog.Logger, u string) ([
2930

3031
resp, err := hc.Do(req)
3132
if err != nil {
32-
return nil, fmt.Errorf("failed to get %s: %v", u, err)
33+
// Parse URL to safely format error message without exposing credentials
34+
if parsedURL, parseErr := url.Parse(u); parseErr == nil {
35+
return nil, fmt.Errorf("failed to get %s://%s:%s%s: %v",
36+
parsedURL.Scheme, parsedURL.Hostname(), parsedURL.Port(), parsedURL.Path, err)
37+
}
38+
// Fallback if URL parsing fails - still avoid exposing full URL
39+
return nil, fmt.Errorf("failed to get URL: %v", err)
3340
}
3441

3542
defer func() {

0 commit comments

Comments
 (0)