Correctly determine $PASS_COLUMN_NAME, Fixing #22#23
Open
lewart3 wants to merge 1 commit intojmrenouard:masterfrom
Open
Correctly determine $PASS_COLUMN_NAME, Fixing #22#23lewart3 wants to merge 1 commit intojmrenouard:masterfrom
lewart3 wants to merge 1 commit intojmrenouard:masterfrom
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors how the password/authentication column is determined for the mysql.user table by directly inspecting existing columns instead of relying on server version parsing and ad‑hoc shell queries, and improves the skip messaging when no known auth column is found. Sequence diagram for determining PASS_COLUMN_NAME in security_recommendationssequenceDiagram
participant Security_recommendations
participant select_table_columns_db
participant MySQL_server
Security_recommendations->>select_table_columns_db: get mysql_user_columns(mysql, user)
select_table_columns_db->>MySQL_server: SELECT COLUMN_NAME FROM information_schema.columns WHERE TABLE_SCHEMA = mysql AND TABLE_NAME = user
MySQL_server-->>select_table_columns_db: column_name list
select_table_columns_db-->>Security_recommendations: @mysql_user_columns
alt authentication_string column exists
Security_recommendations->>Security_recommendations: PASS_COLUMN_NAME = authentication_string
else Password column exists
Security_recommendations->>Security_recommendations: PASS_COLUMN_NAME = Password
else no known auth column
Security_recommendations->>Security_recommendations: badprint Skipped because could not determine auth column
Security_recommendations-->>Security_recommendations: return
end
Security_recommendations->>Security_recommendations: debugprint Password column = PASS_COLUMN_NAME
Flow diagram for new PASS_COLUMN_NAME detection logicflowchart TD
A[start security_recommendations] --> B[Call select_table_columns_db with mysql and user]
B --> C[Receive mysql_user_columns]
C --> D{Does mysql_user_columns contain authentication_string?}
D -->|yes| E[Set PASS_COLUMN_NAME to authentication_string]
D -->|no| F{Does mysql_user_columns contain Password?}
F -->|yes| G[Set PASS_COLUMN_NAME to Password]
F -->|no| H[badprint Skipped because could not determine auth column]
H --> I[return from security_recommendations]
E --> J[debugprint Password column = PASS_COLUMN_NAME]
G --> J
J --> K[Continue security checks]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- The previous implementation handled the rare but possible case where both
authentication_stringandpasswordexisted by using anIF(plugin=...)expression; the new code always picksauthentication_stringif present, which may break on instances still relying on the legacypasswordcolumn, so consider preserving a combined expression when both columns are present. - The new detection only matches a capitalized
Passwordcolumn; since older MySQL/MariaDB installations sometimes exposepasswordin varying cases, consider making the check case-insensitive or verifying the exact column name(s) returned byselect_table_columns_dbto avoid false negatives.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The previous implementation handled the rare but possible case where both `authentication_string` and `password` existed by using an `IF(plugin=...)` expression; the new code always picks `authentication_string` if present, which may break on instances still relying on the legacy `password` column, so consider preserving a combined expression when both columns are present.
- The new detection only matches a capitalized `Password` column; since older MySQL/MariaDB installations sometimes expose `password` in varying cases, consider making the check case-insensitive or verifying the exact column name(s) returned by `select_table_columns_db` to avoid false negatives.
## Individual Comments
### Comment 1
<location> `mysqltuner.pl:3312-3315` </location>
<code_context>
- return;
- }
+ my @mysql_user_columns = select_table_columns_db( 'mysql', 'user' );
+ if ( grep { /^authentication_string$/msx } @mysql_user_columns ) {
+ $PASS_COLUMN_NAME = 'authentication_string';
}
+ elsif ( grep { /^Password$/msx } @mysql_user_columns ) {
+ $PASS_COLUMN_NAME = 'Password';
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** Potential change in behavior when both `authentication_string` and `password` columns exist
The prior query used:
```sql
IF(plugin='mysql_native_password', authentication_string, password)
```
which supported mixed setups where some users still only had `password` populated. The new logic always prefers `authentication_string` when the column exists and never falls back to `password`, so users with only `password` set may now be treated as having empty credentials.
Please consider reinstating a conditional expression (or equivalent query construction) when both columns exist, so that `authentication_string` is preferred for `mysql_native_password` users while still correctly handling accounts that only use `password`.
</issue_to_address>
### Comment 2
<location> `mysqltuner.pl:3315` </location>
<code_context>
+ if ( grep { /^authentication_string$/msx } @mysql_user_columns ) {
+ $PASS_COLUMN_NAME = 'authentication_string';
}
+ elsif ( grep { /^Password$/msx } @mysql_user_columns ) {
+ $PASS_COLUMN_NAME = 'Password';
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** Column name case might not match typical `mysql.user` schema
The previous implementation matched `COLUMN_NAME = 'password'` (lowercase), but the new logic only checks for `Password` (capital P). On common MySQL setups the column is actually lowercase, so this may stop detecting the password column on some versions.
To preserve compatibility, either:
* Match `password` (lowercase) as before, or
* Do a case-insensitive match (e.g., `lc $_ eq 'password'`) so this works regardless of column-name casing.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
lewart3
referenced
this pull request
Feb 14, 2026
#22) - Refactored password column detection into a standalone sub. - Implemented schema-based detection using information_schema.COLUMNS. - Added regression test tests/repro_issue_22.t. - Updated tests/test_issue_875.t mocks. - Updated Changelog.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Better and much simpler logic.
However, needs testing across all supported MariaDB and MySQL versions.
Future: if mysql.global_priv table exists, use that instead:
SELECT JSON_VALUE(Priv, '$.authentication_string') authentication_string FROM mysql.global_priv;Summary by Sourcery
Simplify and harden detection of the authentication column in the mysql.user table when generating security recommendations.
Bug Fixes:
Enhancements: