The vulnerability exists in the LDAP authentication method of HashiCorp Vault when the username_as_alias option is enabled. The root cause is the improper handling of usernames with leading or trailing whitespace. An attacker could authenticate with a username like ' user' instead of 'user', causing Vault to create a new, distinct entity alias. Since MFA policies are tied to the canonical entity alias, this new alias would not have any MFA enforcement, allowing the attacker to bypass the security control.
The patch addresses this by changing how the entity alias is created. Instead of directly using the user-provided username, the patched code now parses the Distinguished Name (DN) returned by the LDAP server upon successful authentication. It extracts the canonical username from the DN and uses that to create the entity alias. This ensures that, regardless of any extra whitespace in the provided username, the same canonical entity alias is always used, and thus the correct MFA policies are always enforced.
The analysis of the patch commit 299306ff4e3657c469e86da459144dda3c627ae8 clearly shows these changes in the backend.Login function within builtin/credential/ldap/backend.go. The backend.pathLogin function in builtin/credential/ldap/path_login.go is the HTTP handler that calls the vulnerable Login function, making it a critical part of the exploitation path.