Skip to content

Commit 293ac54

Browse files
fix(security): ci-quality-local.sh reads DB creds from .env, no hardcoded password
The initial script hardcoded the local dev DB password as a default — a secret must never be committed. It now loads DB_* from the gitignored .env (the same source the .unit.php tests use) with only non-secret fallbacks (socket path, host, port). Also documents the gate as MANDATORY in updater.md alongside the reinstall/schema gates.
1 parent 29dadd3 commit 293ac54

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

scripts/ci-quality-local.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@
1313
# Exit 0 iff every BLOCKING check passes (npm audit + the soft-delete grep are
1414
# advisory, mirroring the CI's continue-on-error / warn-only behaviour).
1515
#
16-
# DB: the standalone unit tests need MySQL. Defaults below match the canonical
17-
# local dev DB (MySQL on the Homebrew socket). Override via the E2E_DB_* env.
16+
# DB: the standalone unit tests need MySQL. Credentials come from the gitignored
17+
# .env (same source the .unit.php tests use) — NEVER hardcode a password here.
18+
# Override any of them via the environment before invoking the script.
1819

1920
set -uo pipefail
2021
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" || exit 2
2122

22-
export E2E_DB_SOCKET="${E2E_DB_SOCKET:-/opt/homebrew/var/mysql/mysql.sock}"
23+
# Load DB_* from .env (gitignored) unless already set in the environment.
24+
if [ -f .env ]; then
25+
while IFS='=' read -r k v; do
26+
v="${v%\"}"; v="${v#\"}"; v="${v%\'}"; v="${v#\'}"
27+
[ -n "${!k:-}" ] || export "$k=$v"
28+
done < <(grep -E '^(DB_HOST|DB_PORT|DB_USER|DB_PASS|DB_PASSWORD|DB_NAME|DB_SOCKET)=' .env 2>/dev/null)
29+
fi
30+
# Only non-secret fallbacks (socket path/host/port) — no password default.
31+
export E2E_DB_SOCKET="${E2E_DB_SOCKET:-${DB_SOCKET:-/opt/homebrew/var/mysql/mysql.sock}}"
2332
export DB_HOST="${DB_HOST:-127.0.0.1}"
2433
export DB_PORT="${DB_PORT:-3306}"
25-
export DB_USER="${DB_USER:-fabiodal_biblioteca_user}"
26-
export DB_PASSWORD="${DB_PASSWORD:-Zd10)uwziWlK}"
27-
export DB_NAME="${DB_NAME:-fabiodal_biblioteca}"
28-
# The .unit.php tests read DB_USER/DB_PASS/DB_NAME (and E2E_DB_*).
29-
export DB_PASS="${DB_PASS:-$DB_PASSWORD}"
34+
export DB_PASS="${DB_PASS:-${DB_PASSWORD:-}}"
3035

3136
PHPSTAN="${PHPSTAN:-$HOME/.composer/vendor/bin/phpstan}"
3237
[ -x "$PHPSTAN" ] || PHPSTAN="phpstan"

0 commit comments

Comments
 (0)