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

@mongodb-js/ssh-tunnel

Package Overview
Dependencies
Maintainers
33
Versions
432
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mongodb-js/ssh-tunnel - npm Package Compare versions

Comparing version 0.0.0-next-084f1c20551b15b25b3945fae7547f5321bc4128 to 0.0.0-next-0acfcb0d2533f0282b45e2bc24bdfb571d3dc797

1

dist/index.d.ts

@@ -22,2 +22,3 @@ /// <reference types="node" />

private forwardOut;
private logCtx;
constructor(config?: Partial<SshTunnelConfig>);

@@ -24,0 +25,0 @@ get config(): SshTunnelConfig;

61

dist/index.js

@@ -10,7 +10,7 @@ "use strict";

const ssh2_1 = require("ssh2");
const debug_1 = __importDefault(require("debug"));
const compass_logging_1 = require("@mongodb-js/compass-logging");
const server_1 = __importDefault(require("socksv5/lib/server"));
const None_1 = __importDefault(require("socksv5/lib/auth/None"));
const UserPassword_1 = __importDefault(require("socksv5/lib/auth/UserPassword"));
const debug = (0, debug_1.default)('mongodb:ssh-tunnel');
const { log, mongoLogId, debug } = (0, compass_logging_1.createLoggerAndTelemetry)('COMPASS-SSH-TUNNEL');
function getConnectConfig(config) {

@@ -29,2 +29,3 @@ const { localAddr, localPort, socks5Password, socks5Username, ...connectConfig } = config;

}
let idCounter = 0;
class SshTunnel extends events_1.EventEmitter {

@@ -36,6 +37,7 @@ constructor(config = {}) {

this.connections = new Set();
this.logCtx = `tunnel-${idCounter++}`;
this.rawConfig = getSshTunnelConfig(config);
this.sshClient = new ssh2_1.Client();
this.sshClient.on('close', () => {
debug('sshClient closed');
log.info(mongoLogId(1001000252), this.logCtx, 'sshClient closed');
this.connected = false;

@@ -49,8 +51,8 @@ });

this.rawConfig.socks5Password === pass;
debug('validating auth parameters', success);
process.nextTick(cb, success);
log.info(mongoLogId(1001000253), this.logCtx, 'Validated auth parameters', { success });
queueMicrotask(() => cb(success));
}));
}
else {
debug('skipping auth setup for this server');
log.info(mongoLogId(1001000254), this.logCtx, 'Skipping auth setup');
this.server.useAuth((0, None_1.default)());

@@ -74,3 +76,3 @@ }

const { localPort, localAddr } = this.rawConfig;
debug('starting to listen', { localAddr, localPort });
log.info(mongoLogId(1001000255), this.logCtx, 'Listening for Socks5 connections', { localAddr, localPort });
await this.serverListen(localPort, localAddr);

@@ -80,3 +82,3 @@ await this.connectSsh();

