1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-36380 User has unauthorized access to a sequence through a view with security invoker

check sequence privileges in Item_func_nextval::fix_fields(),
just like column privileges are checked in Item_field::fix_fields()

remove sequence specific hacks that kinda made sequence privilege
checks works, but not in all cases. And they were too lax,
didn't requre SELECT privilege for NEXTVAL. Also INSERT privilege looks
wrong here, UPDATE would've been more appropriate, but won't
change that for compatibility reasons.

also fixes

MDEV-36413 User without any privileges to a sequence can read from it and modify it via column default
This commit is contained in:
Sergei Golubchik
2025-04-11 08:28:42 +02:00
parent f89f8aa313
commit f99586668a
11 changed files with 211 additions and 26 deletions

View File

@ -47,14 +47,57 @@ next_not_cached_value minimum_value maximum_value start_value increment cache_si
11 1 9223372036854775806 1 1 1000 0 0
connection only_alter;
select next value for s1;
ERROR 42000: INSERT command denied to user 'only_alter'@'localhost' for table `mysqltest_1`.`s1`
ERROR 42000: SELECT, INSERT command denied to user 'only_alter'@'localhost' for table `mysqltest_1`.`s1`
alter sequence s1 restart= 11;
select * from s1;
ERROR 42000: SELECT command denied to user 'only_alter'@'localhost' for table `mysqltest_1`.`s1`
connection default;
drop database mysqltest_1;
drop user 'normal'@'%';
drop user 'read_only'@'%';
drop user 'read_write'@'%';
drop user 'alter'@'%';
drop user 'only_alter'@'%';
drop sequence s1;
#
# MDEV-36413 User without any privileges to a sequence can read from
# it and modify it via column default
#
create sequence s1;
create sequence s2;
select * from s2;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 9223372036854775806 1 1 1000 0 0
create table t2 (a int not null default(nextval(s1)));
insert into t2 values();
create user u;
grant create, insert, select, drop on mysqltest_1.t1 to u;
grant insert, select on mysqltest_1.s1 to u;
grant select on mysqltest_1.t2 to u;
connect con1,localhost,u,,mysqltest_1;
select nextval(s2);
ERROR 42000: SELECT, INSERT command denied to user 'u'@'localhost' for table `mysqltest_1`.`s2`
show create sequence s2;
ERROR 42000: SHOW command denied to user 'u'@'localhost' for table `mysqltest_1`.`s2`
create table t1 (a int not null default(nextval(s1)));
drop table t1;
create table t1 (a int not null default(nextval(s1))) select a from t2;
insert into t1 values();
select * from t1;
a
1
2
drop table t1;
create table t1 (a int not null default(nextval(s1))) select a from (select t2.a from t2,t2 as t3 where t2.a=t3.a) as t4;
drop table t1;
create table t1 (a int not null default(nextval(s2)));
ERROR 42000: SELECT, INSERT command denied to user 'u'@'localhost' for table `mysqltest_1`.`s2`
create table t1 (a int not null default(nextval(s1)),
b int not null default(nextval(s2)));
ERROR 42000: SELECT, INSERT command denied to user 'u'@'localhost' for table `mysqltest_1`.`s2`
disconnect con1;
connection default;
drop user u;
drop database mysqltest_1;
#
# End of 10.11 tests
#

View File

@ -60,10 +60,58 @@ select * from s1;
#
connection default;
drop database mysqltest_1;
drop user 'normal'@'%';
drop user 'read_only'@'%';
drop user 'read_write'@'%';
drop user 'alter'@'%';
drop user 'only_alter'@'%';
drop sequence s1;
--echo #
--echo # MDEV-36413 User without any privileges to a sequence can read from
--echo # it and modify it via column default
--echo #
create sequence s1;
create sequence s2;
select * from s2;
create table t2 (a int not null default(nextval(s1)));
insert into t2 values();
create user u;
grant create, insert, select, drop on mysqltest_1.t1 to u;
grant insert, select on mysqltest_1.s1 to u;
grant select on mysqltest_1.t2 to u;
--connect(con1,localhost,u,,mysqltest_1)
--error ER_TABLEACCESS_DENIED_ERROR
select nextval(s2);
--error ER_TABLEACCESS_DENIED_ERROR
show create sequence s2;
create table t1 (a int not null default(nextval(s1)));
drop table t1;
create table t1 (a int not null default(nextval(s1))) select a from t2;
insert into t1 values();
select * from t1;
drop table t1;
create table t1 (a int not null default(nextval(s1))) select a from (select t2.a from t2,t2 as t3 where t2.a=t3.a) as t4;
drop table t1;
--error ER_TABLEACCESS_DENIED_ERROR
create table t1 (a int not null default(nextval(s2)));
--error ER_TABLEACCESS_DENIED_ERROR
create table t1 (a int not null default(nextval(s1)),
b int not null default(nextval(s2)));
--disconnect con1
--connection default
drop user u;
#
# Cleanup
#
drop database mysqltest_1;
--echo #
--echo # End of 10.11 tests
--echo #

View File

@ -174,7 +174,7 @@ create sequence s_db.s2;
drop sequence s_db.s2;
connection m_normal_2;
select next value for s_db.s1;
ERROR 42000: INSERT command denied to user 'normal_2'@'localhost' for table `s_db`.`s1`
ERROR 42000: SELECT, INSERT command denied to user 'normal_2'@'localhost' for table `s_db`.`s1`
create sequence s_db.s2;
ERROR 42000: CREATE command denied to user 'normal_2'@'localhost' for table `s_db`.`s2`
connection m_normal_1;

View File

@ -285,7 +285,7 @@ create sequence s_db.s2;
drop sequence s_db.s2;
connection m_normal_2;
select NEXT VALUE for s_db.s1;
ERROR 42000: INSERT command denied to user 'normal_2'@'localhost' for table `s_db`.`s1`
ERROR 42000: SELECT, INSERT command denied to user 'normal_2'@'localhost' for table `s_db`.`s1`
create sequence s_db.s2;
ERROR 42000: CREATE command denied to user 'normal_2'@'localhost' for table `s_db`.`s2`
connection m_normal_1;

View File

@ -1,5 +1,4 @@
--source include/have_sequence.inc
--source include/have_innodb.inc
#
# Test sequences with views