Bug: RLS policy FOR SELECT is used to check new rows

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Bug: RLS policy FOR SELECT is used to check new rows
Date: 2023-10-24 08:35:32
Message-ID: aee893f1ec3ca8f62a0da2fc2f9f8b73920f9f9d.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Try this as a user with NOBYPASSRLS:

CREATE TABLE rlsbug (deleted boolean);

INSERT INTO rlsbug VALUES (FALSE);

CREATE POLICY p_sel ON rlsbug FOR SELECT TO laurenz USING (NOT deleted);

CREATE POLICY p_upd ON rlsbug FOR UPDATE TO laurenz USING (TRUE);

ALTER TABLE rlsbug ENABLE ROW LEVEL SECURITY;
ALTER TABLE rlsbug FORCE ROW LEVEL SECURITY;

UPDATE rlsbug SET deleted = TRUE WHERE NOT deleted;
ERROR: new row violates row-level security policy for table "rlsbug"

I'd say that this error is wrong. The FOR SELECT policy should be applied
to the WHERE condition, but certainly not to check new rows.

Yours,
Laurenz Albe

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message PG Bug reporting form 2023-10-24 09:42:28 BUG #18167: cannot create partitioned tables when default_tablespace is set
Previous Message Daniel Gustafsson 2023-10-24 08:32:58 Re: Replace references to malloc() in libpq documentation with generic language