mysql2 3.21.1 → 3.21.2-canary.884bec56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -72,6 +72,28 @@ function authSwitchRequest(packet, connection, command) {
|
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
if (pluginName === 'mysql_clear_password') {
|
|
76
|
+
const hasCustomPlugin =
|
|
77
|
+
connection.config.authPlugins &&
|
|
78
|
+
Object.prototype.hasOwnProperty.call(
|
|
79
|
+
connection.config.authPlugins,
|
|
80
|
+
'mysql_clear_password'
|
|
81
|
+
);
|
|
82
|
+
if (!hasCustomPlugin && !connection.config.enableCleartextPlugin) {
|
|
83
|
+
const err = new Error(
|
|
84
|
+
'Server requested authentication using mysql_clear_password, ' +
|
|
85
|
+
'which sends the password in plaintext over the network and is ' +
|
|
86
|
+
'disabled by default. To enable it, set the `enableCleartextPlugin` ' +
|
|
87
|
+
'option to `true` in your connection configuration, or provide a ' +
|
|
88
|
+
'custom `mysql_clear_password` auth plugin via the `authPlugins` ' +
|
|
89
|
+
'option. Only use this over a secure connection (TLS/SSL).'
|
|
90
|
+
);
|
|
91
|
+
err.code = 'MYSQL_CLEAR_PASSWORD_NOT_ENABLED';
|
|
92
|
+
err.fatal = true;
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
75
97
|
const authPlugin = getAuthPlugin(pluginName, connection);
|
|
76
98
|
if (!authPlugin) {
|
|
77
99
|
throw new Error(
|
|
@@ -105,7 +105,9 @@ class ClientHandshake extends Command {
|
|
|
105
105
|
const canUseDirectAuth =
|
|
106
106
|
!hasCustomAuthPlugin &&
|
|
107
107
|
!hasLegacyAuthSwitchHandler &&
|
|
108
|
-
this.canUseAuthMethodDirectly(serverAuthMethod, isSecureConnection)
|
|
108
|
+
this.canUseAuthMethodDirectly(serverAuthMethod, isSecureConnection) &&
|
|
109
|
+
(serverAuthMethod !== 'mysql_clear_password' ||
|
|
110
|
+
connection.config.enableCleartextPlugin);
|
|
109
111
|
|
|
110
112
|
const clientAuthMethod = canUseDirectAuth
|
|
111
113
|
? serverAuthMethod
|
|
@@ -339,8 +341,9 @@ class ClientHandshake extends Command {
|
|
|
339
341
|
}
|
|
340
342
|
return ClientHandshake.prototype.handshakeResult;
|
|
341
343
|
} catch (err) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
+
if (!err.code) {
|
|
345
|
+
err.code = 'AUTH_SWITCH_PLUGIN_ERROR';
|
|
346
|
+
}
|
|
344
347
|
err.fatal = true;
|
|
345
348
|
|
|
346
349
|
if (this.onResult) {
|
package/lib/connection_config.js
CHANGED
|
@@ -60,6 +60,7 @@ const validOptions = {
|
|
|
60
60
|
uri: 1,
|
|
61
61
|
user: 1,
|
|
62
62
|
disableEval: 1,
|
|
63
|
+
enableCleartextPlugin: 1,
|
|
63
64
|
// These options are used for Pool
|
|
64
65
|
connectionLimit: 1,
|
|
65
66
|
maxIdle: 1,
|
|
@@ -152,6 +153,7 @@ class ConnectionConfig {
|
|
|
152
153
|
options.nestTables === undefined ? undefined : options.nestTables;
|
|
153
154
|
this.typeCast = options.typeCast === undefined ? true : options.typeCast;
|
|
154
155
|
this.disableEval = Boolean(options.disableEval);
|
|
156
|
+
this.enableCleartextPlugin = Boolean(options.enableCleartextPlugin);
|
|
155
157
|
if (this.timezone[0] === ' ') {
|
|
156
158
|
// "+" is a url encoded char for space so it
|
|
157
159
|
// gets translated to space when giving a
|
package/package.json
CHANGED
|
@@ -326,6 +326,18 @@ export interface ConnectionOptions {
|
|
|
326
326
|
|
|
327
327
|
disableEval?: boolean;
|
|
328
328
|
|
|
329
|
+
/**
|
|
330
|
+
* Enable the `mysql_clear_password` authentication plugin, which sends the
|
|
331
|
+
* password in plaintext. Disabled by default for security — only enable
|
|
332
|
+
* over secure connections (TLS/SSL).
|
|
333
|
+
*
|
|
334
|
+
* Providing a custom `mysql_clear_password` function via `authPlugins`
|
|
335
|
+
* implicitly enables cleartext authentication without this flag.
|
|
336
|
+
*
|
|
337
|
+
* (Default: false)
|
|
338
|
+
*/
|
|
339
|
+
enableCleartextPlugin?: boolean;
|
|
340
|
+
|
|
329
341
|
authPlugins?: {
|
|
330
342
|
[key: string]: AuthPlugin;
|
|
331
343
|
};
|