Skip to content

server: expose the matched password index during authentication - #4

Merged
thatliuser merged 3 commits into
formalco:masterfrom
pwnh4:fix/matched-password-index
Oct 6, 2026
Merged

thatliuser merged 3 commits into
formalco:masterfrom
pwnh4:fix/matched-password-index

Conversation

@loic-fml

@loic-fml loic-fml commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

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 in OnAuthSuccess, without changing existing authentication interfaces.

  • Record the first matching index during native, SHA256, and full caching-SHA2 authentication, including empty passwords.
  • Resolve SHA2 cache hits against the current credential list so reordering cannot misattribute a match and removed credentials require full authentication.
  • Clear the match on authentication failure. Custom providers report no match unless they delegate verification to the default provider.

Validation

go test -race ./server ./mysql ./packet ./compress -count=1 passed. 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 in Credential.Passwords verified the connection (intended for use in OnAuthSuccess), 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 (replacing Credential.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 AuthenticationHandler are updated (immutable Passwords during 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.

@thatliuser thatliuser left a comment

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.

thx!

@thatliuser
thatliuser merged commit d6c14a1 into formalco:master Oct 6, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants