T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:474- Finding
Redis Credentials Exposed Through Positional Arguments and Process Command Lines
- Content
View full analysis
Vulnerability Details
File Location:
scripts/script.sh, lines 474–482; invoked at lines 499 and 562
Vulnerability Type: Insecure credential handling
Risk Level: MediumThe script accepts the Redis password as a positional command-line argument and incorporates it into a command string using the
redis-cli -aoption.bash build_redis_cmd() { local host="$1" local port="$2" local pass="$3" local cmd="redis-cli -h $host -p $port" if [[ -n "$pass" ]]; then cmd="$cmd -a $pass --no-auth-warning" fi echo "$cmd" }The generated string is subsequently assigned and executed in both connection-testing and monitoring operations:
bash RCMD="$(build_redis_cmd "$host" "$port" "$pass")" # Test PING PONG="$($RCMD PING 2>&1 || true)"bash RCMD="$(build_redis_cmd "$host" "$port" "$pass")" # Test connection first PONG="$($RCMD PING 2>&1 || true)"Technical Analysis
Supplying a secret as a positional argument exposes it in multiple places:
- The original invocation, such as
bash script.sh test host 6379 password, may be retained in the user's shell history. - The password is passed to
redis-cliusing-a, making it part of the child process's argument vector. Depending on operating-system process visibility and hardening settings, other local users or monitoring tools may inspect it while the command is running. - The command is assembled as a scalar string and executed through unquoted expansion. This causes shell word splitting and pathname expansion. Passwords, hostnames, or ports containing whitespace or glob characters may therefore be divided or expanded into unintended arguments.
The use of
--no-auth-warningonly suppresses the warning emitted byredis-cli; it does not prevent credential disclosure.Attack Path
- A user invokes the connection or monitoring feature with a Redis password: `bash script ...[truncated 1271 chars]
- The original invocation, such as
- Remediation
View remediation
Remediation Suggestions
-
Stop accepting passwords as positional command-line arguments. Prompt interactively with input echo disabled or retrieve the secret from an appropriately protected secret manager or file descriptor:
bash read -r -s -p "Redis password: " REDIS_PASSWORD echo -
Pass authentication through
REDISCLI_AUTHrather thanredis-cli -a, and remove it from the environment immediately after use:bash redis_cmd=(redis-cli -h "$host" -p "$port") if [[ -n "$REDIS_PASSWORD" ]]; then export REDISCLI_AUTH="$REDIS_PASSWORD" fi pong="$("${redis_cmd[@]}" PING 2>&1 || true)" unset REDISCLI_AUTH REDIS_PASSWORDEnvironment variables can still be exposed in some environments, so a protected secret source and short variable lifetime remain important.
-
Construct commands using Bash arrays rather than scalar command strings. Arrays preserve argument boundaries and prevent word splitting and pathname expansion:
bash redis_cmd=(redis-cli -h "$host" -p "$port") info="$("${redis_cmd[@]}" INFO server 2>&1 || true)" -
Validate the port as an integer in the valid TCP port range and reject control characters in endpoint input.
-
Update
SKILL.mdand usage output so examples do not encourage entering plaintext passwords directly on the command line. -
Recommend Redis ACL users with only the commands and key patterns required for testing or monitoring, reducing the impact of any credential compromise.
-
