-
Notifications
You must be signed in to change notification settings - Fork 0
🛡️ Sentinel: [HIGH] Harden entrypoint.sh script execution #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Sentinel's Security Journal | ||
|
|
||
| ## 2025-02-18 - Shell Script Variable Expansion & Read Pitfalls | ||
| **Vulnerability:** Shell script variable expansion and input reading logic flaws. | ||
| **Learning:** `read` without `-r` interprets backslashes, leading to data corruption (e.g., in passwords). Unquoted array expansion coupled with logic errors can result in incomplete execution of commands (only first command executed in a list). | ||
| **Prevention:** Always use `read -r`. Always quote variables. When iterating over lists in shell, verify loop logic and array expansion behavior. |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,7 +25,7 @@ set -e | |||||||
|
|
||||||||
| CONFIG=/var/lib/softether/vpn_server.config | ||||||||
|
|
||||||||
| if [ ! -f $CONFIG ] || [ ! -s $CONFIG ]; then | ||||||||
| if [ ! -f "$CONFIG" ] || [ ! -s "$CONFIG" ]; then | ||||||||
| # Generate a random PSK if not provided | ||||||||
| : ${PSK:=$(cat /dev/urandom | tr -dc 'A-Za-z0-9' | fold -w 20 | head -n 1)} | ||||||||
|
|
||||||||
|
|
@@ -138,15 +138,15 @@ if [ ! -f $CONFIG ] || [ ! -s $CONFIG ]; then | |||||||
| printf '# Creating user(s):' | ||||||||
|
|
||||||||
| if [[ $USERS ]]; then | ||||||||
| while IFS=';' read -ra USER; do | ||||||||
| while IFS=';' read -r -a USER; do | ||||||||
| for i in "${USER[@]}"; do | ||||||||
| IFS=':' read username password <<<"$i" | ||||||||
| IFS=':' read -r username password <<<"$i" | ||||||||
| # echo "Creating user: ${username}" | ||||||||
| adduser $username $password | ||||||||
| adduser "$username" "$password" | ||||||||
| done | ||||||||
| done <<<"$USERS" | ||||||||
| else | ||||||||
| adduser $USERNAME $PASSWORD | ||||||||
| adduser "$USERNAME" "$PASSWORD" | ||||||||
| fi | ||||||||
|
|
||||||||
| echo | ||||||||
|
|
@@ -156,14 +156,18 @@ if [ ! -f $CONFIG ] || [ ! -s $CONFIG ]; then | |||||||
|
|
||||||||
| # handle VPNCMD_* commands right before setting admin passwords | ||||||||
| if [[ $VPNCMD_SERVER ]]; then | ||||||||
| while IFS=";" read -ra CMD; do | ||||||||
| vpncmd_server $CMD | ||||||||
| while IFS=";" read -r -a CMDS; do | ||||||||
| for cmd in "${CMDS[@]}"; do | ||||||||
| vpncmd_server $cmd | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original logic only executed the first command in a semicolon-separated list, silently ignoring subsequent commands, which was a critical logic flaw. However, the variable
Suggested change
|
||||||||
| done | ||||||||
|
Comment on lines
+159
to
+162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevent globbing when dispatching VPNCMD commands. 🔧 Proposed fix- for cmd in "${CMDS[@]}"; do
- vpncmd_server $cmd
- done
+ for cmd in "${CMDS[@]}"; do
+ [[ -z "$cmd" ]] && continue
+ read -r -a CMD_PARTS <<<"$cmd"
+ vpncmd_server "${CMD_PARTS[@]}"
+ done
@@
- for cmd in "${CMDS[@]}"; do
- vpncmd_hub $cmd
- done
+ for cmd in "${CMDS[@]}"; do
+ [[ -z "$cmd" ]] && continue
+ read -r -a CMD_PARTS <<<"$cmd"
+ vpncmd_hub "${CMD_PARTS[@]}"
+ doneAlso applies to: 167-170 🤖 Prompt for AI Agents |
||||||||
| done <<<"$VPNCMD_SERVER" | ||||||||
| fi | ||||||||
|
|
||||||||
| if [[ $VPNCMD_HUB ]]; then | ||||||||
| while IFS=";" read -ra CMD; do | ||||||||
| vpncmd_hub $CMD | ||||||||
| while IFS=";" read -r -a CMDS; do | ||||||||
| for cmd in "${CMDS[@]}"; do | ||||||||
| vpncmd_hub $cmd | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the
Suggested change
|
||||||||
| done | ||||||||
| done <<<"$VPNCMD_HUB" | ||||||||
| fi | ||||||||
|
|
||||||||
|
|
@@ -191,7 +195,7 @@ else | |||||||
| fi | ||||||||
|
|
||||||||
| if [[ -d "/opt/scripts/" ]]; then | ||||||||
| while read _script; do | ||||||||
| while read -r _script; do | ||||||||
| echo >&2 ":: executing $_script..." | ||||||||
| bash -n "$_script" && | ||||||||
| bash "$_script" | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change to quote
$CONFIGis a good practice. Unquoted variables can lead to unexpected behavior due to word splitting or globbing, especially if the path contains spaces or special characters. This improves the script's robustness and security.