async close() {
debug('closing SSH tunnel');
log.info(mongoLogId(1001000256), this.logCtx, 'Closing SSH tunnel');
const [maybeError] = await Promise.all([

@@ -103,3 +105,3 @@ this.serverClose().catch((e) => e),

}
debug('creating SSH connection');
log.info(mongoLogId(1001000257), this.logCtx, 'Establishing new SSH connection');
this.connectingPromise = Promise.race([

@@ -119,3 +121,4 @@ (0, events_1.once)(this.sshClient, 'error').then(([err]) => {

catch (err) {
debug('failed to establish SSH connection', err);
this.emit('forwardingError', err);
log.error(mongoLogId(1001000258), this.logCtx, 'Failed to establish new SSH connection', { error: err?.stack ?? String(err) });
delete this.connectingPromise;

@@ -127,3 +130,3 @@ await this.serverClose();

this.connected = true;
debug('created SSH connection');
log.info(mongoLogId(1001000259), this.logCtx, 'Finished establishing new SSH connection');
}

@@ -149,3 +152,7 @@ async closeSshClient() {

async socks5Request(info, accept, deny) {
debug('receiving socks5 forwarding request', info);
const { srcAddr, srcPort, dstAddr, dstPort } = info;
const logMetadata = { srcAddr, srcPort, dstAddr, dstPort };
log.info(mongoLogId(1001000260), this.logCtx, 'Received Socks5 fowarding request', {
...logMetadata,
});
let socket = null;

@@ -156,3 +163,3 @@ try {

try {
channel = await this.forwardOut(info.srcAddr, info.srcPort, info.dstAddr, info.dstPort);
channel = await this.forwardOut(srcAddr, srcPort, dstAddr, dstPort);
}

@@ -162,5 +169,8 @@ catch (err) {

this.connected = false;
debug('error forwarding. retrying..', info, err);
log.error(mongoLogId(1001000261), this.logCtx, 'Error forwarding Socks5 request, retrying', {
...logMetadata,
error: err.stack,
});
await this.connectSsh();
channel = await this.forwardOut(info.srcAddr, info.srcPort, info.dstAddr, info.dstPort);
channel = await this.forwardOut(srcAddr, srcPort, dstAddr, dstPort);
}

@@ -171,12 +181,19 @@ else {

}
debug('channel opened, accepting socks5 request', info);
log.info(mongoLogId(1001000262), this.logCtx, 'Opened SSH channel and accepting socks5 request', {
...logMetadata,
});
socket = accept(true);
this.connections.add(socket);
socket.on('error', (err) => {
debug('error on socksv5 socket', info, err);
log.error(mongoLogId(1001000263), this.logCtx, 'Error on Socks5 stream socket', {
...logMetadata,
error: err.stack,
});
err.origin = err.origin ?? 'connection';
this.server.emit('error', err);
this.emit('forwardingError', err);
});
socket.once('close', () => {
debug('socksv5 socket closed, removing from set');
log.info(mongoLogId(1001000264), this.logCtx, 'Socks5 stream socket closed', {
...logMetadata,
});
this.connections.delete(socket);

@@ -187,3 +204,7 @@ });

catch (err) {
debug('caught error, rejecting socks5 request', info, err);
this.emit('forwardingError', err);
log.error(mongoLogId(1001000265), this.logCtx, 'Error establishing SSH channel for Socks5 request', {
...logMetadata,
error: err.stack,
});
deny();

@@ -190,0 +211,0 @@ if (socket) {

@@ -16,3 +16,3 @@ {

"homepage": "https://github.com/mongodb-js/compass",
"version": "0.0.0-next-084f1c20551b15b25b3945fae7547f5321bc4128",
"version": "0.0.0-next-0acfcb0d2533f0282b45e2bc24bdfb571d3dc797",
"repository": {

@@ -43,3 +43,3 @@ "type": "git",

"lint": "npm run eslint . && npm run prettier -- --check .",
"depcheck": "depcheck",
"depcheck": "compass-scripts check-peer-deps && depcheck",
"check": "npm run lint && npm run depcheck",

@@ -51,14 +51,13 @@ "check-ci": "npm run check",

"test-ci": "npm run test-cov",
"reformat": "npm run prettier -- --write . && npm run eslint . --fix"
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write ."
},
"devDependencies": {
"@mongodb-js/eslint-config-compass": "0.0.0-next-084f1c20551b15b25b3945fae7547f5321bc4128",
"@mongodb-js/mocha-config-compass": "0.0.0-next-084f1c20551b15b25b3945fae7547f5321bc4128",
"@mongodb-js/prettier-config-compass": "0.0.0-next-084f1c20551b15b25b3945fae7547f5321bc4128",
"@mongodb-js/tsconfig-compass": "0.0.0-next-084f1c20551b15b25b3945fae7547f5321bc4128",
"@mongodb-js/eslint-config-compass": "0.0.0-next-0acfcb0d2533f0282b45e2bc24bdfb571d3dc797",
"@mongodb-js/mocha-config-compass": "0.0.0-next-0acfcb0d2533f0282b45e2bc24bdfb571d3dc797",
"@mongodb-js/prettier-config-compass": "0.0.0-next-0acfcb0d2533f0282b45e2bc24bdfb571d3dc797",
"@mongodb-js/tsconfig-compass": "0.0.0-next-0acfcb0d2533f0282b45e2bc24bdfb571d3dc797",
"@types/chai": "^4.2.21",
"@types/chai-as-promised": "^7.1.4",
"@types/debug": "^4.1.7",
"@types/mocha": "^9.0.0",
"@types/node-fetch": "^2.5.8",
"@types/node-fetch": "^2.6.11",
"@types/sinon-chai": "^3.2.5",

@@ -72,15 +71,15 @@ "@types/ssh2": "^1.11.8",

"mocha": "^10.2.0",
"node-fetch": "^2.6.7",
"node-fetch": "^2.7.0",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"sinon": "^9.2.3",
"socks": "^2.6.1",
"socks": "^2.7.3",
"typescript": "^5.0.4"
},
"dependencies": {
"debug": "^4.2.0",
"@mongodb-js/compass-logging": "0.0.0-next-0acfcb0d2533f0282b45e2bc24bdfb571d3dc797",
"socksv5": "0.0.6",
"ssh2": "^1.12.0"
},
"gitHead": "084f1c20551b15b25b3945fae7547f5321bc4128"
"gitHead": "0acfcb0d2533f0282b45e2bc24bdfb571d3dc797"
}

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