mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
MDEV-3915 COM_CHANGE_USER allows fast password brute-forcing
allow only three failed change_user per connection. successful change_user do NOT reset the counter tests/mysql_client_test.c: make --error to work for --change_user errors
This commit is contained in:
@ -1144,6 +1144,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
|
||||
|
||||
uint save_db_length= thd->db_length;
|
||||
char *save_db= thd->db;
|
||||
int rc;
|
||||
USER_CONN *save_user_connect= thd->user_connect;
|
||||
Security_context save_security_ctx= *thd->security_ctx;
|
||||
CHARSET_INFO *save_character_set_client=
|
||||
@ -1157,7 +1158,19 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
|
||||
thd->security_ctx->user= 0;
|
||||
thd->user_connect= 0;
|
||||
|
||||
if (acl_authenticate(thd, 0, packet_length))
|
||||
/*
|
||||
to limit COM_CHANGE_USER ability to brute-force passwords,
|
||||
we only allow three unsuccessful COM_CHANGE_USER per connection.
|
||||
*/
|
||||
if (thd->failed_com_change_user >= 3)
|
||||
{
|
||||
my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
|
||||
rc= 1;
|
||||
}
|
||||
else
|
||||
rc= acl_authenticate(thd, 0, packet_length);
|
||||
|
||||
if (rc)
|
||||
{
|
||||
/* Free user if allocated by acl_authenticate */
|
||||
x_free(thd->security_ctx->user);
|
||||
@ -1170,6 +1183,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
|
||||
thd->variables.collation_connection= save_collation_connection;
|
||||
thd->variables.character_set_results= save_character_set_results;
|
||||
thd->update_charset();
|
||||
thd->failed_com_change_user++;
|
||||
my_sleep(1000000);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user