You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Added domain hash (`sha256sum`, first 8 hex chars) to `db_name_suffix` in `vhost-install.sh` to prevent silent database name collisions when long domain names are truncated to fit MariaDB's 64-character identifier limit. Added explicit regex validation of the hash output (`^[0-9a-f]{8}$`) to catch pipeline failures with a clear error message.
12
+
- Replaced the overly-broad suffix length guard (`>= 64`) with an exact-length check (`!= 14`) that precisely validates the expected suffix format: `_<8-char-hash>_<RAND_CHAR4>`.
13
+
- Added backtick rejection to `validate_db_identifier()` as defense-in-depth against SQL injection via backtick-quoted identifiers, guarding against future regex changes.
14
+
- Tightened `database_user` validation regex from `^[A-Za-z0-9_]+$` to `^[A-Za-z0-9]+$` to accurately reflect the `RAND_CHAR16` source charset (`a-zA-Z0-9`, no underscores).
15
+
- Removed redundant single-quote and backslash sub-checks from `database_password` validation; these are already excluded by the `^[A-Za-z0-9_]+$` regex and were unnecessarily duplicated.
16
+
- Removed duplicate post-`source` validations of `${DB}` and `${PSWD}`; both values are fully validated pre-write before the credentials file is created, eliminating double validation.
- 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.
# Ensure parent directory exists and is restricted before writing sensitive data
248
-
# Validate generated credentials before writing any sensitive data to disk
249
-
if [[ -z"${database_user}"||${#database_user}-lt 8 ||${#database_user}-gt 80 ||!"${database_user}"=~ ^[A-Za-z0-9_]+$ ]];then
250
-
echo"Error: Invalid generated MariaDB user '${database_user}' for domain '${DOMAIN}' (must be 8-80 characters and contain only letters, numbers, or underscores).">&2
257
+
# Validate generated credentials before writing any sensitive data to disk.
258
+
# RAND_CHAR16 uses a-zA-Z0-9 only; regex matches that exact charset.
259
+
if [[ -z"${database_user}"||${#database_user}-lt 8 ||${#database_user}-gt 80 ||!"${database_user}"=~ ^[A-Za-z0-9]+$ ]];then
260
+
echo"Error: Invalid generated MariaDB user '${database_user}' for domain '${DOMAIN}' (must be 8-80 characters and contain only letters or numbers).">&2
251
261
exit 1
252
262
fi
253
263
254
-
if [[ -z"${database_password}"||!"${database_password}"=~ ^[A-Za-z0-9_]+$ ||"${database_password}"==*"'"*||"${database_password}"==*"\\"*]];then
264
+
if [[ -z"${database_password}"||!"${database_password}"=~ ^[A-Za-z0-9_]+$ ]];then
255
265
echo"Error: Invalid generated database password for domain '${DOMAIN}'.">&2
256
266
exit 1
257
267
fi
@@ -267,20 +277,6 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
267
277
268
278
source"${credentials_file}"
269
279
270
-
# Validate DB identifier before interpolating into SQL
271
-
if [[ -z"${DB}"||!"${DB}"=~ ^[A-Za-z][A-Za-z0-9_]*$ ]];then
272
-
echo"Error: Invalid database name '${DB}' for domain '${DOMAIN}'.">&2
273
-
exit 1
274
-
fi
275
-
276
-
# Validate DB password before interpolating into SQL single-quoted string.
277
-
# Allow printable ASCII generally, but reject characters that would break
278
-
# single-quoted SQL interpolation without escaping (' and \).
279
-
if [[ -z"${PSWD}"||!"${PSWD}"=~ ^[[:print:]]+$ ||"${PSWD}"==*"'"*||"${PSWD}"==*"\\"* ]];then
280
-
echo"Error: Invalid database password for domain '${DOMAIN}'.">&2
281
-
exit 1
282
-
fi
283
-
284
280
echo"Randomly generated MySQL database credentials for ${DOMAIN}."
285
281
286
282
printf -v create_db_sql "CREATE DATABASE \`%s\` CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci;""${DB}"
0 commit comments