|
| 1 | +# |
| 2 | +# Bug#33732907: Slow query log logs password in plain text on syntax error |
| 3 | +# |
| 4 | + |
| 5 | +SET @save_sqlf=@@global.slow_query_log_file; |
| 6 | +SET @save_sql=@@global.slow_query_log; |
| 7 | +SET @save_lo=@@global.log_output; |
| 8 | +SET @save_lqt=@@session.long_query_time; |
| 9 | +SET GLOBAL slow_query_log_file= '.../slow33732907.log'; |
| 10 | +SET @@global.slow_query_log=1; |
| 11 | +SET @@global.log_output='file,table'; |
| 12 | +SET @@session.long_query_time=0; |
| 13 | + |
| 14 | +# This succeeds, and the password is correctly obfuscated. |
| 15 | +CREATE USER 'duplicate_user'@'%' IDENTIFIED BY 'mypassword'; |
| 16 | +# This fails, but the password is still correctly obfuscated. |
| 17 | +CREATE USER 'duplicate_user'@'%' IDENTIFIED BY 'mypassword'; |
| 18 | +ERROR HY000: Operation CREATE USER failed for 'duplicate_user'@'%' |
| 19 | + |
| 20 | +# Since we throw an error during the parse stage, we don't know which |
| 21 | +# part of the statement is the password (or whether there even is one), |
| 22 | +# so we cannot obfuscate it. In that case, the statement should not be |
| 23 | +# logged, either. The general log also behaves like this by default. |
| 24 | +CREATE USER ‘bad_characters’@’%’ IDENTIFIED BY 'mypassword'; |
| 25 | +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '��bad_characters’@’%’ IDENTIFIED BY 'mypassword'' at line 1 |
| 26 | +# Expected: 1 OK stmt, 1 failed stmt, 0 unparseable stmts |
| 27 | +SELECT "general table>",argument |
| 28 | +FROM mysql.general_log |
| 29 | +WHERE INSTR(argument,"CREATE USER")=1 |
| 30 | +ORDER BY event_time; |
| 31 | +general table> argument |
| 32 | +general table> CREATE USER 'duplicate_user'@'%' IDENTIFIED WITH 'mysql_native_password' AS '<secret>' |
| 33 | +general table> CREATE USER 'duplicate_user'@'%' IDENTIFIED WITH 'mysql_native_password' AS '<secret>' |
| 34 | +# Expected: 1 OK stmt, 1 failed stmt, 0 unparseable stmts |
| 35 | +SELECT "slow table>",sql_text |
| 36 | +FROM mysql.slow_log |
| 37 | +WHERE INSTR(sql_text,"CREATE USER")=1 |
| 38 | +ORDER BY start_time; |
| 39 | +slow table> sql_text |
| 40 | +slow table> CREATE USER 'duplicate_user'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*FABE5482D5AADF36D028AC443D117BE1180B9725' |
| 41 | +slow table> CREATE USER 'duplicate_user'@'%' IDENTIFIED WITH 'mysql_native_password' AS '<secret>' |
| 42 | +SET @@global.slow_query_log_file=@save_sqlf; |
| 43 | +SET @@global.slow_query_log=@save_sql; |
| 44 | +SET @@global.log_output=@save_lo; |
| 45 | +SET @@session.long_query_time=@save_lqt; |
| 46 | +DROP USER 'duplicate_user'@'%'; |
| 47 | +# Expected: 1 OK stmt, 1 failed stmt, 0 unparseable stmts |
| 48 | +slow file>CREATE USER 'duplicate_user'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*FABE5482D5AADF36D028AC443D117BE1180B9725'; |
| 49 | +slow file>CREATE USER 'duplicate_user'@'%' IDENTIFIED WITH 'mysql_native_password' AS '<secret>'; |
| 50 | +TRUNCATE mysql.slow_log; |
| 51 | +TRUNCATE mysql.general_log; |
| 52 | +# |
| 53 | +# Done. |
0 commit comments