-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mysqlnd fails to authenticate with sha256_password accounts using passwords longer than 19 characters. #11438
Comments
I think there's an off-by-one in mysqlnd_xor_string. If I subtract 1 from the xor_str_len in the modulo operand, it seems to work... I'll dig a bit deeper. |
…ccounts using passwords longer than 19 characters https://dev.mysql.com/doc/dev/mysql-server/latest/page_caching_sha2_authentication_exchanges.html tells us that the nonce used in this authentication method is 20 bytes long. However, we might receive additional scramble data in php_mysqlnd_greet_read not used in this method. On my test setup, I received 21 bytes (20 bytes + '\0'). This resulted in the xor computation to incorrectly include the NUL byte. Every password of at least 20 characters therefore failed to authenticate using this method. Looking at mysql-server source code also seems to reveal that it always uses a fixed number of scramble bytes [1]. [1] https://github.com/mysql/mysql-server/blob/ea7087d885006918ad54458e7aad215b1650312c/sql/auth/sha2_password.cc#L1078-L1079
The behavior you are experiencing is related to how PHP's mysqli extension handles the connection authentication method when using the In MySQL 8.0.4 and later, a new default authentication plugin was introduced called To resolve this issue, you have a couple of options:
Note that using mysqlnd is generally recommended for better compatibility with the latest MySQL features and improvements. However, if you have a specific need to stick with Remember to restart your web server (e.g., Apache or Nginx) after making any changes to the PHP configuration. |
@MohamedAbuZamil your answer doesn't make sense. Please refrain from posting nonsense AI-generated content. |
…ccounts using passwords longer than 19 characters https://dev.mysql.com/doc/dev/mysql-server/latest/page_caching_sha2_authentication_exchanges.html tells us that the nonce used in this authentication method is 20 bytes long. However, we might receive additional scramble data in php_mysqlnd_greet_read not used in this method. On my test setup, I received 21 bytes (20 bytes + '\0'). This resulted in the xor computation to incorrectly include the NUL byte. Every password of at least 20 characters therefore failed to authenticate using this method. Looking at mysql-server source code also seems to reveal that it always uses a fixed number of scramble bytes [1]. [1] https://github.com/mysql/mysql-server/blob/ea7087d885006918ad54458e7aad215b1650312c/sql/auth/sha2_password.cc#L1078-L1079 Closes phpGH-11445. Co-authored-by: Kamil Tekiela <[email protected]>
Description
The following code:
Resulted in this output:
But I expected this output instead:
With the mysql client, authentication works as expected.
PHP Version
PHP 8.1.2
Operating System
Ubuntu 22.04
The text was updated successfully, but these errors were encountered: