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
# Ensure parent directory exists and is restricted before writing sensitive data
235
+
# Validate generated credentials before writing any sensitive data to disk
236
+
if [[ -z"${database_name}"||!"${database_name}"=~ ^[a-z][a-z0-9_]*$ ]];then
237
+
echo"Error: Invalid generated database name '${database_name}' for domain '${DOMAIN}'.">&2
238
+
exit 1
239
+
fi
240
+
241
+
if [[ -z"${database_user}"||${#database_user}-lt 8 ||!"${database_user}"=~ ^[A-Za-z0-9_]+$ ]];then
242
+
echo"Error: Invalid generated MariaDB user '${database_user}' for domain '${DOMAIN}' (must be at least 8 characters and contain only letters, numbers, or underscores).">&2
243
+
exit 1
244
+
fi
245
+
246
+
if [[ -z"${database_password}"||!"${database_password}"=~ ^[A-Za-z0-9@%+=:,./_-]+$ ]];then
247
+
echo"Error: Invalid generated database password for domain '${DOMAIN}'.">&2
248
+
exit 1
249
+
fi
250
+
235
251
install -d -m 700 "${credentials_dir}"
236
252
chmod 700 "${credentials_dir}"
237
253
# Create the file with restrictive permissions before writing any sensitive data
@@ -255,11 +271,16 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
255
271
exit 1
256
272
fi
257
273
258
-
# Validate DB password before interpolating into SQL single-quoted string
259
-
if [[ -z"${PSWD}"||!"${PSWD}"=~ ^[A-Za-z0-9@%+=:,./_-]+$ ]];then
274
+
# Validate DB password before interpolating into SQL single-quoted string.
275
+
# Allow printable ASCII generally, but reject characters that would break
276
+
# single-quoted SQL interpolation without escaping (' and \).
277
+
if [[ -z"${PSWD}"||!"${PSWD}"=~ ^[[:print:]]+$ ||"${PSWD}"==*"'"*||"${PSWD}"==*"\\"* ]];then
260
278
echo"Error: Invalid database password for domain '${DOMAIN}'.">&2
261
279
exit 1
262
280
fi
281
+
282
+
# Escape password for safe use inside SQL single-quoted literal
283
+
ESCAPED_PSWD="${PSWD//\'/\'\'}"
263
284
264
285
echo"Randomly generated MySQL database credentials for ${DOMAIN}."
265
286
@@ -268,7 +289,7 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
268
289
exit 1
269
290
fi
270
291
271
-
if! sudo mariadb -e "CREATE USER '${USR}'@'localhost' IDENTIFIED BY '${PSWD}';";then
292
+
if! sudo mariadb -e "CREATE USER '${USR}'@'localhost' IDENTIFIED BY '${ESCAPED_PSWD}';";then
272
293
echo"Error: Failed to create MariaDB user '${USR}' for domain '${DOMAIN}'.">&2
273
294
exit 1
274
295
fi
@@ -344,7 +365,7 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
344
365
345
366
# Email: basic format validation
346
367
# Single character addresses such as [email protected] are valid and accepted by the regex.
0 commit comments