Skip to content

Commit 858f05a

Browse files
CopilotPDowney
andauthored
Fix vhost-install.sh: domain regex, multi-part TLDs, variable naming, DB error handling, mysql.* privilege removal
Agent-Logs-Url: https://github.com/EngineScript/EngineScript/sessions/33817d13-2732-452c-8ca4-bc6ef0b6e88e Co-authored-by: PDowney <[email protected]>
1 parent 61eaf7a commit 858f05a

2 files changed

Lines changed: 34 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to EngineScript will be documented in this file.
44

55
Changes are organized by date, with the most recent changes listed first.
66

7+
## 2026-04-11 (2)
8+
9+
### 🔒 VHOST INSTALL SECURITY & CODE QUALITY IMPROVEMENTS
10+
11+
- Fixed domain name validation regex in `scripts/functions/vhost/vhost-install.sh` to require a minimum of 2 characters by changing `^[a-z0-9]([a-z0-9-]*[a-z0-9])?$` to `^[a-z0-9][a-z0-9-]*[a-z0-9]$`, preventing single-character domain names.
12+
- Expanded the multi-part TLD list in `scripts/functions/vhost/vhost-install.sh` to include common public suffixes: `co.jp`, `com.au`, `co.nz`, `com.sg`, `com.my`, `com.br`, `com.mx`, `co.za`, `com.tr`, `com.hk`, making the TLD selection consistent and comprehensive.
13+
- Renamed ambiguous variables in `scripts/functions/vhost/vhost-install.sh`: `sand``domain_input`, `SANDOMAIN``domain_without_tld`, `SDB``database_name`, `SUSR``database_user`, `SPS``database_password`, improving code readability.
14+
- Added error handling for all MariaDB operations in `scripts/functions/vhost/vhost-install.sh`; each `CREATE DATABASE`, `CREATE USER`, and `GRANT` command now exits with a descriptive error message if it fails, preventing broken installations from continuing silently.
15+
- Removed the critical security risk of `GRANT ALL ON mysql.*` to the WordPress application user in `scripts/functions/vhost/vhost-install.sh`; the application user now only has privileges on its own database.
16+
717
## 2026-04-11
818

919
### 🔧 VHOST IMPORT BUG FIXES & IMPROVEMENTS

scripts/functions/vhost/vhost-install.sh

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ echo ""
4545
# Prompt for domain name
4646
while true; do
4747
read -p "Enter the domain name (e.g., 'wordpresstesting'): " DOMAIN_NAME
48-
if [[ "$DOMAIN_NAME" =~ ^[a-z0-9]([a-z0-9-]*[a-z0-9])?$ ]]; then
48+
if [[ "$DOMAIN_NAME" =~ ^[a-z0-9][a-z0-9-]*[a-z0-9]$ ]]; then
4949
echo "You entered: ${DOMAIN_NAME}"
5050
break
5151
else
@@ -69,7 +69,9 @@ VALID_TLDS=(
6969
"us" "uk" "ca" "au" "de" "fr" "es" "it" "nl" "se" "no" "fi" "dk" "jp" "cn"
7070
"in" "br" "ru" "za" "mx" "ar" "ch" "at" "be" "pl" "gr" "pt" "tr" "kr" "hk"
7171
"sg" "id" "my" "th" "ph" "vn" "nz" "ie" "il" "sa" "ae" "eg" "ng" "ke" "gh"
72-
"co.uk"
72+
73+
# Common multi-part public suffixes
74+
"co.uk" "co.jp" "com.au" "co.nz" "com.sg" "com.my" "com.br" "com.mx" "co.za" "com.tr" "com.hk"
7375
)
7476
select TLD in "${VALID_TLDS[@]}"; do
7577
if [[ -n "$TLD" ]]; then
@@ -156,24 +158,34 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
156158

157159
# Domain Creation Variables
158160
PREFIX="${RAND_CHAR2}"
159-
sand="${DOMAIN}" && SANDOMAIN="${sand%.*}" && SDB="${SANDOMAIN}_${RAND_CHAR4}"
160-
SUSR="${RAND_CHAR16}"
161-
SPS="${RAND_CHAR32}"
161+
domain_input="${DOMAIN}" && domain_without_tld="${domain_input%.*}" && database_name="${domain_without_tld}_${RAND_CHAR4}"
162+
database_user="${RAND_CHAR16}"
163+
database_password="${RAND_CHAR32}"
162164

163165
# Domain Database Credentials
164-
echo "DB=\"${SDB}\"" >> "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
165-
echo "USR=\"${SUSR}\"" >> "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
166-
echo "PSWD=\"${SPS}\"" >> "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
166+
echo "DB=\"${database_name}\"" >> "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
167+
echo "USR=\"${database_user}\"" >> "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
168+
echo "PSWD=\"${database_password}\"" >> "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
167169
echo "" >> "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
168170

169171
source "/home/EngineScript/mysql-credentials/${DOMAIN}.txt"
170172

171173
echo "Randomly generated MySQL database credentials for ${DOMAIN}."
172174

173-
sudo mariadb -e "CREATE DATABASE ${DB} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
174-
sudo mariadb -e "CREATE USER '${USR}'@'localhost' IDENTIFIED BY '${PSWD}';"
175-
sudo mariadb -e "GRANT ALL ON ${DB}.* TO '${USR}'@'localhost'; FLUSH PRIVILEGES;"
176-
sudo mariadb -e "GRANT ALL ON mysql.* TO '${USR}'@'localhost'; FLUSH PRIVILEGES;"
175+
if ! sudo mariadb -e "CREATE DATABASE ${DB} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"; then
176+
echo "Error: Failed to create database '${DB}' for domain '${DOMAIN}'." >&2
177+
exit 1
178+
fi
179+
180+
if ! sudo mariadb -e "CREATE USER '${USR}'@'localhost' IDENTIFIED BY '${PSWD}';"; then
181+
echo "Error: Failed to create MariaDB user '${USR}' for domain '${DOMAIN}'." >&2
182+
exit 1
183+
fi
184+
185+
if ! sudo mariadb -e "GRANT ALL ON ${DB}.* TO '${USR}'@'localhost'; FLUSH PRIVILEGES;"; then
186+
echo "Error: Failed to grant privileges on database '${DB}' to user '${USR}'." >&2
187+
exit 1
188+
fi
177189

178190
# Download WordPress using WP-CLI
179191
wp core download --allow-root

0 commit comments

Comments
 (0)