mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Fix column-privilege leak in error-message paths
While building error messages to return to the user, BuildIndexValueDescription, ExecBuildSlotValueDescription and ri_ReportViolation would happily include the entire key or entire row in the result returned to the user, even if the user didn't have access to view all of the columns being included. Instead, include only those columns which the user is providing or which the user has select rights on. If the user does not have any rights to view the table or any of the columns involved then no detail is provided and a NULL value is returned from BuildIndexValueDescription and ExecBuildSlotValueDescription. Note that, for key cases, the user must have access to all of the columns for the key to be shown; a partial key will not be returned. Further, in master only, do not return any data for cases where row security is enabled on the relation and row security should be applied for the user. This required a bit of refactoring and moving of things around related to RLS- note the addition of utils/misc/rls.c. Back-patch all the way, as column-level privileges are now in all supported versions. This has been assigned CVE-2014-8161, but since the issue and the patch have already been publicized on pgsql-hackers, there's no point in trying to hide this commit.
This commit is contained in:
@ -381,6 +381,37 @@ SELECT atest6 FROM atest6; -- ok
|
||||
(0 rows)
|
||||
|
||||
COPY atest6 TO stdout; -- ok
|
||||
-- check error reporting with column privs
|
||||
SET SESSION AUTHORIZATION regressuser1;
|
||||
CREATE TABLE t1 (c1 int, c2 int, c3 int check (c3 < 5), primary key (c1, c2));
|
||||
GRANT SELECT (c1) ON t1 TO regressuser2;
|
||||
GRANT INSERT (c1, c2, c3) ON t1 TO regressuser2;
|
||||
GRANT UPDATE (c1, c2, c3) ON t1 TO regressuser2;
|
||||
-- seed data
|
||||
INSERT INTO t1 VALUES (1, 1, 1);
|
||||
INSERT INTO t1 VALUES (1, 2, 1);
|
||||
INSERT INTO t1 VALUES (2, 1, 2);
|
||||
INSERT INTO t1 VALUES (2, 2, 2);
|
||||
INSERT INTO t1 VALUES (3, 1, 3);
|
||||
SET SESSION AUTHORIZATION regressuser2;
|
||||
INSERT INTO t1 (c1, c2) VALUES (1, 1); -- fail, but row not shown
|
||||
ERROR: duplicate key value violates unique constraint "t1_pkey"
|
||||
UPDATE t1 SET c2 = 1; -- fail, but row not shown
|
||||
ERROR: duplicate key value violates unique constraint "t1_pkey"
|
||||
INSERT INTO t1 (c1, c2) VALUES (null, null); -- fail, but see columns being inserted
|
||||
ERROR: null value in column "c1" violates not-null constraint
|
||||
DETAIL: Failing row contains (c1, c2) = (null, null).
|
||||
INSERT INTO t1 (c3) VALUES (null); -- fail, but see columns being inserted or have SELECT
|
||||
ERROR: null value in column "c1" violates not-null constraint
|
||||
DETAIL: Failing row contains (c1, c3) = (null, null).
|
||||
INSERT INTO t1 (c1) VALUES (5); -- fail, but see columns being inserted or have SELECT
|
||||
ERROR: null value in column "c2" violates not-null constraint
|
||||
DETAIL: Failing row contains (c1) = (5).
|
||||
UPDATE t1 SET c3 = 10; -- fail, but see columns with SELECT rights, or being modified
|
||||
ERROR: new row for relation "t1" violates check constraint "t1_c3_check"
|
||||
DETAIL: Failing row contains (c1, c3) = (1, 10).
|
||||
SET SESSION AUTHORIZATION regressuser1;
|
||||
DROP TABLE t1;
|
||||
-- test column-level privileges when involved with DELETE
|
||||
SET SESSION AUTHORIZATION regressuser1;
|
||||
ALTER TABLE atest6 ADD COLUMN three integer;
|
||||
|
@ -295,7 +295,6 @@ INSERT INTO document VALUES (10, 33, 1, current_user, 'hoge');
|
||||
SET SESSION AUTHORIZATION rls_regress_user1;
|
||||
INSERT INTO document VALUES (8, 44, 1, 'rls_regress_user1', 'my third manga'); -- Must fail with unique violation, revealing presence of did we can't see
|
||||
ERROR: duplicate key value violates unique constraint "document_pkey"
|
||||
DETAIL: Key (did)=(8) already exists.
|
||||
SELECT * FROM document WHERE did = 8; -- and confirm we can't see it
|
||||
did | cid | dlevel | dauthor | dtitle
|
||||
-----+-----+--------+---------+--------
|
||||
@ -1683,7 +1682,6 @@ EXPLAIN (COSTS OFF) WITH cte1 AS (SELECT * FROM t1 WHERE f_leak(b)) SELECT * FRO
|
||||
|
||||
WITH cte1 AS (UPDATE t1 SET a = a + 1 RETURNING *) SELECT * FROM cte1; --fail
|
||||
ERROR: new row violates WITH CHECK OPTION for "t1"
|
||||
DETAIL: Failing row contains (1, cfcd208495d565ef66e7dff9f98764da).
|
||||
WITH cte1 AS (UPDATE t1 SET a = a RETURNING *) SELECT * FROM cte1; --ok
|
||||
a | b
|
||||
----+----------------------------------
|
||||
@ -1702,7 +1700,6 @@ WITH cte1 AS (UPDATE t1 SET a = a RETURNING *) SELECT * FROM cte1; --ok
|
||||
|
||||
WITH cte1 AS (INSERT INTO t1 VALUES (21, 'Fail') RETURNING *) SELECT * FROM cte1; --fail
|
||||
ERROR: new row violates WITH CHECK OPTION for "t1"
|
||||
DETAIL: Failing row contains (21, Fail).
|
||||
WITH cte1 AS (INSERT INTO t1 VALUES (20, 'Success') RETURNING *) SELECT * FROM cte1; --ok
|
||||
a | b
|
||||
----+---------
|
||||
|
@ -256,6 +256,31 @@ UPDATE atest5 SET one = 1; -- fail
|
||||
SELECT atest6 FROM atest6; -- ok
|
||||
COPY atest6 TO stdout; -- ok
|
||||
|
||||
-- check error reporting with column privs
|
||||
SET SESSION AUTHORIZATION regressuser1;
|
||||
CREATE TABLE t1 (c1 int, c2 int, c3 int check (c3 < 5), primary key (c1, c2));
|
||||
GRANT SELECT (c1) ON t1 TO regressuser2;
|
||||
GRANT INSERT (c1, c2, c3) ON t1 TO regressuser2;
|
||||
GRANT UPDATE (c1, c2, c3) ON t1 TO regressuser2;
|
||||
|
||||
-- seed data
|
||||
INSERT INTO t1 VALUES (1, 1, 1);
|
||||
INSERT INTO t1 VALUES (1, 2, 1);
|
||||
INSERT INTO t1 VALUES (2, 1, 2);
|
||||
INSERT INTO t1 VALUES (2, 2, 2);
|
||||
INSERT INTO t1 VALUES (3, 1, 3);
|
||||
|
||||
SET SESSION AUTHORIZATION regressuser2;
|
||||
INSERT INTO t1 (c1, c2) VALUES (1, 1); -- fail, but row not shown
|
||||
UPDATE t1 SET c2 = 1; -- fail, but row not shown
|
||||
INSERT INTO t1 (c1, c2) VALUES (null, null); -- fail, but see columns being inserted
|
||||
INSERT INTO t1 (c3) VALUES (null); -- fail, but see columns being inserted or have SELECT
|
||||
INSERT INTO t1 (c1) VALUES (5); -- fail, but see columns being inserted or have SELECT
|
||||
UPDATE t1 SET c3 = 10; -- fail, but see columns with SELECT rights, or being modified
|
||||
|
||||
SET SESSION AUTHORIZATION regressuser1;
|
||||
DROP TABLE t1;
|
||||
|
||||
-- test column-level privileges when involved with DELETE
|
||||
SET SESSION AUTHORIZATION regressuser1;
|
||||
ALTER TABLE atest6 ADD COLUMN three integer;
|
||||
|
Reference in New Issue
Block a user