mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-29 15:59:10 +01:00
[client] Reject leading hyphen in getent input to prevent flag injection (#6787)
This commit is contained in:
@@ -69,7 +69,8 @@ func parseGetentPasswd(output string) (*user.User, string, error) {
|
|||||||
|
|
||||||
// validateGetentInput checks that the input is safe to pass to getent or id.
|
// validateGetentInput checks that the input is safe to pass to getent or id.
|
||||||
// Allows POSIX usernames, numeric UIDs, and common NSS extensions
|
// Allows POSIX usernames, numeric UIDs, and common NSS extensions
|
||||||
// (@ for Kerberos, $ for Samba, + for NIS compat).
|
// (@ for Kerberos, $ for Samba, + for NIS compat). A leading hyphen is
|
||||||
|
// rejected so the input can never be parsed as a command-line flag.
|
||||||
func validateGetentInput(input string) bool {
|
func validateGetentInput(input string) bool {
|
||||||
maxLen := 32
|
maxLen := 32
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
@@ -80,6 +81,10 @@ func validateGetentInput(input string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if input[0] == '-' {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
for _, r := range input {
|
for _, r := range input {
|
||||||
if isAllowedGetentChar(r) {
|
if isAllowedGetentChar(r) {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -157,6 +157,9 @@ func TestValidateGetentInput(t *testing.T) {
|
|||||||
{"numeric UID", "1001", true},
|
{"numeric UID", "1001", true},
|
||||||
{"dots and underscores", "alice.bob_test", true},
|
{"dots and underscores", "alice.bob_test", true},
|
||||||
{"hyphen", "alice-bob", true},
|
{"hyphen", "alice-bob", true},
|
||||||
|
{"leading hyphen rejected", "-i", false},
|
||||||
|
{"leading double hyphen rejected", "--no-idn", false},
|
||||||
|
{"lone hyphen rejected", "-", false},
|
||||||
{"kerberos principal", "user@REALM", true},
|
{"kerberos principal", "user@REALM", true},
|
||||||
{"samba machine account", "MACHINE$", true},
|
{"samba machine account", "MACHINE$", true},
|
||||||
{"NIS compat", "+user", true},
|
{"NIS compat", "+user", true},
|
||||||
|
|||||||
Reference in New Issue
Block a user