You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

mongodb-core

Package Overview
Dependencies
Maintainers
3
Versions
177
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.3 to 3.1.4

18

HISTORY.md

@@ -5,2 +5,20 @@ # Change Log

<a name="3.1.4"></a>
## [3.1.4](https://github.com/mongodb-js/mongodb-core/compare/v3.1.3...v3.1.4) (2018-09-14)
### Bug Fixes
* **apm:** fix upconversion for OP_QUERY in apm ([f969bee](https://github.com/mongodb-js/mongodb-core/commit/f969bee))
* **gssapi:** check lowercase and camelCase gssapiServiceName option ([bf0315d](https://github.com/mongodb-js/mongodb-core/commit/bf0315d))
* **test:** do not check deep equality when test.auth.db is null ([7d3c057](https://github.com/mongodb-js/mongodb-core/commit/7d3c057))
* **uri_parser:** use admin as default auth.db ([345e6af](https://github.com/mongodb-js/mongodb-core/commit/345e6af))
### Features
* **connection:** Implement fast fallback ([622394a](https://github.com/mongodb-js/mongodb-core/commit/622394a))
<a name="3.1.3"></a>

@@ -7,0 +25,0 @@ ## [3.1.3](https://github.com/mongodb-js/mongodb-core/compare/v3.1.2...v3.1.3) (2018-08-25)

3

lib/auth/gssapi.js

@@ -49,3 +49,4 @@ 'use strict';

if (Kerberos == null) return callback(new Error('Kerberos library is not installed'));
var gssapiServiceName = options['gssapiServiceName'] || 'mongodb';
// TODO: remove this once we fix URI parsing
var gssapiServiceName = options['gssapiservicename'] || options['gssapiServiceName'] || 'mongodb';
// Total connections

@@ -52,0 +53,0 @@ var count = connections.length;

@@ -79,8 +79,14 @@ 'use strict';

if (command.query && command.query.$query) {
// upconvert legacy find command
const result = { find: collectionName(command) };
Object.keys(LEGACY_FIND_QUERY_MAP).forEach(key => {
if (typeof command.query[key] !== 'undefined')
result[LEGACY_FIND_QUERY_MAP[key]] = command.query[key];
});
let result;
if (command.ns === 'admin.$cmd') {
// upconvert legacy command
result = Object.assign({}, command.query.$query);
} else {
// upconvert legacy find command
result = { find: collectionName(command) };
Object.keys(LEGACY_FIND_QUERY_MAP).forEach(key => {
if (typeof command.query[key] !== 'undefined')
result[LEGACY_FIND_QUERY_MAP[key]] = command.query[key];
});
}

@@ -87,0 +93,0 @@ Object.keys(LEGACY_FIND_OPTIONS_MAP).forEach(key => {

@@ -231,13 +231,13 @@ 'use strict';

// Connection handlers
var errorHandler = function(self) {
var errorHandler = function(conn) {
return function(err) {
if (connectionAccounting) deleteConnection(self.id);
if (connectionAccounting) deleteConnection(conn.id);
// Debug information
if (self.logger.isDebug())
self.logger.debug(
if (conn.logger.isDebug())
conn.logger.debug(
f(
'connection %s for [%s:%s] errored out with [%s]',
self.id,
self.host,
self.port,
conn.id,
conn.host,
conn.port,
JSON.stringify(err)

@@ -247,17 +247,17 @@ )

// Emit the error
if (self.listeners('error').length > 0) self.emit('error', new MongoNetworkError(err), self);
if (conn.listeners('error').length > 0) conn.emit('error', new MongoNetworkError(err), conn);
};
};
var timeoutHandler = function(self) {
var timeoutHandler = function(conn) {
return function() {
if (connectionAccounting) deleteConnection(self.id);
if (connectionAccounting) deleteConnection(conn.id);
// Debug information
if (self.logger.isDebug())
self.logger.debug(f('connection %s for [%s:%s] timed out', self.id, self.host, self.port));
if (conn.logger.isDebug())
conn.logger.debug(f('connection %s for [%s:%s] timed out', conn.id, conn.host, conn.port));
// Emit timeout error
self.emit(
conn.emit(
'timeout',
new MongoNetworkError(f('connection %s to %s:%s timed out', self.id, self.host, self.port)),
self
new MongoNetworkError(f('connection %s to %s:%s timed out', conn.id, conn.host, conn.port)),
conn
);

@@ -267,15 +267,15 @@ };

var closeHandler = function(self) {
var closeHandler = function(conn) {
return function(hadError) {
if (connectionAccounting) deleteConnection(self.id);
if (connectionAccounting) deleteConnection(conn.id);
// Debug information
if (self.logger.isDebug())
self.logger.debug(f('connection %s with for [%s:%s] closed', self.id, self.host, self.port));
if (conn.logger.isDebug())
conn.logger.debug(f('connection %s with for [%s:%s] closed', conn.id, conn.host, conn.port));
// Emit close event
if (!hadError) {
self.emit(
conn.emit(
'close',
new MongoNetworkError(f('connection %s to %s:%s closed', self.id, self.host, self.port)),
self
new MongoNetworkError(f('connection %s to %s:%s closed', conn.id, conn.host, conn.port)),
conn
);

@@ -287,3 +287,3 @@ }

// Handle a message once it is recieved
var emitMessageHandler = function(self, message) {
var emitMessageHandler = function(conn, message) {
var msgHeader = parseHeader(message);

@@ -308,17 +308,17 @@ if (msgHeader.opCode === OP_COMPRESSED) {

}
self.messageHandler(
new Response(self.bson, message, msgHeader, decompressedMsgBody, self.responseOptions),
self
conn.messageHandler(
new Response(conn.bson, message, msgHeader, decompressedMsgBody, conn.responseOptions),
conn
);
});
} else {
self.messageHandler(
conn.messageHandler(
new Response(
self.bson,
conn.bson,
message,
msgHeader,
message.slice(MESSAGE_HEADER_SIZE),
self.responseOptions
conn.responseOptions
),
self
conn
);

@@ -328,3 +328,3 @@ }

var dataHandler = function(self) {
var dataHandler = function(conn) {
return function(data) {

@@ -334,11 +334,11 @@ // Parse until we are done with the data

// If we still have bytes to read on the current message
if (self.bytesRead > 0 && self.sizeOfMessage > 0) {
if (conn.bytesRead > 0 && conn.sizeOfMessage > 0) {
// Calculate the amount of remaining bytes
var remainingBytesToRead = self.sizeOfMessage - self.bytesRead;
var remainingBytesToRead = conn.sizeOfMessage - conn.bytesRead;
// Check if the current chunk contains the rest of the message
if (remainingBytesToRead > data.length) {
// Copy the new data into the exiting buffer (should have been allocated when we know the message size)
data.copy(self.buffer, self.bytesRead);
data.copy(conn.buffer, conn.bytesRead);
// Adjust the number of bytes read so it point to the correct index in the buffer
self.bytesRead = self.bytesRead + data.length;
conn.bytesRead = conn.bytesRead + data.length;

@@ -349,3 +349,3 @@ // Reset state of buffer

// Copy the missing part of the data into our current buffer
data.copy(self.buffer, self.bytesRead, 0, remainingBytesToRead);
data.copy(conn.buffer, conn.bytesRead, 0, remainingBytesToRead);
// Slice the overflow into a new buffer that we will then re-parse

@@ -356,10 +356,10 @@ data = data.slice(remainingBytesToRead);

try {
var emitBuffer = self.buffer;
var emitBuffer = conn.buffer;
// Reset state of buffer
self.buffer = null;
self.sizeOfMessage = 0;
self.bytesRead = 0;
self.stubBuffer = null;
conn.buffer = null;
conn.sizeOfMessage = 0;
conn.bytesRead = 0;
conn.stubBuffer = null;
emitMessageHandler(self, emitBuffer);
emitMessageHandler(conn, emitBuffer);
} catch (err) {

@@ -369,11 +369,11 @@ var errorObject = {

trace: err,
bin: self.buffer,
bin: conn.buffer,
parseState: {
sizeOfMessage: self.sizeOfMessage,
bytesRead: self.bytesRead,
stubBuffer: self.stubBuffer
sizeOfMessage: conn.sizeOfMessage,
bytesRead: conn.bytesRead,
stubBuffer: conn.stubBuffer
}
};
// We got a parse Error fire it off then keep going
self.emit('parseError', errorObject, self);
conn.emit('parseError', errorObject, conn);
}

@@ -384,9 +384,9 @@ }

// size of the message (< 4 bytes)
if (self.stubBuffer != null && self.stubBuffer.length > 0) {
if (conn.stubBuffer != null && conn.stubBuffer.length > 0) {
// If we have enough bytes to determine the message size let's do it
if (self.stubBuffer.length + data.length > 4) {
if (conn.stubBuffer.length + data.length > 4) {
// Prepad the data
var newData = Buffer.alloc(self.stubBuffer.length + data.length);
self.stubBuffer.copy(newData, 0);
data.copy(newData, self.stubBuffer.length);
var newData = Buffer.alloc(conn.stubBuffer.length + data.length);
conn.stubBuffer.copy(newData, 0);
data.copy(newData, conn.stubBuffer.length);
// Reassign for parsing

@@ -396,13 +396,13 @@ data = newData;

// Reset state of buffer
self.buffer = null;
self.sizeOfMessage = 0;
self.bytesRead = 0;
self.stubBuffer = null;
conn.buffer = null;
conn.sizeOfMessage = 0;
conn.bytesRead = 0;
conn.stubBuffer = null;
} else {
// Add the the bytes to the stub buffer
var newStubBuffer = Buffer.alloc(self.stubBuffer.length + data.length);
var newStubBuffer = Buffer.alloc(conn.stubBuffer.length + data.length);
// Copy existing stub buffer
self.stubBuffer.copy(newStubBuffer, 0);
conn.stubBuffer.copy(newStubBuffer, 0);
// Copy missing part of the data
data.copy(newStubBuffer, self.stubBuffer.length);
data.copy(newStubBuffer, conn.stubBuffer.length);
// Exit parsing loop

@@ -417,15 +417,15 @@ data = Buffer.alloc(0);

// If we have a negative sizeOfMessage emit error and return
if (sizeOfMessage < 0 || sizeOfMessage > self.maxBsonMessageSize) {
if (sizeOfMessage < 0 || sizeOfMessage > conn.maxBsonMessageSize) {
errorObject = {
err: 'socketHandler',
trace: '',
bin: self.buffer,
bin: conn.buffer,
parseState: {
sizeOfMessage: sizeOfMessage,
bytesRead: self.bytesRead,
stubBuffer: self.stubBuffer
bytesRead: conn.bytesRead,
stubBuffer: conn.stubBuffer
}
};
// We got a parse Error fire it off then keep going
self.emit('parseError', errorObject, self);
conn.emit('parseError', errorObject, conn);
return;

@@ -437,14 +437,14 @@ }

sizeOfMessage > 4 &&
sizeOfMessage < self.maxBsonMessageSize &&
sizeOfMessage < conn.maxBsonMessageSize &&
sizeOfMessage > data.length
) {
self.buffer = Buffer.alloc(sizeOfMessage);
conn.buffer = Buffer.alloc(sizeOfMessage);
// Copy all the data into the buffer
data.copy(self.buffer, 0);
data.copy(conn.buffer, 0);
// Update bytes read
self.bytesRead = data.length;
conn.bytesRead = data.length;
// Update sizeOfMessage
self.sizeOfMessage = sizeOfMessage;
conn.sizeOfMessage = sizeOfMessage;
// Ensure stub buffer is null
self.stubBuffer = null;
conn.stubBuffer = null;
// Exit parsing loop

@@ -454,3 +454,3 @@ data = Buffer.alloc(0);

sizeOfMessage > 4 &&
sizeOfMessage < self.maxBsonMessageSize &&
sizeOfMessage < conn.maxBsonMessageSize &&
sizeOfMessage === data.length

@@ -461,14 +461,14 @@ ) {

// Reset state of buffer
self.buffer = null;
self.sizeOfMessage = 0;
self.bytesRead = 0;
self.stubBuffer = null;
conn.buffer = null;
conn.sizeOfMessage = 0;
conn.bytesRead = 0;
conn.stubBuffer = null;
// Exit parsing loop
data = Buffer.alloc(0);
// Emit the message
emitMessageHandler(self, emitBuffer);
emitMessageHandler(conn, emitBuffer);
} catch (err) {
self.emit('parseError', err, self);
conn.emit('parseError', err, conn);
}
} else if (sizeOfMessage <= 4 || sizeOfMessage > self.maxBsonMessageSize) {
} else if (sizeOfMessage <= 4 || sizeOfMessage > conn.maxBsonMessageSize) {
errorObject = {

@@ -486,9 +486,9 @@ err: 'socketHandler',

// We got a parse Error fire it off then keep going
self.emit('parseError', errorObject, self);
conn.emit('parseError', errorObject, conn);
// Clear out the state of the parser
self.buffer = null;
self.sizeOfMessage = 0;
self.bytesRead = 0;
self.stubBuffer = null;
conn.buffer = null;
conn.sizeOfMessage = 0;
conn.bytesRead = 0;
conn.stubBuffer = null;
// Exit parsing loop

@@ -499,16 +499,16 @@ data = Buffer.alloc(0);

// Reset state of buffer
self.buffer = null;
self.sizeOfMessage = 0;
self.bytesRead = 0;
self.stubBuffer = null;
conn.buffer = null;
conn.sizeOfMessage = 0;
conn.bytesRead = 0;
conn.stubBuffer = null;
// Copy rest of message
data = data.slice(sizeOfMessage);
// Emit the message
emitMessageHandler(self, emitBuffer);
emitMessageHandler(conn, emitBuffer);
}
} else {
// Create a buffer that contains the space for the non-complete message
self.stubBuffer = Buffer.alloc(data.length);
conn.stubBuffer = Buffer.alloc(data.length);
// Copy the data to the stub buffer
data.copy(self.stubBuffer, 0);
data.copy(conn.stubBuffer, 0);
// Exit parsing loop

@@ -550,93 +550,118 @@ data = Buffer.alloc(0);

function makeSSLConnection(self, _options) {
let sslOptions = {
socket: self.connection,
rejectUnauthorized: self.rejectUnauthorized
};
function prepareConnectionOptions(conn, _options) {
let options;
if (conn.ssl) {
options = {
socket: conn.connection,
rejectUnauthorized: conn.rejectUnauthorized
};
// Merge in options
merge(sslOptions, self.options);
merge(sslOptions, _options);
// Merge in options
merge(options, conn.options);
merge(options, _options);
// Set options for ssl
if (self.ca) sslOptions.ca = self.ca;
if (self.crl) sslOptions.crl = self.crl;
if (self.cert) sslOptions.cert = self.cert;
if (self.key) sslOptions.key = self.key;
if (self.passphrase) sslOptions.passphrase = self.passphrase;
// Set options for ssl
if (conn.ca) options.ca = conn.ca;
if (conn.crl) options.crl = conn.crl;
if (conn.cert) options.cert = conn.cert;
if (conn.key) options.key = conn.key;
if (conn.passphrase) options.passphrase = conn.passphrase;
// Override checkServerIdentity behavior
if (self.checkServerIdentity === false) {
// Skip the identiy check by retuning undefined as per node documents
// https://nodejs.org/api/tls.html#tls_tls_connect_options_callback
sslOptions.checkServerIdentity = function() {
return undefined;
};
} else if (typeof self.checkServerIdentity === 'function') {
sslOptions.checkServerIdentity = self.checkServerIdentity;
}
// Override checkServerIdentity behavior
if (conn.checkServerIdentity === false) {
// Skip the identiy check by returning undefined as per node documents
// https://nodejs.org/api/tls.html#tls_tls_connect_options_callback
options.checkServerIdentity = function() {
return undefined;
};
} else if (typeof conn.checkServerIdentity === 'function') {
options.checkServerIdentity = conn.checkServerIdentity;
}
// Set default sni servername to be the same as host
if (sslOptions.servername == null) {
sslOptions.servername = self.host;
// Set default sni servername to be the same as host
if (options.servername == null) {
options.servername = conn.host;
}
options = Object.assign({}, options, { host: conn.host, port: conn.port });
} else {
if (conn.domainSocket) {
options = { path: conn.host };
} else {
options = { port: conn.port, host: conn.host };
}
}
// Attempt SSL connection
const connection = tls.connect(self.port, self.host, sslOptions, function() {
// Error on auth or skip
if (connection.authorizationError && self.rejectUnauthorized) {
return self.emit('error', connection.authorizationError, self, { ssl: true });
return options;
}
function makeConnection(conn, options, callback) {
const netModule = options.ssl ? tls : net;
const connection = netModule.connect(options, function() {
if (conn.ssl) {
// Error on auth or skip
if (connection.authorizationError && conn.rejectUnauthorized) {
return conn.emit('error', connection.authorizationError, conn, { ssl: true });
}
}
// Set socket timeout instead of connection timeout
// Set socket timeout instead of connection timeout
connection.setTimeout(self.socketTimeout);
// We are done emit connect
self.emit('connect', self);
connection.setTimeout(conn.socketTimeout);
return callback(null, connection);
});
// Set the options for the connection
connection.setKeepAlive(self.keepAlive, self.keepAliveInitialDelay);
connection.setTimeout(self.connectionTimeout);
connection.setNoDelay(self.noDelay);
connection.setKeepAlive(conn.keepAlive, conn.keepAliveInitialDelay);
connection.setTimeout(conn.connectionTimeout);
connection.setNoDelay(conn.noDelay);
return connection;
// Add handlers for events
connection.once('error', err => callback(err, null));
}
function makeUnsecureConnection(self, family) {
// Create new connection instance
let connection_options;
if (self.domainSocket) {
connection_options = { path: self.host };
} else {
connection_options = { port: self.port, host: self.host };
connection_options.family = family;
}
function normalConnect(conn, family, _options, callback) {
const options = prepareConnectionOptions(conn, _options);
makeConnection(conn, Object.assign({ family }, options), (err, connection) => {
if (err) return callback(err, null);
callback(null, connection);
});
}
const connection = net.createConnection(connection_options);
function fastFallbackConnect(conn, _options, callback) {
const options = prepareConnectionOptions(conn, _options);
// Set the options for the connection
connection.setKeepAlive(self.keepAlive, self.keepAliveInitialDelay);
connection.setTimeout(self.connectionTimeout);
connection.setNoDelay(self.noDelay);
let errors = [];
let connection;
const connectionHandler = (err, _connection) => {
if (err) {
if (errors.length > 0) {
// an error occurred for the second time, we have officially failed
// return mongo error to be emitted
return callback(err, null);
}
connection.once('connect', function() {
// Set socket timeout instead of connection timeout
connection.setTimeout(self.socketTimeout);
// Emit connect event
self.emit('connect', self);
});
// otherwise push the error, and wait for subsequent connects
errors.push(err);
return;
}
return connection;
}
if (_connection) {
if (connection) {
_connection.removeAllListeners('error');
_connection.unref();
return;
}
function doConnect(self, family, _options, _errorHandler) {
self.connection = self.ssl
? makeSSLConnection(self, _options)
: makeUnsecureConnection(self, family);
connection = _connection;
return callback(null, connection);
}
};
// Add handlers for events
self.connection.once('error', _errorHandler);
self.connection.once('timeout', timeoutHandler(self));
self.connection.once('close', closeHandler(self));
self.connection.on('data', dataHandler(self));
makeConnection(conn, Object.assign({ family: 6 }, options), connectionHandler);
// IPv4 attempts to connect 250ms after IPv6 to give IPv6 preference
setTimeout(() => {
makeConnection(conn, Object.assign({ family: 4 }, options), connectionHandler);
}, 250);
}

@@ -659,30 +684,25 @@

const _errorHandler = errorHandler(this);
const connectHandler = (err, connection) => {
const connectionErrorHandler = errorHandler(this);
if (err) {
connectionErrorHandler(err);
return;
}
// Add handlers for events
connection.once('error', connectionErrorHandler);
connection.once('timeout', timeoutHandler(this));
connection.once('close', closeHandler(this));
connection.on('data', dataHandler(this));
this.connection = connection;
this.emit('connect', this);
return;
};
if (this.family !== void 0) {
return doConnect(this, this.family, _options, _errorHandler);
return normalConnect(this, this.family, _options, connectHandler);
}
return doConnect(this, 6, _options, err => {
if (this.logger.isDebug()) {
this.logger.debug(
f(
'connection %s for [%s:%s] errored out with [%s]',
this.id,
this.host,
this.port,
JSON.stringify(err)
)
);
}
// clean up existing event handlers
this.connection.removeAllListeners('error');
this.connection.removeAllListeners('timeout');
this.connection.removeAllListeners('close');
this.connection.removeAllListeners('data');
this.connection = undefined;
return doConnect(this, 4, _options, _errorHandler);
});
return fastFallbackConnect(this, _options, connectHandler);
};

@@ -698,5 +718,5 @@

else {
var self = this;
var conn = this;
this.once('connect', function() {
self.connection.unref();
conn.connection.unref();
});

@@ -703,0 +723,0 @@ }

@@ -237,3 +237,3 @@ 'use strict';

parsedOptions = Object.assign({}, parsedOptions, options);
const auth = { username: null, password: null, db: db && db !== '' ? qs.unescape(db) : null };
const auth = { username: null, password: null, db: db && db !== '' ? qs.unescape(db) : 'admin' };
if (cap[4].split('?')[0].indexOf('@') !== -1) {

@@ -240,0 +240,0 @@ return callback(new MongoParseError('Unescaped slash in userinfo section'));

{
"name": "mongodb-core",
"version": "3.1.3",
"version": "3.1.4",
"description": "Core MongoDB driver functionality, no bells and whistles and meant for integration not end applications",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc