MySQL: a user without a password is refused when the server switches the auth plugin (empty password scrambled)
メンテナーはふだん 4 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 80/100
調査の方向性
sqlx-mysql/src/connection/establish.rsの0xfe認証切り替え処理から始め、次にAuthPlugin::scrambleを読んで、空のパスワードがどのように扱われるかを確認してください。issueにあるMySQL 8.4のDocker手順で再現し、変更後にパスワードなしのユーザーが接続できることを確認してください。issueでは特定のテストは挙げられていません。空のパスワードでの認証切り替えケースを対象とするテストを追加するか、実行してください。
索引モデルが issue の本文から書いたものです。
説明
I have found these related issues/pull requests
#3484 (closed): people kept reporting "Access denied … (using password: YES)" for users without a password; this is a reproduction on a clean database, with the cause.
Description
A MySQL user with no password can't log in with sqlx-mysql 0.9.0 when the server switches the auth plugin during the handshake (an AuthSwitchRequest): sqlx answers with a scramble of the empty string instead of an empty response, so the server sees a wrong password. The mysql client logs in fine.
In sqlx-mysql/src/connection/establish.rs, the 0xfe (auth switch) arm calls
switch.plugin.scramble(&mut stream, options.password.as_deref().unwrap_or_default(), &nonce)
and AuthPlugin::scramble turns "" into 20 (native) or 32 (caching_sha2) bytes. libmysqlclient sends an empty auth response for an empty password.
Reproduction steps
docker run -d --name sqlx-repro -e MYSQL_ROOT_PASSWORD=root -p 127.0.0.1:53390:3306 mysql:8.4 --mysql-native-password=ON
docker exec sqlx-repro mysql -uroot -proot -e "CREATE USER 'nopw'@'%' IDENTIFIED WITH mysql_native_password BY ''"
docker exec sqlx-repro mysql -h127.0.0.1 -unopw -e "select 1" # the mysql client: works
// sqlx = { version = "=0.9.0", default-features = false, features = ["mysql", "runtime-tokio"] }
use sqlx::mysql::MySqlConnectOptions;
use sqlx::ConnectOptions;
#[tokio::main]
async fn main() {
// No `.password()`: the user has none.
let options = MySqlConnectOptions::new().host("127.0.0.1").port(53390).username("nopw");
match options.connect().await {
Ok(_) => println!("connected"),
Err(e) => println!("error: {e}"),
}
}
Prints error: error returned from database: 1045 (28000): Access denied for user 'nopw'@'172.17.0.1' (using password: YES).
The same happens on public servers that use such users, e.g. EBI's Rfam (mysql://[email protected]:4497/Rfam).
A fix
Answer with an empty response when the password is empty, for the plugins that scramble it. In AuthPlugin::scramble:
AuthPlugin::CachingSha2Password | AuthPlugin::MySqlNativePassword if password.is_empty() => Ok(Vec::new()),
With that, the program above prints connected (checked against the same container), and Rfam connects. Happy to send it as a pull request.
SQLx version
0.9.0
Enabled SQLx features
mysql, runtime-tokio
Database server and version
MySQL 8.4.11 (Docker mysql:8.4), and EBI's public Rfam server
Operating system
macOS 26
Rust version
1.99
- 主要言語
- Rust
- スター
- 17.5k
- フォーク
- 1.7k
- 平均マージ
- 3日 17時間
- マージ済み PR(30日)
- 11
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
transact-rs/sqlx のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
transact-rs/sqlx#4466 ·
メンテナーはふだん 4 日以内に返信
-
MySQL: ENUM and SET columns with a binary collation are named BINARY or CHAR対応中かも @CodeMasterXZT が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
transact-rs/sqlx#4453 ·
メンテナーはふだん 4 日以内に返信
-
Postgres text arrays: a quoted "NULL" element is decoded as SQL NULL対応中かも @MinJaeRun が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
transact-rs/sqlx#4452 ·
メンテナーはふだん 4 日以内に返信
-
Fetch stream ends after first error using query macros対応中かも @barry3406 が 205 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
transact-rs/sqlx#4126 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
transact-rs/sqlx#3963 · コメント 2 件 ·
メンテナーはふだん 4 日以内に返信
transact-rs/sqlx の issue をすべて見る
似ている issue
-
bug duplicate enhancement priority: low ui
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
storytold/pdfcraft#5594 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
documentation good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
open-jarvis/OpenJarvis#1212 ·
メンテナーはふだん 4 日以内に返信
-
bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
CakeRepository/agentshangout#38 ·
メンテナーはふだん 1 日以内に返信