Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-7025

ANALYZE SELECT/INSERT/UPDATE/DELETE from a view does not check access permissions on the underlying table

Details

    Description

      Test case

      --enable_connect_log
      create database db;
      use db;
      create table t1 (i int, c varchar(8));
      insert into t1 values (1,'foo'),(2,'bar'),(3,'baz'),(4,'qux');
      create view v1 as select * from t1 where i > 1;
      grant all on db.v1 to u1@localhost;
       
      --connect (con1,localhost,u1,,)
       
      --error ER_TABLEACCESS_DENIED_ERROR
      select * from db.t1;
      --error ER_TABLEACCESS_DENIED_ERROR
      explain select * from db.t1;
      --error ER_TABLEACCESS_DENIED_ERROR
      analyze select * from db.t1;
       
      select * from db.v1;
      --error ER_VIEW_NO_EXPLAIN
      explain select * from db.v1;
      --error ER_VIEW_NO_EXPLAIN
      analyze select * from db.v1;
       
      --disconnect con1
      --connection default
       
      drop user u1@localhost;
      drop database db;

      The last statement should fail just like the previous one does, but it succeeds (and reveals the underlying t1 table in the output).

      Same for INSERT, UPDATE, DELETE.

      Attachments

        Issue Links

          Activity

            elenst Elena Stepanova created issue -
            elenst Elena Stepanova made changes -
            Field Original Value New Value
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            Description {code:sql|title=Test case}
            --enable_connect_log

            create database db;
            use db;
            create table t1 (i int, c varchar(8));
            insert into t1 values (1,'foo'),(2,'bar'),(3,'baz'),(4,'qux');
            create view v1 as select * from t1 where i > 1;
            grant all on db.v1 to u1@localhost;

            --connect (con1,localhost,u1,,)

            --error ER_TABLEACCESS_DENIED_ERROR
            select * from db.t1;
            --error ER_TABLEACCESS_DENIED_ERROR
            explain select * from db.t1;
            --error ER_TABLEACCESS_DENIED_ERROR
            analyze select * from db.t1;

            select * from db.v1;
            --error ER_VIEW_NO_EXPLAIN
            explain select * from db.v1;
            --error ER_VIEW_NO_EXPLAIN
            analyze select * from db.v1;
            {code}

            The last statement should fail just like the previous one does, but it succeeds (and reveals the underlying t1 table in the output).
            {code:sql|title=Test case}
            --enable_connect_log
            create database db;
            use db;
            create table t1 (i int, c varchar(8));
            insert into t1 values (1,'foo'),(2,'bar'),(3,'baz'),(4,'qux');
            create view v1 as select * from t1 where i > 1;
            grant all on db.v1 to u1@localhost;

            --connect (con1,localhost,u1,,)

            --error ER_TABLEACCESS_DENIED_ERROR
            select * from db.t1;
            --error ER_TABLEACCESS_DENIED_ERROR
            explain select * from db.t1;
            --error ER_TABLEACCESS_DENIED_ERROR
            analyze select * from db.t1;

            select * from db.v1;
            --error ER_VIEW_NO_EXPLAIN
            explain select * from db.v1;
            --error ER_VIEW_NO_EXPLAIN
            analyze select * from db.v1;
            {code}

            The last statement should fail just like the previous one does, but it succeeds (and reveals the underlying t1 table in the output).
            elenst Elena Stepanova made changes -
            Description {code:sql|title=Test case}
            --enable_connect_log
            create database db;
            use db;
            create table t1 (i int, c varchar(8));
            insert into t1 values (1,'foo'),(2,'bar'),(3,'baz'),(4,'qux');
            create view v1 as select * from t1 where i > 1;
            grant all on db.v1 to u1@localhost;

            --connect (con1,localhost,u1,,)

            --error ER_TABLEACCESS_DENIED_ERROR
            select * from db.t1;
            --error ER_TABLEACCESS_DENIED_ERROR
            explain select * from db.t1;
            --error ER_TABLEACCESS_DENIED_ERROR
            analyze select * from db.t1;

            select * from db.v1;
            --error ER_VIEW_NO_EXPLAIN
            explain select * from db.v1;
            --error ER_VIEW_NO_EXPLAIN
            analyze select * from db.v1;
            {code}

            The last statement should fail just like the previous one does, but it succeeds (and reveals the underlying t1 table in the output).
            {code:sql|title=Test case}
            --enable_connect_log
            create database db;
            use db;
            create table t1 (i int, c varchar(8));
            insert into t1 values (1,'foo'),(2,'bar'),(3,'baz'),(4,'qux');
            create view v1 as select * from t1 where i > 1;
            grant all on db.v1 to u1@localhost;

            --connect (con1,localhost,u1,,)

            --error ER_TABLEACCESS_DENIED_ERROR
            select * from db.t1;
            --error ER_TABLEACCESS_DENIED_ERROR
            explain select * from db.t1;
            --error ER_TABLEACCESS_DENIED_ERROR
            analyze select * from db.t1;

            select * from db.v1;
            --error ER_VIEW_NO_EXPLAIN
            explain select * from db.v1;
            --error ER_VIEW_NO_EXPLAIN
            analyze select * from db.v1;

            --disconnect con1
            --connection default

            drop user u1@localhost;
            drop database db;
            {code}

            The last statement should fail just like the previous one does, but it succeeds (and reveals the underlying t1 table in the output).
            elenst Elena Stepanova made changes -
            Summary ANALYZE SELECT from a view does not check access permissions to the underlying table ANALYZE SELECT/INSERT/UPDATE/DELETE from a view does not check access permissions to the underlying table
            elenst Elena Stepanova made changes -
            Description {code:sql|title=Test case}
            --enable_connect_log
            create database db;
            use db;
            create table t1 (i int, c varchar(8));
            insert into t1 values (1,'foo'),(2,'bar'),(3,'baz'),(4,'qux');
            create view v1 as select * from t1 where i > 1;
            grant all on db.v1 to u1@localhost;

            --connect (con1,localhost,u1,,)

            --error ER_TABLEACCESS_DENIED_ERROR
            select * from db.t1;
            --error ER_TABLEACCESS_DENIED_ERROR
            explain select * from db.t1;
            --error ER_TABLEACCESS_DENIED_ERROR
            analyze select * from db.t1;

            select * from db.v1;
            --error ER_VIEW_NO_EXPLAIN
            explain select * from db.v1;
            --error ER_VIEW_NO_EXPLAIN
            analyze select * from db.v1;

            --disconnect con1
            --connection default

            drop user u1@localhost;
            drop database db;
            {code}

            The last statement should fail just like the previous one does, but it succeeds (and reveals the underlying t1 table in the output).
            {code:sql|title=Test case}
            --enable_connect_log
            create database db;
            use db;
            create table t1 (i int, c varchar(8));
            insert into t1 values (1,'foo'),(2,'bar'),(3,'baz'),(4,'qux');
            create view v1 as select * from t1 where i > 1;
            grant all on db.v1 to u1@localhost;

            --connect (con1,localhost,u1,,)

            --error ER_TABLEACCESS_DENIED_ERROR
            select * from db.t1;
            --error ER_TABLEACCESS_DENIED_ERROR
            explain select * from db.t1;
            --error ER_TABLEACCESS_DENIED_ERROR
            analyze select * from db.t1;

            select * from db.v1;
            --error ER_VIEW_NO_EXPLAIN
            explain select * from db.v1;
            --error ER_VIEW_NO_EXPLAIN
            analyze select * from db.v1;

            --disconnect con1
            --connection default

            drop user u1@localhost;
            drop database db;
            {code}

            The last statement should fail just like the previous one does, but it succeeds (and reveals the underlying t1 table in the output).

            Same for INSERT, UPDATE, DELETE.
            elenst Elena Stepanova made changes -
            Summary ANALYZE SELECT/INSERT/UPDATE/DELETE from a view does not check access permissions to the underlying table ANALYZE SELECT/INSERT/UPDATE/DELETE from a view does not check access permissions on the underlying table
            psergei Sergei Petrunia made changes -
            Assignee Sergei Petrunia [ psergey ] Vicentiu Ciorbaru [ cvicentiu ]
            cvicentiu Vicențiu Ciorbaru made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            cvicentiu Vicențiu Ciorbaru made changes -
            Assignee Vicentiu Ciorbaru [ cvicentiu ] Sergei Petrunia [ psergey ]
            Status In Progress [ 3 ] In Review [ 10002 ]

            review feedback provided over email

            psergei Sergei Petrunia added a comment - review feedback provided over email
            psergei Sergei Petrunia made changes -
            Assignee Sergei Petrunia [ psergey ] Vicentiu Ciorbaru [ cvicentiu ]
            Status In Review [ 10002 ] Stalled [ 10000 ]

            Added access checks to be performed for the analyze statement, similarly to how it was done for EXPLAIN and SHOW VIEW.

            Fixed with:
            0ed57e34c76ffa5e457e1abb402ada6352fb52b2

            cvicentiu Vicențiu Ciorbaru added a comment - Added access checks to be performed for the analyze statement, similarly to how it was done for EXPLAIN and SHOW VIEW. Fixed with: 0ed57e34c76ffa5e457e1abb402ada6352fb52b2
            cvicentiu Vicențiu Ciorbaru made changes -
            Fix Version/s 10.1.4 [ 18400 ]
            Fix Version/s 10.1 [ 16100 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -
            Component/s OTHER [ 10125 ]
            ratzpo Rasmus Johansson (Inactive) made changes -
            Workflow MariaDB v2 [ 58211 ] MariaDB v3 [ 66959 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 66959 ] MariaDB v4 [ 148414 ]

            People

              cvicentiu Vicențiu Ciorbaru
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.