This commit is contained in:
2026-03-15 12:22:42 +01:00
parent cd99275933
commit 311ba5e7f3
558 changed files with 55182 additions and 22981 deletions

View File

@@ -3,6 +3,7 @@
const PLUGIN_NAME = 'sha256_password';
const crypto = require('crypto');
const { xorRotating } = require('../auth_41');
const Tls = require('tls');
const REQUEST_SERVER_KEY_PACKET = Buffer.from([1]);
@@ -32,6 +33,14 @@ module.exports =
return (data) => {
switch (state) {
case STATE_INITIAL:
if (
connection.stream instanceof Tls.TLSSocket &&
connection.stream.encrypted === true
) {
// We don't need to encrypt passwords over TLS connection
return Buffer.from(`${password}\0`, 'utf8');
}
scramble = data.slice(0, 20);
// if client provides key we can save one extra roundrip on first connection
if (pluginOptions.serverPublicKey) {

View File

@@ -345,7 +345,9 @@ class BaseConnection extends EventEmitter {
});
const rejectUnauthorized = this.config.ssl.rejectUnauthorized;
const verifyIdentity = this.config.ssl.verifyIdentity;
const servername = this.config.host;
const servername = Net.isIP(this.config.host)
? undefined
: this.config.host;
let secureEstablished = false;
this.stream.removeAllListeners('data');
@@ -410,6 +412,37 @@ class BaseConnection extends EventEmitter {
this.emit('error', err);
}
get state() {
// Error state has highest priority
if (this._fatalError || this._protocolError) {
return 'error';
}
// Closing state has second priority
if (this._closing || (this.stream && this.stream.destroyed)) {
return 'disconnected';
}
// Authenticated state has third priority
if (this.authorized) {
return 'authenticated';
}
// Connected state: handshake completed but not yet authorized
// This matches the original mysql driver's 'connected' state
if (this._handshakePacket) {
return 'connected';
}
// Protocol handshake state: connection established, handshake in progress
if (this.stream && !this.stream.destroyed) {
return 'protocol_handshake';
}
// Default: not connected
return 'disconnected';
}
get fatalError() {
return this._fatalError;
}

View File

@@ -48,7 +48,6 @@ class ClientHandshake extends Command {
sendCredentials(connection) {
if (connection.config.debug) {
// eslint-disable-next-line
console.log(
'Sending handshake packet: flags:%d=(%s)',
this.clientFlags,
@@ -111,7 +110,6 @@ class ClientHandshake extends Command {
});
this.handshake = Packets.Handshake.fromPacket(helloPacket);
if (connection.config.debug) {
// eslint-disable-next-line
console.log(
'Server hello packet: capability flags:%d=(%s)',
this.handshake.capabilityFlags,

View File

@@ -39,7 +39,7 @@ class Query extends Command {
then() {
const err =
"You have tried to call .then(), .catch(), or invoked await on the result of query that is not a promise, which is a programming error. Try calling con.promise().query(), or require('mysql2/promise') instead of 'mysql2' for a promise-compatible version of the query interface. To learn how to use async/await or Promises check out documentation at https://sidorares.github.io/node-mysql2/docs#using-promise-wrapper, or the mysql2 documentation at https://sidorares.github.io/node-mysql2/docs/documentation/promise-wrapper";
// eslint-disable-next-line
console.log(err);
throw new Error(err);
}
@@ -47,7 +47,6 @@ class Query extends Command {
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
start(_packet, connection) {
if (connection.config.debug) {
// eslint-disable-next-line
console.log(' Sending query command: %s', this.sql);
}
this._connection = connection;
@@ -119,7 +118,6 @@ class Query extends Command {
const rs = new Packets.ResultSetHeader(packet, connection);
this._fieldCount = rs.fieldCount;
if (connection.config.debug) {
// eslint-disable-next-line
console.log(
` Resultset header received, expecting ${rs.fieldCount} column definition packets`
);
@@ -201,12 +199,10 @@ class Query extends Command {
);
this._fields[this._resultIndex].push(field);
if (connection.config.debug) {
/* eslint-disable no-console */
console.log(' Column definition:');
console.log(` name: ${field.name}`);
console.log(` type: ${field.columnType}`);
console.log(` flags: ${field.flags}`);
/* eslint-enable no-console */
}
}
// last field received
@@ -235,7 +231,6 @@ class Query extends Command {
return this.row;
}
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
row(packet, _connection) {
if (packet.isEOF()) {
const status = packet.eofStatusFlags();

View File

@@ -168,7 +168,6 @@ class ServerHandshake extends Command {
if (connection.listeners('packet').length) {
connection.emit('packet', packet.clone(), knownCommand, commandCode);
} else if (!knownCommand) {
// eslint-disable-next-line no-console
console.log('Unknown command:', commandCode);
}
return ServerHandshake.prototype.dispatchCommands;

View File

@@ -87,7 +87,6 @@ class ConnectionConfig {
if (!Object.prototype.hasOwnProperty.call(options, key)) continue;
if (validOptions[key] !== 1) {
// REVIEW: Should this be emitted somehow?
// eslint-disable-next-line no-console
console.error(
`Ignoring invalid configuration option passed to Connection: ${key}. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection`
);
@@ -131,7 +130,7 @@ class ConnectionConfig {
) {
// strictly supports timezones specified by mysqljs/mysql:
// https://github.com/mysqljs/mysql#user-content-connection-options
// eslint-disable-next-line no-console
console.error(
`Ignoring invalid timezone passed to Connection: ${options.timezone}. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection`
);
@@ -282,7 +281,7 @@ class ConnectionConfig {
try {
// Try to parse this as a JSON expression first
options[key] = JSON.parse(value);
} catch (err) {
} catch {
// Otherwise assume it is a plain string
options[key] = value;
}

View File

@@ -31,7 +31,6 @@ exports.CONNECT_ATTRS = 0x00100000; /* permits connection attributes */
exports.PLUGIN_AUTH_LENENC_CLIENT_DATA = 0x00200000; /* Understands length-encoded integer for auth response data in Protocol::HandshakeResponse41. */
exports.CAN_HANDLE_EXPIRED_PASSWORDS = 0x00400000; /* Announces support for expired password extension. */
exports.SESSION_TRACK = 0x00800000; /* Can set SERVER_SESSION_STATE_CHANGED in the Status Flags and send session-state change data after a OK packet. */
exports.DEPRECATE_EOF = 0x01000000; /* Can send OK after a Text Resultset. */
exports.SSL_VERIFY_SERVER_CERT = 0x40000000;
exports.REMEMBER_OPTIONS = 0x80000000;

5
node_modules/mysql2/lib/helpers.js generated vendored
View File

@@ -28,10 +28,9 @@ try {
// the purpose of this is to prevent projects using Webpack from displaying a warning during runtime if cardinal is not a dependency
const REQUIRE_TERMINATOR = '';
highlightFn = require(`cardinal${REQUIRE_TERMINATOR}`).highlight;
} catch (err) {
} catch {
highlightFn = (text) => {
if (!cardinalRecommended) {
// eslint-disable-next-line no-console
console.log('For nicer debug output consider install cardinal@^2.0.0');
cardinalRecommended = true;
}
@@ -43,9 +42,7 @@ try {
* Prints debug message with code frame, will try to use `cardinal` if available.
*/
function printDebugWithCode(msg, code) {
// eslint-disable-next-line no-console
console.log(`\n\n${msg}:\n`);
// eslint-disable-next-line no-console
console.log(`${highlightFn(code)}\n`);
}

View File

@@ -73,7 +73,6 @@ class Packet {
}
dump() {
// eslint-disable-next-line no-console
console.log(
[this.buffer.asciiSlice(this.start, this.end)],
this.buffer.slice(this.start, this.end),
@@ -227,7 +226,7 @@ class Packet {
res = resNumber.toString() === resString ? resNumber : resString;
return bigNumberStrings ? resString : res;
}
// eslint-disable-next-line no-console
console.trace();
throw new Error(`Should not reach here: ${tag}`);
}

View File

@@ -9,10 +9,10 @@ module.exports = function (command, connectionStream) {
options = options || {};
options.objectMode = true;
(stream = new Readable(options)),
((stream = new Readable(options)),
(stream._read = function () {
connectionStream.resume();
});
}));
this.on('result', (row, i) => {
if (!stream.push(row)) {