Repository navigation
server: expose the matched password index during authentication - #4
Merged
Merged
Conversation
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.
Description
When a server accepts multiple passwords for one username, applications cannot identify which credential authenticated the connection. This prevents associating the connection with credential-specific identity or authorization metadata.
Add
Conn.MatchedPasswordIndex() (int, bool), available inOnAuthSuccess, without changing existing authentication interfaces.Validation
go test -race ./server ./mysql ./packet ./compress -count=1passed. Tests cover TLS/RSA, plugin switches, multiple and empty passwords, failures, policy rejection, cache hits, credential reordering/removal, and custom-provider delegation.Note
Medium Risk
Touches MySQL authentication and caching_sha2 fast-path validation; behavior changes when cached credentials no longer match the current password list.
Overview
Adds
Conn.MatchedPasswordIndex()so handlers can see which entry inCredential.Passwordsverified the connection (intended for use inOnAuthSuccess), without changing existing auth interfaces.The default auth paths now record the first matching password index for native, SHA256, full caching-SHA2, and empty-password logins, and clear that state when authentication fails or when a custom provider does not delegate to the default verifier. Empty-password handling is centralized in
compareEmptyPassword(replacingCredential.hasEmptyPassword).For caching_sha2_password fast cache hits, the server no longer trusts the cache alone: it re-resolves the cached hash against the current credential list, sets the matched index when a password still matches, and falls back to full auth if the cached secret was removed or no longer applies—avoiding wrong index attribution after reorder or revocation.
Docs on
AuthenticationHandlerare updated (immutablePasswordsduring auth, cache expectations). New tests and an example cover TLS, plugin switches, duplicates, failures, cache reorder/removal, and custom providers.Reviewed by Cursor Bugbot for commit 119c365. Bugbot is set up for automated code reviews on this repo. Configure here.