github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/trace/trace.go (about) 1 package trace 2 3 import ( 4 "fmt" 5 "regexp" 6 7 . "code.cloudfoundry.org/cli/cf/i18n" 8 ) 9 10 var LoggingToStdout bool 11 12 func Sanitize(input string) string { 13 re := regexp.MustCompile(`(?m)^Authorization: .*`) 14 sanitized := re.ReplaceAllString(input, "Authorization: "+PrivateDataPlaceholder()) 15 16 // allow query parameter to contain all characters of the "query" character class, except for & 17 // https://tools.ietf.org/html/rfc3986#appendix-A 18 re = regexp.MustCompile(`([&?]password)=[A-Za-z0-9\-._~!$'()*+,;=:@/?]*`) 19 sanitized = re.ReplaceAllString(sanitized, "$1="+PrivateDataPlaceholder()) 20 21 sanitized = sanitizeJSON("token", sanitized) 22 sanitized = sanitizeJSON("password", sanitized) 23 24 return sanitized 25 } 26 27 func sanitizeJSON(propertySubstring string, json string) string { 28 regex := regexp.MustCompile(fmt.Sprintf(`(?i)"([^"]*%s[^"]*)":\s*"[^\,]*"`, propertySubstring)) 29 return regex.ReplaceAllString(json, fmt.Sprintf(`"$1":"%s"`, PrivateDataPlaceholder())) 30 } 31 32 func PrivateDataPlaceholder() string { 33 return T("[PRIVATE DATA HIDDEN]") 34 }