feat: safely control Shell Target
This commit is contained in:
@@ -172,10 +172,16 @@ func normalizeBypassEntry(raw string) (string, error) {
|
||||
|
||||
var credentialPattern = regexp.MustCompile(`(?i)(https?|socks5h?)://([^/@\s:]+):([^@\s]*)@`)
|
||||
|
||||
// RedactText removes URL passwords from diagnostic text without requiring the
|
||||
// surrounding text to be a valid URL.
|
||||
func RedactText(value string) string {
|
||||
return credentialPattern.ReplaceAllString(value, `${1}://${2}:REDACTED@`)
|
||||
}
|
||||
|
||||
func ObscureURL(value string) string {
|
||||
u, err := url.Parse(value)
|
||||
if err != nil || u.User == nil {
|
||||
return credentialPattern.ReplaceAllString(value, `${1}://${2}:REDACTED@`)
|
||||
return RedactText(value)
|
||||
}
|
||||
if _, present := u.User.Password(); !present {
|
||||
return value
|
||||
|
||||
@@ -112,6 +112,16 @@ func (systemIdentityEnvironment) LookupEnv(name string) (string, bool) {
|
||||
return os.LookupEnv(name)
|
||||
}
|
||||
|
||||
// SystemCurrentUser and SystemLookupUser expose the same injectable identity model
|
||||
// to user-scoped Target configuration without duplicating OS account parsing.
|
||||
func SystemCurrentUser() (UserIdentity, error) {
|
||||
return systemIdentityEnvironment{}.CurrentUser()
|
||||
}
|
||||
|
||||
func SystemLookupUser(name string) (UserIdentity, error) {
|
||||
return systemIdentityEnvironment{}.LookupUser(name)
|
||||
}
|
||||
|
||||
func ConfigPath() (string, error) {
|
||||
configuration, err := ResolveConfigurationForCurrentProcess()
|
||||
return configuration.Path, err
|
||||
|
||||
Reference in New Issue
Block a user