SECURITY UPDATE: psql meta-commands injected through plain-text dumps.
pg_dump, pg_dumpall and pg_restore copy object definitions and table
data from the source server into their plain-text scripts verbatim,
so a malicious or compromised source server could place psql
meta-commands such as ! in the dump, and psql ran them on the
machine restoring the dump, as the user running psql.
debian/patches/CVE-2025-8714.patch: add a "restricted mode" to psql
(\restrict KEY refuses every meta-command until \unrestrict KEY with
the same key) and make pg_dump, pg_dumpall and pg_restore wrap every
plain-text script they write, by pg_restore both to --file and to
standard output, in \restrict/\unrestrict with a random key, settable
with the new --restrict-key option. Where the script switches
databases inside the restricted section (pg_dump and pg_restore
--create, and pg_dumpall moving the postgres or template1 database to
another tablespace), the \connect line is preceded by \unrestrict and
followed by \restrict, so psql runs the \connect itself unrestricted
and a restore with ON_ERROR_STOP does not stop at it; pg_dumpall
writes the \connect for each database it dumps between the restricted
sections (upstream c204bd39f7, ae63671a7f, e8bc40d290). PostgreSQL
9.5 has no pg_strong_random(), so the key is read from /dev/urandom
and the dump fails if that is not possible.
debian/patches/CVE-2026-18408.patch: read the \unrestrict argument
up to the end of the line without backquote or variable expansion;
otherwise a dump could still run shell commands through
"\unrestrict command" while restricted (upstream 2006fca401).
BEHAVIOUR CHANGE: every plain-text dump now starts with
"\restrict " and ends with "\unrestrict ", so two dumps of
the same database are no longer byte-identical unless the same
--restrict-key is given, and a psql without this update prints
"invalid command \restrict" when restoring such a dump (with
ON_ERROR_STOP it stops there, before restoring anything; otherwise
the restore continues unprotected). Scripts that insert their own
meta-commands into a dump must place them outside the
\restrict/\unrestrict section or use a known --restrict-key.
Custom, directory and tar archives are unchanged.