mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
BUG#18681: View privileges are broken
The check for view security was lacking several points : 1. Check with the right set of permissions : for each table ref that participates in a view there were the right credentials to use in it's security_ctx member, but these weren't used for checking the credentials. This makes hard enforcing the SQL SECURITY DEFINER|INVOKER property consistently. 2. Because of the above the security checking for views was just ruled out in explicit ways in several places. 3. The security was checked only for the columns of the tables that are brought into the query from a view. So if there is no column reference outside of the view definition it was not detecting the lack of access to the tables in the view in SQL SECURITY INVOKER mode. The fix below tries to fix the above 3 points.
This commit is contained in:
@ -4497,6 +4497,58 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
prepare tables and check access for the view tables
|
||||
|
||||
SYNOPSIS
|
||||
setup_tables_and_check_view_access()
|
||||
thd Thread handler
|
||||
context name resolution contest to setup table list there
|
||||
from_clause Top-level list of table references in the FROM clause
|
||||
tables Table list (select_lex->table_list)
|
||||
conds Condition of current SELECT (can be changed by VIEW)
|
||||
leaves List of join table leaves list (select_lex->leaf_tables)
|
||||
refresh It is onle refresh for subquery
|
||||
select_insert It is SELECT ... INSERT command
|
||||
want_access what access is needed
|
||||
|
||||
NOTE
|
||||
a wrapper for check_tables that will also check the resulting
|
||||
table leaves list for access to all the tables that belong to a view
|
||||
|
||||
RETURN
|
||||
FALSE ok; In this case *map will include the chosen index
|
||||
TRUE error
|
||||
*/
|
||||
bool setup_tables_and_check_access(THD *thd,
|
||||
Name_resolution_context *context,
|
||||
List<TABLE_LIST> *from_clause,
|
||||
TABLE_LIST *tables,
|
||||
Item **conds, TABLE_LIST **leaves,
|
||||
bool select_insert,
|
||||
ulong want_access)
|
||||
{
|
||||
TABLE_LIST *leaves_tmp = NULL;
|
||||
|
||||
if (setup_tables (thd, context, from_clause, tables, conds,
|
||||
&leaves_tmp, select_insert))
|
||||
return TRUE;
|
||||
|
||||
if (leaves)
|
||||
*leaves = leaves_tmp;
|
||||
|
||||
for (; leaves_tmp; leaves_tmp= leaves_tmp->next_leaf)
|
||||
if (leaves_tmp->belong_to_view &&
|
||||
check_one_table_access(thd, want_access, leaves_tmp))
|
||||
{
|
||||
tables->hide_view_error(thd);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Create a key_map from a list of index names
|
||||
|
||||
|
Reference in New Issue
Block a user