-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathurl.go
More file actions
48 lines (43 loc) · 1.22 KB
/
url.go
File metadata and controls
48 lines (43 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright IBM Corp. 2015, 2025
// SPDX-License-Identifier: MPL-2.0
package getter
import "net/url"
// redactedParams is the list of URL query parameter names whose values are
// sensitive and must be replaced with "redacted" in error messages and logs.
var redactedParams = []string{
"sshkey",
"aws_access_key_id",
"aws_access_key_secret",
"aws_access_token",
}
// RedactURL is a port of url.Redacted from the standard library,
// which is like url.String but replaces any password with "redacted".
// Only the password in u.URL is redacted. This allows the library
// to maintain compatibility with go1.14.
// This port was also extended to redact sensitive URL query parameters
// (sshkey, aws_access_key_id, aws_access_key_secret, aws_access_token)
// and replace them with "redacted".
func RedactURL(u *url.URL) string {
if u == nil {
return ""
}
ru := *u
if _, has := ru.User.Password(); has {
ru.User = url.UserPassword(ru.User.Username(), "redacted")
}
q := ru.Query()
modified := false
for _, param := range redactedParams {
if q.Has(param) {
values := q[param]
for i := range values {
values[i] = "redacted"
}
modified = true
}
}
if modified {
ru.RawQuery = q.Encode()
}
return ru.String()
}