fix: parse Matrix env files safely
This commit is contained in:
parent
0977ad1a9b
commit
b7f37fcc78
|
|
@ -15,10 +15,35 @@ if [[ ! -f "${ENV_FILE}" ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
. "${ENV_FILE}"
|
||||
set +a
|
||||
load_env_file() {
|
||||
local line key value
|
||||
|
||||
while IFS= read -r line || [[ -n "${line}" ]]; do
|
||||
[[ -z "${line}" || "${line}" =~ ^[[:space:]]*# ]] && continue
|
||||
if [[ "${line}" != *=* ]]; then
|
||||
echo "Invalid env line without '=' in ${ENV_FILE}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
key="${line%%=*}"
|
||||
value="${line#*=}"
|
||||
key="${key#"${key%%[![:space:]]*}"}"
|
||||
key="${key%"${key##*[![:space:]]}"}"
|
||||
|
||||
if [[ ! "${key}" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then
|
||||
echo "Invalid env key '${key}' in ${ENV_FILE}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Do not source the file. Matrix secrets are generated and may contain
|
||||
# shell metacharacters such as ';', '&', '$', or backticks. Exporting the
|
||||
# literal value keeps this file compatible with docker-compose env-file
|
||||
# syntax and prevents accidental command execution during bootstrap.
|
||||
export "${key}=${value}"
|
||||
done <"${ENV_FILE}"
|
||||
}
|
||||
|
||||
load_env_file
|
||||
|
||||
MATRIX_SERVER_NAME="${MATRIX_SERVER_NAME:-matrix.lab2025.duckdns.org}"
|
||||
MATRIX_POSTGRES_DB="${MATRIX_POSTGRES_DB:-synapse}"
|
||||
|
|
@ -71,4 +96,4 @@ echo " server_name ${MATRIX_SERVER_NAME}"
|
|||
cat <<'EOF'
|
||||
Next: register users (hermes bot, and any humans) via the shared-secret CLI:
|
||||
docker exec -u 991 matrix-synapse register_new_matrix_user -c /data/homeserver.yaml -u NAME -p PASS [--no-admin]
|
||||
EOF
|
||||
EOF
|
||||
|
|
|
|||
Loading…
Reference in New Issue