ITADN

Caching SHA-2 auth fails through Unix socket without SSL

#326ClosedMaxime-J 创建于 2025-08-25
M
Maxime-Jcommented
A simple connection with a user using `caching_sha2_password` through Unix socket doesn't work: ```js import { createConnection } from 'mariadb'; const conn = await createConnection({ socketPath: '/var/lib/mysql/mysql.sock', user: 'dbUser', password: 'dbPassword', database: 'db', }); conn.end(); ``` This should be tested from a freshly started server, or with a user who hasn't been successfully authenticated yet. (It could succeed because of caching if a connection through another way was successful with that user). ## Cause The password should be sent in clear when Unix socket is used, which is only currently done with SSL: https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/6baf9707985f9e256d964a066e0bd58487191ca2/lib/cmd/handshake/auth/caching-sha2-password-auth.js#L60-L67 So you either have to connect with SSL, which shouldn't be needed: ```javascript const conn = await createConnection({ socketPath: '/var/lib/mysql/mysql.sock', user: 'dbUser', password: 'dbPassword', database: 'db', ssl: true, // Or eventually // ssl: { rejectUnauthorized: false }, }); ``` Or tweak the plugin so that password is sent in clear. A proper fix would take into account that `socketPath` can be a named pipe, hence requiring RSA. I'll send a PR in few days. ### MySQL doc >For clients that use the caching_sha2_password plugin, passwords are never exposed as cleartext when connecting to the server. How password transmission occurs depends on whether a secure connection or RSA encryption is used: > >- If the connection is secure, an RSA key pair is unnecessary and is not used. This applies to TCP connections encrypted using TLS, as well as Unix socket-file and shared-memory connections. The password is sent as cleartext but cannot be snooped because the connection is secure. > >- If the connection is not secure, an RSA key pair is used. This applies to TCP connections not encrypted using TLS and named-pipe connections. RSA is used only for password exchange between client and server, to prevent password snooping. When the server receives the encrypted password, it decrypts it. A scramble is used in the encryption to prevent repeat attacks.
关闭于 2025-10-03 1 条评论