New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongodb

Package Overview
Dependencies
Maintainers
8
Versions
622
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb - npm Package Compare versions

Comparing version 6.9.0-dev.20241015.sha.7fde8ddc to 6.9.0-dev.20241016.sha.3d5bd513

8

lib/connection_string.js

@@ -37,6 +37,2 @@ "use strict";

}
if (options.srvHost.split('.').length < 3) {
// TODO(NODE-3484): Replace with MongoConnectionStringError
throw new error_1.MongoAPIError('URI must include hostname, domain name, and tld');
}
// Asynchronously start TXT resolution so that we do not have to wait until

@@ -53,5 +49,3 @@ // the SRV record is resolved before starting a second DNS query.

for (const { name } of addresses) {
if (!(0, utils_1.matchesParentDomain)(name, lookupAddress)) {
throw new error_1.MongoAPIError('Server record does not share hostname with parent URI');
}
(0, utils_1.checkParentDomainMatch)(name, lookupAddress);
}

@@ -58,0 +52,0 @@ const hostAddresses = addresses.map(r => utils_1.HostAddress.fromString(`${r.name}:${r.port ?? 27017}`));

6

lib/sdam/srv_polling.js

@@ -89,5 +89,9 @@ "use strict";

for (const record of srvRecords) {
if ((0, utils_1.matchesParentDomain)(record.name, this.srvHost)) {
try {
(0, utils_1.checkParentDomainMatch)(record.name, this.srvHost);
finalAddresses.push(record);
}
catch (error) {
(0, utils_1.squashError)(error);
}
}

@@ -94,0 +98,0 @@ if (!finalAddresses.length) {

@@ -41,3 +41,3 @@ "use strict";

exports.parseUnsignedInteger = parseUnsignedInteger;
exports.matchesParentDomain = matchesParentDomain;
exports.checkParentDomainMatch = checkParentDomainMatch;
exports.get = get;

@@ -930,3 +930,5 @@ exports.request = request;

/**
* Determines whether a provided address matches the provided parent domain.
* This function throws a MongoAPIError in the event that either of the following is true:
* * If the provided address domain does not match the provided parent domain
* * If the parent domain contains less than three `.` separated parts and the provided address does not contain at least one more domain level than its parent
*

@@ -938,5 +940,5 @@ * If a DNS server were to become compromised SRV records would still need to

* @param srvHost - The domain to check the provided address against
* @returns Whether the provided address matches the parent domain
* @returns void
*/
function matchesParentDomain(address, srvHost) {
function checkParentDomainMatch(address, srvHost) {
// Remove trailing dot if exists on either the resolved address or the srv hostname

@@ -946,2 +948,3 @@ const normalizedAddress = address.endsWith('.') ? address.slice(0, address.length - 1) : address;

const allCharacterBeforeFirstDot = /^.*?\./;
const srvIsLessThanThreeParts = normalizedSrvHost.split('.').length < 3;
// Remove all characters before first dot

@@ -952,4 +955,15 @@ // Add leading dot back to string so

const addressDomain = `.${normalizedAddress.replace(allCharacterBeforeFirstDot, '')}`;
const srvHostDomain = `.${normalizedSrvHost.replace(allCharacterBeforeFirstDot, '')}`;
return addressDomain.endsWith(srvHostDomain);
let srvHostDomain = srvIsLessThanThreeParts
? normalizedSrvHost
: `.${normalizedSrvHost.replace(allCharacterBeforeFirstDot, '')}`;
if (!srvHostDomain.startsWith('.')) {
srvHostDomain = '.' + srvHostDomain;
}
if (srvIsLessThanThreeParts &&
normalizedAddress.split('.').length <= normalizedSrvHost.split('.').length) {
throw new error_1.MongoAPIError('Server record does not have at least one more domain level than parent URI');
}
if (!addressDomain.endsWith(srvHostDomain)) {
throw new error_1.MongoAPIError('Server record does not share hostname with parent URI');
}
}

@@ -956,0 +970,0 @@ /**

{
"name": "mongodb",
"version": "6.9.0-dev.20241015.sha.7fde8ddc",
"version": "6.9.0-dev.20241016.sha.3d5bd513",
"description": "The official MongoDB driver for Node.js",

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

@@ -37,2 +37,3 @@ import * as dns from 'dns';

import {
checkParentDomainMatch,
DEFAULT_PK_FACTORY,

@@ -42,3 +43,2 @@ emitWarning,

isRecord,
matchesParentDomain,
parseInteger,

@@ -69,7 +69,2 @@ setDifference,

if (options.srvHost.split('.').length < 3) {
// TODO(NODE-3484): Replace with MongoConnectionStringError
throw new MongoAPIError('URI must include hostname, domain name, and tld');
}
// Asynchronously start TXT resolution so that we do not have to wait until

@@ -92,5 +87,3 @@ // the SRV record is resolved before starting a second DNS query.

for (const { name } of addresses) {
if (!matchesParentDomain(name, lookupAddress)) {
throw new MongoAPIError('Server record does not share hostname with parent URI');
}
checkParentDomainMatch(name, lookupAddress);
}

@@ -97,0 +90,0 @@

@@ -6,3 +6,3 @@ import * as dns from 'dns';

import { TypedEventEmitter } from '../mongo_types';
import { HostAddress, matchesParentDomain, squashError } from '../utils';
import { checkParentDomainMatch, HostAddress, squashError } from '../utils';

@@ -131,4 +131,7 @@ /**

for (const record of srvRecords) {
if (matchesParentDomain(record.name, this.srvHost)) {
try {
checkParentDomainMatch(record.name, this.srvHost);
finalAddresses.push(record);
} catch (error) {
squashError(error);
}

@@ -135,0 +138,0 @@ }

@@ -21,2 +21,3 @@ import * as crypto from 'crypto';

type AnyError,
MongoAPIError,
MongoCompatibilityError,

@@ -1146,3 +1147,5 @@ MongoInvalidArgumentError,

/**
* Determines whether a provided address matches the provided parent domain.
* This function throws a MongoAPIError in the event that either of the following is true:
* * If the provided address domain does not match the provided parent domain
* * If the parent domain contains less than three `.` separated parts and the provided address does not contain at least one more domain level than its parent
*

@@ -1154,5 +1157,5 @@ * If a DNS server were to become compromised SRV records would still need to

* @param srvHost - The domain to check the provided address against
* @returns Whether the provided address matches the parent domain
* @returns void
*/
export function matchesParentDomain(address: string, srvHost: string): boolean {
export function checkParentDomainMatch(address: string, srvHost: string): void {
// Remove trailing dot if exists on either the resolved address or the srv hostname

@@ -1163,2 +1166,3 @@ const normalizedAddress = address.endsWith('.') ? address.slice(0, address.length - 1) : address;

const allCharacterBeforeFirstDot = /^.*?\./;
const srvIsLessThanThreeParts = normalizedSrvHost.split('.').length < 3;
// Remove all characters before first dot

@@ -1169,5 +1173,20 @@ // Add leading dot back to string so

const addressDomain = `.${normalizedAddress.replace(allCharacterBeforeFirstDot, '')}`;
const srvHostDomain = `.${normalizedSrvHost.replace(allCharacterBeforeFirstDot, '')}`;
let srvHostDomain = srvIsLessThanThreeParts
? normalizedSrvHost
: `.${normalizedSrvHost.replace(allCharacterBeforeFirstDot, '')}`;
return addressDomain.endsWith(srvHostDomain);
if (!srvHostDomain.startsWith('.')) {
srvHostDomain = '.' + srvHostDomain;
}
if (
srvIsLessThanThreeParts &&
normalizedAddress.split('.').length <= normalizedSrvHost.split('.').length
) {
throw new MongoAPIError(
'Server record does not have at least one more domain level than parent URI'
);
}
if (!addressDomain.endsWith(srvHostDomain)) {
throw new MongoAPIError('Server record does not share hostname with parent URI');
}
}

@@ -1174,0 +1193,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc