From: Noah Misch <noah@leadboat.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Check ON CONFLICT target row against RLS policies before user qu
Date: Mon, 09 Nov 2026 14:21:55 +0000
Message-ID: <E1xQQFv-000000003W9-1lww@gemulon.postgresql.org> (raw)
Check ON CONFLICT target row against RLS policies before user quals.
ExecOnConflictUpdate() and ExecOnConflictSelect() evaluated the
user-supplied ON CONFLICT WHERE clause before checking the pre-existing
conflicting row against the RLS policy USING quals collected as
WCO_RLS_CONFLICT_CHECK. A user could therefore have that clause read a
row that no policy allowed them to see.
Fix by performing the check immediately after the conflicting row is
locked and found visible, before the WHERE clause is evaluated. A row
that fails the check now raises an error whatever the WHERE clause would
have returned, so the two outcomes are no longer distinguishable.
This moves the USING quals of the UPDATE policies ahead of the WHERE
clause as well, not just those of the SELECT policies. Only the latter
is a security issue, since a row that nothing but an UPDATE policy hides
can be read with a plain SELECT anyway. No order is consistent with
every other command: a plain UPDATE evaluates both kinds of USING qual
ahead of the user's quals, whereas MERGE evaluates a WHEN MATCHED ... AND
condition ahead of the UPDATE policies' USING quals, since it cannot
know whether it is going to update until then. ON CONFLICT DO UPDATE
now behaves like UPDATE.
This dates to 168d5805e, which added WCO_RLS_CONFLICT_CHECK along with
ON CONFLICT itself. ON CONFLICT DO SELECT was added in 19 by 88327092f,
so the back branches only need the ExecOnConflictUpdate() part of the
fix.
Reported-by: Peter Geoghegan <pg@bowt.ie>
Reported-by: Zsolt Parragi <zsolt.parragi@percona.com>
Reported-by: Only see myself <1950233439@qq.com>
Reported-by: Nicholas Carlini <npc@anthropic.com>
Reported-by: Joao Detomini <joao.detomini@enterprisedb.com>
Reported-by: Josef Šimánek <josef.simanek@gmail.com>
Reported-by: Qing Xu <emyiqing@gmail.com>
Author: Peter Geoghegan <pg@bowt.ie>
Author: Zsolt Parragi <zsolt.parragi@percona.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Security: CVE-2026-120154
Backpatch-through: 14
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/aac16b69fa8e02ce48799c849f3b86e78727a992
Author: Peter Geoghegan <pg@bowt.ie>
Modified Files
--------------
src/backend/executor/nodeModifyTable.c | 81 ++++++++++++++++---------------
src/test/regress/expected/rowsecurity.out | 16 ++++++
src/test/regress/sql/rowsecurity.sql | 14 ++++++
3 files changed, 73 insertions(+), 38 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: noah@leadboat.com
Subject: Re: pgsql: Check ON CONFLICT target row against RLS policies before user qu
In-Reply-To: <E1xQQFv-000000003W9-1lww@gemulon.postgresql.org>
References: <E1xQQFv-000000003W9-1lww@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox