GHSA-3f6p-5ww8-9rcr: Npm/mysql2 vulnerability
Summary
A rogue MySQL server (or MITM) can force mysql2 to send credentials in plaintext by requesting an auth switch to mysqlclearpassword. The driver complies without verifying that TLS is active.
Details
mysqlclearpassword is registered as a default standard plugin in lib/commands/authswitch.js (line 21). When a server sends an AuthSwitchRequest (0xFE) requesting mysqlclearpassword, the driver executes it without checking for TLS. The plugin (lib/authplugins/mysqlclearpassword.js) returns Buffer.from(password + '\0').
Note: cachingsha2password plugin DOES check for SSL before sending cleartext (line 77). But mysqlclearpassword has no such guard.
Attack Scenario
1. Attacker operates rogue MySQL server or performs MITM 2. Server advertises cachingsha2password in handshake 3. Client sends hashed auth response 4. Server replies with AuthSwitchRequest to mysqlclearpassword 5. Client sends password in plaintext 6. Attacker captures plaintext password
PoC
Rogue MySQL server (Node.js, ~80 lines) that captures plaintext passwords from mysql2 clients. Tested against mysql2 3.20.0. Full PoC available on request.
Suggested Fix
Remove mysqlclearpassword from standardAuthPlugins, or add a guard requiring TLS/unix socket before allowing cleartext auth.
Impact
- mysql2: 9M weekly downloads - Any application connecting without TLS is vulnerable to credential theft - Cloud environments with untrusted network paths are especially at risk
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
npm/mysql2to a version that resolves this vulnerability.Fixed in 3.22.0 - Configuration
Remove `mysql_clear_password` from `standardAuthPlugins` so the mysql2 client cannot switch to cleartext authentication.
mysql2 (Node.js MySQL client) standardAuthPlugins = Remove mysql_clear_password - Configuration
Add a guard so that when an AuthSwitchRequest (0xFE) requests `mysql_clear_password`, the driver only proceeds if TLS is active (or when using unix socket), preventing plaintext password transmission.
mysql2 (Node.js MySQL client) cleartext auth guard (AuthSwitchRequest for mysql_clear_password) = Require TLS or unix socket before allowing cleartext auth - Compensating control
In cloud environments with untrusted network paths, ensure connections to MySQL use TLS so credential traffic is not sent in plaintext.
Event History
Frequently Asked Questions
What attacker position is required to capture a password?
The attacker must operate a rogue MySQL server or be able to perform a man-in-the-middle attack on the MySQL connection. The attacker can advertise caching_sha2_password during the handshake and then request a switch to mysql_clear_password.
Does exploitation require an application to explicitly enable the cleartext authentication plugin?
The mysql_clear_password plugin is registered as a default standard plugin in mysql2. When the server sends an AuthSwitchRequest for that plugin, the driver executes it without checking whether TLS is active.
What is actually exposed during a successful attack?
The driver sends the password as Buffer.from(password + '\0'), which exposes the plaintext password to the rogue server or intercepting attacker. The initial hashed authentication response does not prevent the later authentication switch from obtaining the plaintext password.
Which version has been demonstrated as affected?
The supplied proof of concept was tested against mysql2 3.20.0. No broader affected-version range is provided.