forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.go
34 lines (25 loc) · 1.01 KB
/
trace.go
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
package trace
import (
"fmt"
"regexp"
. "code.cloudfoundry.org/cli/cf/i18n"
)
var LoggingToStdout bool
func Sanitize(input string) string {
re := regexp.MustCompile(`(?m)^Authorization: .*`)
sanitized := re.ReplaceAllString(input, "Authorization: "+PrivateDataPlaceholder())
// allow query parameter to contain all characters of the "query" character class, except for &
// https://tools.ietf.org/html/rfc3986#appendix-A
re = regexp.MustCompile(`([&?]password)=[A-Za-z0-9\-._~!$'()*+,;=:@/?]*`)
sanitized = re.ReplaceAllString(sanitized, "$1="+PrivateDataPlaceholder())
sanitized = sanitizeJSON("token", sanitized)
sanitized = sanitizeJSON("password", sanitized)
return sanitized
}
func sanitizeJSON(propertySubstring string, json string) string {
regex := regexp.MustCompile(fmt.Sprintf(`(?i)"([^"]*%s[^"]*)":\s*"[^\,]*"`, propertySubstring))
return regex.ReplaceAllString(json, fmt.Sprintf(`"$1":"%s"`, PrivateDataPlaceholder()))
}
func PrivateDataPlaceholder() string {
return T("[PRIVATE DATA HIDDEN]")
}