GHSA-3f6p-5ww8-9rcr: Npm/mysql2 vulnerability

Published Sep 1, 2026
·
Updated

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

1 affected componentFixes available
npm/mysql2<3.22.0
3.22.0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade npm/mysql2 to a version that resolves this vulnerability.

    Fixed in 3.22.0
  2. 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
  3. 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
  4. 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

Sep 1, 2026
Advisory Published
via GitHub·04:40 PM
Data Sourced
via GitHub·04:40 PM
DescriptionWeaknessAffected Software

Frequently Asked Questions

1

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.

2

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.

3

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.

4

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.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203