]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix RLS policy usage in MERGE.
authorDean Rasheed <dean.a.rasheed@gmail.com>
Mon, 7 Aug 2023 08:27:09 +0000 (09:27 +0100)
committerDean Rasheed <dean.a.rasheed@gmail.com>
Mon, 7 Aug 2023 08:27:09 +0000 (09:27 +0100)
commit67a007dc0cdb8578726c2000a7abc513109cb4a2
tree4cda9b15c2f51ab983bbce28b9b3c4860578ebc1
parentf0a3805d7c44ed1c01668061bc2f6458e7b1369a
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
src/backend/executor/nodeModifyTable.c
src/backend/rewrite/rowsecurity.c
src/test/regress/expected/rowsecurity.out
src/test/regress/sql/rowsecurity.sql