Skip to content

MDEV-38862: server_audit: Fix double comma in user lists causing incorrect filtering#4598

Closed
KevinDryden wants to merge 2 commits intoMariaDB:mainfrom
KevinDryden:fix-server-audit-double-comma-user-list
Closed

MDEV-38862: server_audit: Fix double comma in user lists causing incorrect filtering#4598
KevinDryden wants to merge 2 commits intoMariaDB:mainfrom
KevinDryden:fix-server-audit-double-comma-user-list

Conversation

@KevinDryden
Copy link
Copy Markdown

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.

Testing

Added 6 MTR tests to verify the fix handles all edge cases:

Test Description
plugins.server_audit_double_comma Double comma in incl_users ('user1,,user2')
plugins.server_audit_excl_double_comma Double comma in excl_users
plugins.server_audit_edge_commas Leading/trailing commas (',user1,user2,')
plugins.server_audit_empty_input Empty and whitespace-only input
plugins.server_audit_multiple_commas Multiple consecutive commas ('user1,,,,,user2')
plugins.server_audit_whitespace Whitespace around usernames (' user1 , user2 ')

Test Results - With Fix (MariaDB main branch)

TEST                                      RESULT   TIME (ms)
--------------------------------------------------------------------------
plugins.server_audit_double_comma        [ pass ]     10
plugins.server_audit_edge_commas         [ pass ]     22
plugins.server_audit_empty_input         [ pass ]     18
plugins.server_audit_excl_double_comma   [ pass ]     10
plugins.server_audit_multiple_commas     [ pass ]     10
plugins.server_audit_whitespace          [ pass ]     15
--------------------------------------------------------------------------
Completed: All 6 tests were successful.

Test Results - Without Fix (Bug Reproduction)

To verify the tests correctly detect the bug, we reverted the fix and ran the tests:

TEST                                      RESULT   TIME (ms)
--------------------------------------------------------------------------
plugins.server_audit_double_comma        [ fail ]
plugins.server_audit_edge_commas         [ fail ]
plugins.server_audit_empty_input         [ pass ]     18
plugins.server_audit_excl_double_comma   [ fail ]
plugins.server_audit_multiple_commas     [ fail ]
plugins.server_audit_whitespace          [ fail ]
--------------------------------------------------------------------------
Failed 5/6 tests, 16.67% were successful.

Note: server_audit_empty_input passes without the fix because it tests different behavior - when incl_users contains 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.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Jan 28, 2026
@KevinDryden KevinDryden force-pushed the fix-server-audit-double-comma-user-list branch 2 times, most recently from 8a3912b to 0cc2f9a Compare January 29, 2026 21:34
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.
@KevinDryden KevinDryden force-pushed the fix-server-audit-double-comma-user-list branch from 0cc2f9a to 00fdb96 Compare January 30, 2026 00:01
@gkodinov gkodinov changed the title server_audit: Fix double comma in user lists causing incorrect filtering MDEV-38862: server_audit: Fix double comma in user lists causing incorrect filtering Feb 18, 2026
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why no view protocol?

@@ -0,0 +1,101 @@
--source include/not_embedded.inc
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@gkodinov gkodinov self-assigned this Feb 18, 2026
@gkodinov
Copy link
Copy Markdown
Member

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.

@gkodinov gkodinov closed this Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

3 participants