Skip to content
/ server Public

Commit d757345

Browse files
committed
Add test cases for comment handling in audit plugin
The fix was implemented in 635559a. Previously with the hand-rolled SQL string parsing in the audit plugin, there were many simple ways to bypass server audit logging by placing comments strategically in the query string. The fix in 635559a removes the custom SQL string parser which addresses the issue. We now add MTRs for validation.
1 parent 4e674a2 commit d757345

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

mysql-test/suite/plugins/r/server_audit.result

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,43 @@ select 2;
177177
/*comment*/ select 2;
178178
2
179179
2
180+
with foo as (select 1) select 6;
181+
6
182+
6
183+
values (7, 'a'), (8, 'b');
184+
7 a
185+
7 a
186+
8 b
187+
#
188+
# Certain usage of comments and control characters in query strings bypass audit
189+
# logging when filtering in QUERY_{DCL/DML/DDL} mode
190+
#
191+
-- A comment
192+
select 1;
193+
1
194+
1
195+
--A comment
196+
select 2;
197+
2
198+
2
199+
# A comment
200+
select 3;
201+
3
202+
3
203+
/*! SELECT 4 */;
204+
4
205+
4
206+
/*M! SELECT 5 */;
207+
5
208+
5
209+
/*!100100 SELECT 6 */;
210+
6
211+
6
212+
/*!999999 SELECT 'should not log' */;
213+
/*M!100100 SELECT 7 */;
214+
7
215+
7
216+
/*M!999999 SELECT 'should not log' */;
180217
drop table t1;
181218
set global server_audit_events='query_dcl';
182219
create table t1(id int);
@@ -441,6 +478,15 @@ TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'select 2',0
441478
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'(select 2)',0
442479
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'/*! select 2*/',0
443480
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'/*comment*/ select 2',0
481+
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'with foo as (select 1) select 6',0
482+
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'values (7, \'a\'), (8, \'b\')',0
483+
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'-- A comment\nselect 1',0
484+
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'--A comment\nselect 2',0
485+
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'# A comment\nselect 3',0
486+
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'/*! SELECT 4 */',0
487+
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'/*M! SELECT 5 */',0
488+
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'/*!100100 SELECT 6 */',0
489+
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'/*M!100100 SELECT 7 */',0
444490
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'CREATE USER u1 IDENTIFIED BY *****',0
445491
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'GRANT ALL ON sa_db TO u2 IDENTIFIED BY *****',0
446492
TIME,HOSTNAME,root,localhost,ID,ID,QUERY,sa_db,'CREATE USER u3 IDENTIFIED BY *****',0

mysql-test/suite/plugins/t/server_audit.test

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,31 @@ select 2;
133133
(select 2);
134134
/*! select 2*/;
135135
/*comment*/ select 2;
136+
with foo as (select 1) select 6;
137+
values (7, 'a'), (8, 'b');
138+
139+
--echo #
140+
--echo # Certain usage of comments and control characters in query strings bypass audit
141+
--echo # logging when filtering in QUERY_{DCL/DML/DDL} mode
142+
--echo #
143+
144+
query -- A comment
145+
select 1;
146+
147+
query --A comment
148+
select 2;
149+
150+
query # A comment
151+
select 3;
152+
153+
query /*! SELECT 4 */;
154+
query /*M! SELECT 5 */;
155+
156+
query /*!100100 SELECT 6 */;
157+
query /*!999999 SELECT 'should not log' */;
158+
query /*M!100100 SELECT 7 */;
159+
query /*M!999999 SELECT 'should not log' */;
160+
136161
drop table t1;
137162
set global server_audit_events='query_dcl';
138163
create table t1(id int);

0 commit comments

Comments
 (0)