postgresql/src/backend/rewrite
Dean Rasheed c2e08b04c9 Fix RLS policy usage in MERGE.
If MERGE executes an UPDATE action on a table with row-level security,
the code incorrectly applied the WITH CHECK clauses from the target
table's INSERT policies to new rows, instead of the clauses from the
table's UPDATE policies. In addition, it failed to check new rows
against the target table's SELECT policies, if SELECT permissions were
required (likely to always be the case).

In addition, if MERGE executes a DO NOTHING action for matched rows,
the code incorrectly applied the USING clauses from the target table's
DELETE policies to existing target tuples. These policies were applied
as checks that would throw an error, if they did not pass.

Fix this, so that a MERGE UPDATE action applies the same RLS policies
as a plain UPDATE query with a WHERE clause, and a DO NOTHING action
does not apply any RLS checks (other than adding clauses from SELECT
policies to the join).

Back-patch to v15, where MERGE was introduced.

Dean Rasheed, reviewed by Stephen Frost.

Security: CVE-2023-39418
2023-08-07 09:28:47 +01:00
..
Makefile
meson.build
rewriteDefine.c
rewriteHandler.c Fix typo in comment. 2023-06-16 10:17:15 +09:00
rewriteManip.c Re-allow INDEX_VAR as rt_index in ChangeVarNodes(). 2023-06-08 13:11:49 -04:00
rewriteRemove.c
rewriteSearchCycle.c A minor simplification for List manipulation 2023-07-03 11:39:03 +02:00
rewriteSupport.c
rowsecurity.c Fix RLS policy usage in MERGE. 2023-08-07 09:28:47 +01:00