MaskSensitiveHeaderValue masks sensitive header values while preserving expected formats. Behavior by header key (case-insensitive): - "Authorization": Preserve the auth type prefix (e.g., "Bearer ") and mask only the credential part. - Headers containing "api-key": Mask the entire value using Hide
(key, value string)
| 220 | // Returns: |
| 221 | // - string: The masked value according to the header type; unchanged if not sensitive. |
| 222 | func MaskSensitiveHeaderValue(key, value string) string { |
| 223 | lowerKey := strings.ToLower(strings.TrimSpace(key)) |
| 224 | switch { |
| 225 | case strings.Contains(lowerKey, "authorization"): |
| 226 | return MaskAuthorizationHeader(value) |
| 227 | case strings.Contains(lowerKey, "api-key"), |
| 228 | strings.Contains(lowerKey, "apikey"), |
| 229 | strings.Contains(lowerKey, "token"), |
| 230 | strings.Contains(lowerKey, "secret"): |
| 231 | return HideAPIKey(value) |
| 232 | default: |
| 233 | return value |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | // MaskSensitiveQuery masks sensitive query parameters, e.g. auth_token, within the raw query string. |
| 238 | func MaskSensitiveQuery(raw string) string { |
no test coverage detected