From 05ee25be1d6375e778370f4316c12f5456652116 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Sat, 5 Jan 2019 18:20:36 +0000 Subject: [PATCH] Add username validation Check that the username is valid before doing any work. Use the default regex from debian's adduser.conf. Will also avoid risk of special characters causing issues. --- build.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.sh b/build.sh index c44e6db..2c6c97a 100755 --- a/build.sh +++ b/build.sh @@ -189,6 +189,11 @@ source "${SCRIPT_DIR}/common" # shellcheck source=scripts/dependencies_check source "${SCRIPT_DIR}/dependencies_check" +#check username is valid +if [[ ! "$FIRST_USER_NAME" =~ ^[a-z][-a-z0-9_]*$ ]]; then + echo "Invalid FIRST_USER_NAME: $FIRST_USER_NAME" + exit 1 +fi dependencies_check "${BASE_DIR}/depends"