fix(seed): refuse connection-string PGDATABASE in local-only admin seed guard

psql -d treats URI and key=value values as full connection strings that
override -h, so PGDATABASE could route the unarmed fixture writer to a
shared database. Accept only a plain database name before either psql
path, and extend the refusal test with URI and key/value cases
(host=, hostaddr=, service=) plus a plain-name control that must reach
psql.

Also note in replica_fence that prepared-transaction coverage comes from
the retained deferred trigger, not the insert-time app guard.

Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
This commit is contained in:
Elrond
2026-10-16 09:53:30 -04:00
parent 91b507a66c
commit 93ccf41255
3 changed files with 74 additions and 14 deletions

View File

@@ -31,6 +31,12 @@ case "${PGHOST}" in
exit 1
;;
esac
# psql -d treats URI and key=value values as full connection strings that
# override -h, so accept only a plain database name.
if [[ ! "${PGDATABASE}" =~ ^[A-Za-z0-9_-]+$ ]]; then
echo "error: admin seed requires a local PostgreSQL target with a plain PGDATABASE name" >&2
exit 1
fi
if command -v psql >/dev/null 2>&1; then
run_psql() {