Socket
Socket
Sign inDemoInstall

mongodb-build-info

Package Overview
Dependencies
9
Maintainers
9
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.5.0

9

index.js
const { default: ConnectionString } = require('mongodb-connection-string-url');
const ATLAS_REGEX = /\.mongodb(-dev)?\.net$/i;
const LOCALHOST_REGEX = /^(localhost|127\.0\.0\.1|0\.0\.0\.0)$/i;
const LOCALHOST_REGEX = /^(localhost|127\.([01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.([01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.([01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])|0\.0\.0\.0|(?:0*\:)*?:?0*1)$/i;
const DIGITAL_OCEAN_REGEX = /\.mongo\.ondigitalocean\.com$/i;

@@ -34,2 +34,6 @@

function getHostnameFromHost(host) {
if (host.startsWith('[')) {
// If it's ipv6 return what's in the brackets.
return host.substring(1).split(']')[0];
}
return host.split(':')[0];

@@ -45,4 +49,3 @@ }

const connectionString = new ConnectionString(url);
const firstHost = connectionString.hosts[0];
return firstHost.split(':')[0];
return getHostnameFromHost(connectionString.hosts[0]);
} catch (e) {

@@ -49,0 +52,0 @@ // we assume is already an hostname, will further be checked against regexes

{
"name": "mongodb-build-info",
"version": "1.4.0",
"version": "1.5.0",
"description": "Extract information from mongodb's buildInfo",

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

@@ -1,2 +0,2 @@

# mongodb-build-info [![Build Status][azure-url]][azure-img]
# mongodb-build-info

@@ -72,4 +72,1 @@ Helpful functions to figure out if a connection is on Atlas, Atlas Data Lake,

Apache-2.0
[azure-url]: https://dev.azure.com/team-compass/compass/_apis/build/status/mongodb-js.mongodb-build-info?branchName=master
[azure-img]: https://dev.azure.com/team-compass/compass/_build/results?buildId=1457&view=results

@@ -96,2 +96,26 @@ const expect = require('chai').expect;

// Although 127.0.0.1 is usually used for localhost,
// anything in the 127.0.0.1 -> 127.255.255.255 can be used.
it('reports on localhost of type 127.x.x.x', () => {
expect(isLocalhost('127.0.100.1:27019')).to.be.true;
expect(isLocalhost('127.250.100.250:27019')).to.be.true;
expect(isLocalhost('127.10.0.0:27019')).to.be.true;
});
// IPv6 loopback addresses.
it('reports on localhost of type [::1]', () => {
expect(isLocalhost('[::1]')).to.be.true;
expect(isLocalhost('mongodb://[::1]/?readPreference=secondary')).to.be.true;
expect(isLocalhost('[0000:0000:0000:0000:0000:0000:0000:0001]')).to.be.true;
expect(isLocalhost('[0:0:0:0:0:0:0:1]')).to.be.true;
expect(isLocalhost('[0::1]')).to.be.true;
expect(isLocalhost('[::1]:27019')).to.be.true;
expect(isLocalhost('[0:0:0:0:0:0:0:1]:27019')).to.be.true;
expect(isLocalhost('[0::1]:27019')).to.be.true;
});
it('reports on localhost of type 0.0.0.0', () => {
expect(isLocalhost('0.0.0.0:27019')).to.be.true;
});
it('works as url', () => {

@@ -113,6 +137,11 @@ expect(isLocalhost('mongodb://127.0.0.1:27019')).to.be.true;

it('does not report if localhost or 127.0.0.1 is not the hostname', () => {
expect(isLocalhost('127.0.0.2')).to.be.false;
expect(isLocalhost('127.0.0.500')).to.be.false;
expect(isLocalhost('128.0.0.2')).to.be.false;
expect(isLocalhost('0.0.0.1')).to.be.false;
expect(isLocalhost('remotehost')).to.be.false;
expect(isLocalhost('mongodb://remotelocalhost')).to.be.false;
expect(isLocalhost('[test:ipv6::1]')).to.be.false;
expect(isLocalhost('[1:0:0:0:0:0:0:1]')).to.be.false;
expect(isLocalhost('[test:ipv6::1]:27019')).to.be.false;
expect(isLocalhost('[1:0:0:0:0:0:0:1]:27019')).to.be.false;
});

@@ -119,0 +148,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc