Huge News!Announcing our $40M Series B led by Abstract Ventures.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-bb1a39e78c30cda5ef910174e54d2c9708186388 to 0.0.0-next-bc37cfc07b82d66ae76a8abc7104e13cc84c22eb

5

dist/index.d.ts
/// <reference types="node" />
import { EventEmitter } from 'events';
import type { ConnectConfig } from 'ssh2';
declare type LocalProxyServerConfig = {
type LocalProxyServerConfig = {
localAddr: string;

@@ -10,3 +10,3 @@ localPort: number;

};
export declare type SshTunnelConfig = ConnectConfig & LocalProxyServerConfig;
export type SshTunnelConfig = ConnectConfig & LocalProxyServerConfig;
export declare class SshTunnel extends EventEmitter {

@@ -23,2 +23,3 @@ private connected;

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

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

66

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.createLogger)('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)());

@@ -68,3 +70,3 @@ }

...this.rawConfig,
localPort: (typeof serverAddress !== 'string' && (serverAddress === null || serverAddress === void 0 ? void 0 : serverAddress.port)) ||
localPort: (typeof serverAddress !== 'string' && serverAddress?.port) ||
this.rawConfig.localPort,

@@ -75,3 +77,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);

@@ -81,3 +83,3 @@ await this.connectSsh();

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

@@ -104,3 +106,3 @@ this.serverClose().catch((e) => e),

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

@@ -120,3 +122,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;

@@ -128,3 +131,3 @@ await this.serverClose();

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

@@ -150,3 +153,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;

@@ -157,3 +164,3 @@ try {

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

@@ -163,5 +170,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);
}

@@ -172,13 +182,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) => {
var _a;
debug('error on socksv5 socket', info, err);
err.origin = (_a = err.origin) !== null && _a !== void 0 ? _a : 'connection';
this.server.emit('error', err);
log.error(mongoLogId(1001000263), this.logCtx, 'Error on Socks5 stream socket', {
...logMetadata,
error: err.stack,
});
err.origin = err.origin ?? 'connection';
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);

@@ -189,3 +205,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();

@@ -192,0 +212,0 @@ if (socket) {

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

"homepage": "https://github.com/mongodb-js/compass",
"version": "0.0.0-next-bb1a39e78c30cda5ef910174e54d2c9708186388",
"version": "0.0.0-next-bc37cfc07b82d66ae76a8abc7104e13cc84c22eb",
"repository": {

@@ -43,23 +43,22 @@ "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",
"check-ci": "npm run check",
"test": "mocha",
"test-cov": "nyc -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test",
"test-cov": "nyc --compact=false --produce-source-map=false -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test",
"test-watch": "npm run test -- --watch",
"test-ci": "npm run test-cov",
"reformat": "npm run prettier -- --write ."
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write ."
},
"devDependencies": {
"@mongodb-js/eslint-config-compass": "0.0.0-next-bb1a39e78c30cda5ef910174e54d2c9708186388",
"@mongodb-js/mocha-config-compass": "0.0.0-next-bb1a39e78c30cda5ef910174e54d2c9708186388",
"@mongodb-js/prettier-config-compass": "0.0.0-next-bb1a39e78c30cda5ef910174e54d2c9708186388",
"@mongodb-js/tsconfig-compass": "0.0.0-next-bb1a39e78c30cda5ef910174e54d2c9708186388",
"@mongodb-js/eslint-config-compass": "0.0.0-next-bc37cfc07b82d66ae76a8abc7104e13cc84c22eb",
"@mongodb-js/mocha-config-compass": "0.0.0-next-bc37cfc07b82d66ae76a8abc7104e13cc84c22eb",
"@mongodb-js/prettier-config-compass": "0.0.0-next-bc37cfc07b82d66ae76a8abc7104e13cc84c22eb",
"@mongodb-js/tsconfig-compass": "0.0.0-next-bc37cfc07b82d66ae76a8abc7104e13cc84c22eb",
"@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",
"@types/ssh2": "^0.5.46",
"@types/ssh2": "^1.11.8",
"chai": "^4.3.4",

@@ -70,16 +69,16 @@ "chai-as-promised": "^7.1.1",

"gen-esm-wrapper": "^1.1.0",
"mocha": "^8.4.0",
"node-fetch": "^2.6.1",
"mocha": "^10.2.0",
"node-fetch": "^2.7.0",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"sinon": "^9.2.3",
"socks": "^2.6.1",
"typescript": "^4.8.3"
"socks": "^2.7.3",
"typescript": "^5.0.4"
},
"dependencies": {
"debug": "^4.2.0",
"@mongodb-js/compass-logging": "0.0.0-next-bc37cfc07b82d66ae76a8abc7104e13cc84c22eb",
"socksv5": "0.0.6",
"ssh2": "^0.8.9"
"ssh2": "^1.12.0"
},
"gitHead": "bb1a39e78c30cda5ef910174e54d2c9708186388"
"gitHead": "bc37cfc07b82d66ae76a8abc7104e13cc84c22eb"
}

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