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 <[email protected]> Reported-by: Zsolt Parragi <[email protected]> Reported-by: Only see myself <[email protected]> Reported-by: Nicholas Carlini <[email protected]> Reported-by: Joao Detomini <[email protected]> Reported-by: Josef Šimánek <[email protected]> Reported-by: Qing Xu <[email protected]> Author: Peter Geoghegan <[email protected]> Author: Zsolt Parragi <[email protected]> Reviewed-by: Robert Haas <[email protected]> Security: CVE-2026-120154 Backpatch-through: 14 Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/661a0951bdc219913524ed9015514518e67d0e30 Author: Peter Geoghegan <[email protected]> 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(-)
