Skip to content

Commit 8221044

Browse files
authored
Merge pull request #199 from EngineScript/copilot/remove-local-keyword-in-vhost-install
fix(vhost-install): remove invalid `local` outside functions, fix printf quoting, eliminate IFS manipulation
2 parents 4265544 + 1d4385f commit 8221044

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Changes are organized by date, with the most recent changes listed first.
66

77
## 2026-04-12
88

9+
### 🐛 VHOST INSTALL SHELL CORRECTNESS & SECURITY FIXES
10+
11+
- Removed invalid `local` keyword from `create_db_sql` declaration in `scripts/functions/vhost/vhost-install.sh`; `local` has no effect outside a function and was misleading.
12+
- Removed invalid `local` keyword from `SQL_ESCAPED_PSWD` declaration in `scripts/functions/vhost/vhost-install.sh` for the same reason.
13+
- Changed the `printf -v create_db_sql` format string from single quotes to double quotes (with backticks escaped as `\``) to satisfy shell best-practice linting (SC2016 — expressions don't expand in single quotes).
14+
- Replaced the IFS-manipulation subshell (`IFS='|'; echo "${MULTIPART_PUBLIC_SUFFIXES[*]}"`) used to build `MULTIPART_SUFFIX_CASE_PATTERN` with a `printf`-based join (`printf '%s|'` + trailing-`|` strip), eliminating the HIGH-severity IFS side-effect security concern.
15+
916
### 🔒 VHOST INSTALL SECURITY & VALIDATION FIXES
1017

1118
- Added explicit `return` statement at the end of `escape_sql_string_literal()` in `scripts/functions/vhost/vhost-install.sh` to satisfy shell best-practice linting (SC2151/explicit-return warning).

scripts/functions/vhost/vhost-install.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ validate_db_identifier() {
5151
exit 1
5252
fi
5353
}
54-
MULTIPART_SUFFIX_CASE_PATTERN="$(IFS='|'; echo "${MULTIPART_PUBLIC_SUFFIXES[*]}")"
54+
MULTIPART_SUFFIX_CASE_PATTERN="$(printf '%s|' "${MULTIPART_PUBLIC_SUFFIXES[@]}")"
55+
MULTIPART_SUFFIX_CASE_PATTERN="${MULTIPART_SUFFIX_CASE_PATTERN%|}"
5556

5657
# Check if services are running
5758
check_required_services
@@ -282,14 +283,12 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
282283

283284
echo "Randomly generated MySQL database credentials for ${DOMAIN}."
284285

285-
local create_db_sql
286-
printf -v create_db_sql 'CREATE DATABASE `%s` CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci;' "${DB}"
286+
printf -v create_db_sql "CREATE DATABASE \`%s\` CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci;" "${DB}"
287287
if ! sudo mariadb -e "${create_db_sql}"; then
288288
echo "Error: Failed to create database '${DB}' for domain '${DOMAIN}'." >&2
289289
exit 1
290290
fi
291291

292-
local SQL_ESCAPED_PSWD
293292
SQL_ESCAPED_PSWD="$(escape_sql_string_literal "${PSWD}")"
294293

295294
if ! sudo mariadb -e "CREATE USER '${USR}'@'localhost' IDENTIFIED BY '${SQL_ESCAPED_PSWD}';"; then

0 commit comments

Comments
 (0)