From: Tom Lane <tgl@sss.pgh.pa.us>
To: Олег Самойлов <splarv@ya.ru>
Cc: pgsql-general@postgresql.org
Subject: Re: Incorrect description of the WITH CHECK in the row security can lead to the security issue
Date: Mon, 30 Jul 2018 11:58:11 -0400
Message-ID: <7182.1532966291@sss.pgh.pa.us> (raw)
In-Reply-To: <3298321532002010@sas1-2b3c3045b736.qloud-c.yandex.net>
References: <3298321532002010@sas1-2b3c3045b736.qloud-c.yandex.net>
=?utf-8?B?0J7Qu9C10LMg0KHQsNC80L7QudC70L7Qsg==?= <splarv@ya.ru> writes:
> PostgreSQL 10 (in 11 the same
> https://www.postgresql.org/docs/10/static/ddl-rowsecurity.html
> cite
> To use a different policy for rows that are being added to the table
> compared to those rows that are visible, the WITH CHECK clause can be used.
> This policy would allow all users to view all rows in the users table, but
> only modify their own:
> CREATE POLICY user_policy ON users
> USING (true)
> WITH CHECK (user_name = current_user);
> end cite
> This is is wrong description. Every one can steal other row with such
> policy.
Yup, you're right, this is too simple.
> The right statement to not allow modify rows by other user will be
> CREATE POLICY user_policy ON users
> USING (user_name = current_user)
> WITH CHECK (user_name = current_user);
Well, that also hides the other users' rows, which is not what the
example claims to do. To make it work as documented, we need something
like
CREATE POLICY user_sel_policy ON users
FOR SELECT
USING (true);
CREATE POLICY user_mod_policy ON users
USING (user_name = current_user);
I've pushed a patch along that line. Thanks for the report!
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, splarv@ya.ru
Subject: Re: Incorrect description of the WITH CHECK in the row security can lead to the security issue
In-Reply-To: <7182.1532966291@sss.pgh.pa.us>
References: <3298321532002010@sas1-2b3c3045b736.qloud-c.yandex.net> <7182.1532966291@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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