RedactURL strips userinfo and query parameters from a URL to avoid logging embedded credentials. Query params are removed because API keys are sometimes passed as ?api_key=sk-... in server URLs.
(rawURL string)
| 464 | // removed because API keys are sometimes passed as |
| 465 | // ?api_key=sk-... in server URLs. |
| 466 | func RedactURL(rawURL string) string { |
| 467 | u, err := url.Parse(rawURL) |
| 468 | if err != nil { |
| 469 | return rawURL |
| 470 | } |
| 471 | u.User = nil |
| 472 | u.RawQuery = "" |
| 473 | u.Fragment = "" |
| 474 | return u.String() |
| 475 | } |
| 476 | |
| 477 | // redactErrorURL rewrites URLs in an error string to strip |
| 478 | // credentials. Go's net/http embeds the full request URL in |