Skip to content

Commit 2d5db1d

Browse files
committed
[misc] Prevent password transmission over untrusted SSL with self-signed certificates for caching_sha2_password
1 parent b91022f commit 2d5db1d

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/cmd/handshake/auth/caching-sha2-password-auth.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ class CachingSha2PasswordAuth extends PluginAuth {
6262

6363
case 0x04:
6464
if (this.isSecureConnection()) {
65+
if (info.requireValidCert && info.selfSignedCertificate) {
66+
return this.throwError(
67+
Errors.createFatalError(
68+
'cannot send a `caching_sha2_password` and SSL without providing server certificates, cannot send password in clear on an untrusted SSL connection',
69+
Errors.client.ER_SELF_SIGNED_SHA256,
70+
info
71+
),
72+
info
73+
);
74+
}
6575
// Secure connection, sending password in clear
6676
out.startPacket(this);
6777
out.writeString(opts.password);

lib/connection.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,8 +1375,14 @@ class Connection extends EventEmitter {
13751375
// https://github.com/denoland/deno/issues/30892
13761376
if (typeof Deno !== 'undefined') {
13771377
info.requireValidCert = false;
1378-
} else if (info.isMariaDB()) {
1379-
// for MariaDB servers, permit self-signed certificated
1378+
} else if (info.requireValidCert &&
1379+
info.isMariaDB() &&
1380+
!this.opts.socketPath &&
1381+
Boolean(this.opts.password) &&
1382+
!(this.opts.ssl && this.opts.ssl.ca)
1383+
) {
1384+
// for MariaDB servers without local socket, with a password, and no server certificates provided:
1385+
// permit self-signed certificates at TLS level,
13801386
// this will be replaced by fingerprint validation with ending OK_PACKET
13811387
baseConf['rejectUnauthorized'] = false;
13821388
}

lib/misc/errors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ export const client = {
153153
ER_TLS_IDENTITY_ERROR: 45059,
154154
ER_POOL_NOT_INITIALIZED: 45060,
155155
ER_POOL_NO_CONNECTION: 45061,
156-
ER_SELF_SIGNED_BAD_PLUGIN: 45062
156+
ER_SELF_SIGNED_BAD_PLUGIN: 45062,
157+
ER_SELF_SIGNED_SHA256: 45063
157158
};
158159

159160
export function getClientErrorKey(errno) {

0 commit comments

Comments
 (0)