pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Check ON CONFLICT target row against RLS policies before user qu
3+ messages / 1 participants
[nested] [flat]

* pgsql: Check ON CONFLICT target row against RLS policies before user qu
@ 2026-11-09 14:21 Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Noah Misch @ 2026-11-09 14:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2f32e08adc78cd8f72c1fb31ac4478b9e50833bf
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(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Check ON CONFLICT target row against RLS policies before user qu
@ 2026-11-09 14:21 Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Noah Misch @ 2026-11-09 14:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Check ON CONFLICT target row against RLS policies before user qu
@ 2026-11-09 14:22 Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Noah Misch @ 2026-11-09 14:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/a748ed909271ac58f09e3df0915adf487170a6ae
Author: Peter Geoghegan <pg@bowt.ie>

Modified Files
--------------
src/backend/executor/nodeModifyTable.c    | 43 +++++++++++++++++--------------
src/test/regress/expected/rowsecurity.out | 15 +++++++++++
src/test/regress/sql/rowsecurity.sql      | 12 +++++++++
3 files changed, 50 insertions(+), 20 deletions(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2026-11-09 14:22 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 14:21 pgsql: Check ON CONFLICT target row against RLS policies before user qu Noah Misch <noah@leadboat.com>
2026-11-09 14:21 pgsql: Check ON CONFLICT target row against RLS policies before user qu Noah Misch <noah@leadboat.com>
2026-11-09 14:22 pgsql: Check ON CONFLICT target row against RLS policies before user qu Noah Misch <noah@leadboat.com>

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