MDEV-38862: server_audit: Fix double comma in user lists causing incorrect filtering#4598
MDEV-38862: server_audit: Fix double comma in user lists causing incorrect filtering#4598KevinDryden wants to merge 2 commits intoMariaDB:mainfrom
Conversation
|
|
8a3912b to
0cc2f9a
Compare
When SERVER_AUDIT_INCL_USERS or SERVER_AUDIT_EXCL_USERS contains double commas (e.g., 'user1,,user2'), the audit plugin behaves incorrectly: - For incl_users: ALL users are logged instead of only specified users - For excl_users: ALL users are excluded instead of only specified users The root cause is in user_coll_fill(). When parsing a user list string with consecutive commas, the parser calls getkey_user() with the pointer positioned at a comma, which returns cmp_length of 0. Then coll_insert() inserts an empty string into the user collection, corrupting the collection's search behavior. The fix adds a check to skip empty tokens (when the current character is a comma after whitespace has been skipped) before attempting to extract a username. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.
0cc2f9a to
00fdb96
Compare
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution! This is a preliminary review.
Please clear the CLA bot: click on the CLA button and make sure you sign the CLA.
Then please re-base to 10.6. This is a bug and is reproducible in 10.6 so let's please fix it as per the guideline.
| if (!*users) | ||
| return 0; | ||
|
|
||
| /* Skip consecutive commas (empty tokens) to prevent inserting empty entries */ |
There was a problem hiding this comment.
Why not just call getkey_user and check if cmp_length is zero? That's how you're describing the fix. This has the advantage that it will also cover empty user at the end, i.e. a trailing comma.
| @@ -0,0 +1,104 @@ | |||
| --source include/not_embedded.inc | |||
| --source include/no_view_protocol.inc | |||
| @@ -0,0 +1,101 @@ | |||
| --source include/not_embedded.inc | |||
There was a problem hiding this comment.
All of these tests are essentially the same test, just with different parameters and different expectations.
Why not have the bulk of these in an inc file and just pass parameters to it?
|
It's been more than 3 weeks since I've last replied to this PR. And I've got no response. Closing it due to inactivity. Please re-open if/when you intend to continue working on it. |
When SERVER_AUDIT_INCL_USERS or SERVER_AUDIT_EXCL_USERS contains double commas (e.g., 'user1,,user2'), the audit plugin behaves incorrectly:
The root cause is in user_coll_fill(). When parsing a user list string with consecutive commas, the parser calls getkey_user() with the pointer positioned at a comma, which returns cmp_length of 0. Then coll_insert() inserts an empty string into the user collection, corrupting the collection's search behavior.
The fix adds a check to skip empty tokens (when the current character is a comma after whitespace has been skipped) before attempting to extract a username.
Testing
Added 6 MTR tests to verify the fix handles all edge cases:
plugins.server_audit_double_commaincl_users('user1,,user2')plugins.server_audit_excl_double_commaexcl_usersplugins.server_audit_edge_commas',user1,user2,')plugins.server_audit_empty_inputplugins.server_audit_multiple_commas'user1,,,,,user2')plugins.server_audit_whitespace' user1 , user2 ')Test Results - With Fix (MariaDB main branch)
Test Results - Without Fix (Bug Reproduction)
To verify the tests correctly detect the bug, we reverted the fix and ran the tests:
Note:
server_audit_empty_inputpasses without the fix because it tests different behavior - whenincl_userscontains only commas/whitespace (no valid usernames), the expected behavior is to log ALL users (empty inclusion list = no filtering). This is correct behavior that works with or without the fix. The other 5 tests verify the bug scenario where valid usernames are mixed with empty tokens.All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.