Socket
Socket
Sign inDemoInstall

node-pty

Package Overview
Dependencies
Maintainers
2
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-pty - npm Package Compare versions

Comparing version 0.11.0-beta2 to 0.11.0-beta20

src/unix/comms.h

3

lib/terminal.js

@@ -174,2 +174,5 @@ "use strict";

for (var i = 0; i < keys.length; i++) {
if (keys[i] === undefined) {
continue;
}
pairs.push(keys[i] + '=' + env[keys[i]]);

@@ -176,0 +179,0 @@ }

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

var net = require("net");
var path = require("path");
var terminal_1 = require("./terminal");
var utils_1 = require("./utils");
var pty;
var helperPath;
try {
pty = require('../build/Release/pty.node');
helperPath = '../build/Release/spawn-helper';
}

@@ -33,2 +36,3 @@ catch (outerError) {

pty = require('../build/Debug/pty.node');
helperPath = '../build/Debug/spawn-helper';
}

@@ -41,2 +45,5 @@ catch (innerError) {

}
helperPath = path.resolve(__dirname, helperPath);
helperPath = helperPath.replace('app.asar', 'app.asar.unpacked');
helperPath = helperPath.replace('node_modules.asar', 'node_modules.asar.unpacked');
var DEFAULT_FILE = 'sh';

@@ -48,2 +55,3 @@ var DEFAULT_NAME = 'xterm';

function UnixTerminal(file, args, opt) {
var _a, _b;
var _this = _super.call(this, opt) || this;

@@ -60,4 +68,5 @@ if (typeof args === 'string') {

_this._rows = opt.rows || terminal_1.DEFAULT_ROWS;
var uid = opt.uid || -1;
var gid = opt.gid || -1;
var uid = (_a = opt.uid) !== null && _a !== void 0 ? _a : -1;
var gid = (_b = opt.gid) !== null && _b !== void 0 ? _b : -1;
var closeFDs = opt.closeFDs || false;
var env = utils_1.assign({}, opt.env);

@@ -100,3 +109,3 @@ if (opt.env === process.env) {

// fork
var term = pty.fork(file, args, parsedEnv, cwd, _this._cols, _this._rows, uid, gid, (encoding === 'utf8'), onexit);
var term = pty.fork(file, args, parsedEnv, cwd, _this._cols, _this._rows, uid, gid, (encoding === 'utf8'), closeFDs, onexit, helperPath);
_this._socket = new PipeSocket(term.fd);

@@ -166,2 +175,13 @@ if (encoding !== null) {

};
Object.defineProperty(UnixTerminal.prototype, "fd", {
/* Accessors */
get: function () { return this._fd; },
enumerable: false,
configurable: true
});
Object.defineProperty(UnixTerminal.prototype, "ptsName", {
get: function () { return this._pty; },
enumerable: false,
configurable: true
});
/**

@@ -168,0 +188,0 @@ * openpty

@@ -11,2 +11,4 @@ "use strict";

var path = require("path");
var tty = require("tty");
var os_1 = require("os");
var testUtils_test_1 = require("./testUtils.test");

@@ -29,4 +31,5 @@ var FIXTURES_PATH = path.normalize(path.join(__dirname, '..', 'fixtures', 'utf8-character.txt'));

if (regExp) {
assert.ok(regExp.test(term._pty), '"' + term._pty + '" should match ' + regExp.toString());
assert.ok(regExp.test(term.ptsName), '"' + term.ptsName + '" should match ' + regExp.toString());
}
assert.ok(tty.isatty(term.fd));
});

@@ -100,2 +103,13 @@ });

});
describe('close', function () {
var term = new unixTerminal_1.UnixTerminal('node');
it('should exit when terminal is destroyed programmatically', function (done) {
term.on('exit', function (code, signal) {
assert.strictEqual(code, 0);
assert.strictEqual(signal, os_1.constants.signals.SIGHUP);
done();
});
term.destroy();
});
});
describe('signals in parent and child', function () {

@@ -202,4 +216,35 @@ it('SIGINT - custom in parent and child', function (done) {

});
describe('spawn', function () {
it('should handle exec() errors', function (done) {
try {
new unixTerminal_1.UnixTerminal('/bin/bogus.exe', []);
done(new Error('should have failed'));
}
catch (_a) {
done();
}
});
it('should handle chdir() errors', function (done) {
try {
new unixTerminal_1.UnixTerminal('/bin/echo', [], { cwd: '/nowhere' });
done(new Error('should have failed'));
}
catch (e) {
assert.equal(e.toString(), 'Error: chdir() failed: No such file or directory');
done();
}
});
it('should handle setuid() errors', function (done) {
try {
new unixTerminal_1.UnixTerminal('/bin/echo', [], { uid: 999999 });
done(new Error('should have failed'));
}
catch (e) {
assert.equal(e.toString(), 'Error: setuid() failed: Operation not permitted');
done();
}
});
});
});
}
//# sourceMappingURL=unixTerminal.test.js.map

3

lib/windowsConoutConnection.js

@@ -72,3 +72,4 @@ "use strict";

var workerData = { conoutPipeName: _conoutPipeName };
this._worker = new worker_threads_1.Worker(path_1.join(__dirname, 'worker/conoutSocketWorker.js'), { workerData: workerData });
var scriptPath = __dirname.replace('node_modules.asar', 'node_modules.asar.unpacked');
this._worker = new worker_threads_1.Worker(path_1.join(scriptPath, 'worker/conoutSocketWorker.js'), { workerData: workerData });
this._worker.on('message', function (message) {

@@ -75,0 +76,0 @@ switch (message) {

@@ -7,3 +7,3 @@ {

},
"version": "0.11.0-beta2",
"version": "0.11.0-beta20",
"license": "MIT",

@@ -14,3 +14,3 @@ "main": "./lib/index.js",

"type": "git",
"url": "git://github.com/Tyriar/node-pty.git"
"url": "git://github.com/microsoft/node-pty.git"
},

@@ -25,5 +25,5 @@ "files": [

],
"homepage": "https://github.com/Tyriar/node-pty",
"homepage": "https://github.com/microsoft/node-pty",
"bugs": {
"url": "https://github.com/Tyriar/node-pty/issues"
"url": "https://github.com/microsoft/node-pty/issues"
},

@@ -62,3 +62,6 @@ "keywords": [

"typescript": "^3.8.3"
},
"peerDependencies": {
"node-gyp": "^8.3.0"
}
}
# node-pty
[![Build Status](https://dev.azure.com/vscode/node-pty/_apis/build/status/Microsoft.node-pty)](https://dev.azure.com/vscode/node-pty/_build/latest?definitionId=11)
[![Build Status](https://dev.azure.com/vscode/node-pty/_apis/build/status/Microsoft.node-pty?branchName=main)](https://dev.azure.com/vscode/node-pty/_build/latest?definitionId=11&branchName=main)

@@ -66,2 +66,6 @@ `forkpty(3)` bindings for node.js. This allows you to fork processes with pseudoterminal file descriptors. It returns a terminal object which allows reads and writes.

- [ENiGMA½ BBS Software](https://github.com/NuSkooler/enigma-bbs): A modern BBS software with a nostalgic flair!
- [Tinkerun](https://github.com/tinkerun/tinkerun): A new way of running Tinker.
- [Tess](https://tessapp.dev): Hackable, simple and rapid terminal for the new era of technology 👍
- [NxShell](https://nxshell.github.io/): An easy to use new terminal for Windows/Linux/MacOS platform.
- [OpenSumi](https://github.com/opensumi/core): A framework helps you quickly build Cloud or Desktop IDE products.

@@ -68,0 +72,0 @@ Do you use node-pty in your application as well? Please open a [Pull Request](https://github.com/Tyriar/node-pty/pulls) to include it here. We would love to have it in our list.

@@ -12,2 +12,3 @@ var fs = require('fs');

path.join(RELEASE_DIR, 'pty.pdb'),
path.join(RELEASE_DIR, 'spawn-helper'),
path.join(RELEASE_DIR, 'winpty-agent.exe'),

@@ -14,0 +15,0 @@ path.join(RELEASE_DIR, 'winpty-agent.pdb'),

@@ -6,6 +6,4 @@ /**

import * as net from 'net';
export interface IProcessEnv {
[key: string]: string;
[key: string]: string | undefined;
}

@@ -105,3 +103,3 @@

cwd?: string;
env?: { [key: string]: string };
env?: IProcessEnv;
encoding?: string;

@@ -116,2 +114,3 @@ handleFlowControl?: boolean;

gid?: number;
closeFDs?: boolean;
}

@@ -118,0 +117,0 @@

@@ -21,3 +21,3 @@ /**

interface IUnixNative {
fork(file: string, args: string[], parsedEnv: string[], cwd: string, cols: number, rows: number, uid: number, gid: number, useUtf8: boolean, onExitCallback: (code: number, signal: number) => void): IUnixProcess;
fork(file: string, args: string[], parsedEnv: string[], cwd: string, cols: number, rows: number, uid: number, gid: number, closeFDs: boolean, useUtf8: boolean, onExitCallback: (code: number, signal: number) => void, helperPath: string): IUnixProcess;
open(cols: number, rows: number): IUnixOpenProcess;

@@ -24,0 +24,0 @@ process(fd: number, pty: string): string;

@@ -202,2 +202,5 @@ /**

for (let i = 0; i < keys.length; i++) {
if (keys[i] === undefined) {
continue;
}
pairs.push(keys[i] + '=' + env[keys[i]]);

@@ -204,0 +207,0 @@ }

@@ -10,2 +10,4 @@ /**

import * as path from 'path';
import * as tty from 'tty';
import { constants } from 'os';
import { pollUntil } from './testUtils.test';

@@ -30,4 +32,5 @@

if (regExp) {
assert.ok(regExp.test((<any>term)._pty), '"' + (<any>term)._pty + '" should match ' + regExp.toString());
assert.ok(regExp.test(term.ptsName), '"' + term.ptsName + '" should match ' + regExp.toString());
}
assert.ok(tty.isatty(term.fd));
});

@@ -109,2 +112,13 @@ });

});
describe('close', () => {
const term = new UnixTerminal('node');
it('should exit when terminal is destroyed programmatically', (done) => {
term.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, constants.signals.SIGHUP);
done();
});
term.destroy();
});
});
describe('signals in parent and child', () => {

@@ -245,3 +259,31 @@ it('SIGINT - custom in parent and child', done => {

});
describe('spawn', () => {
it('should handle exec() errors', (done) => {
try {
new UnixTerminal('/bin/bogus.exe', []);
done(new Error('should have failed'));
} catch {
done();
}
});
it('should handle chdir() errors', (done) => {
try {
new UnixTerminal('/bin/echo', [], { cwd: '/nowhere' });
done(new Error('should have failed'));
} catch (e) {
assert.equal(e.toString(), 'Error: chdir() failed: No such file or directory');
done();
}
});
it('should handle setuid() errors', (done) => {
try {
new UnixTerminal('/bin/echo', [], { uid: 999999 });
done(new Error('should have failed'));
} catch (e) {
assert.equal(e.toString(), 'Error: setuid() failed: Operation not permitted');
done();
}
});
});
});
}

@@ -7,2 +7,3 @@ /**

import * as net from 'net';
import * as path from 'path';
import { Terminal, DEFAULT_COLS, DEFAULT_ROWS } from './terminal';

@@ -14,7 +15,10 @@ import { IProcessEnv, IPtyForkOptions, IPtyOpenOptions } from './interfaces';

let pty: IUnixNative;
let helperPath: string;
try {
pty = require('../build/Release/pty.node');
helperPath = '../build/Release/spawn-helper';
} catch (outerError) {
try {
pty = require('../build/Debug/pty.node');
helperPath = '../build/Debug/spawn-helper';
} catch (innerError) {

@@ -27,2 +31,6 @@ console.error('innerError', innerError);

helperPath = path.resolve(__dirname, helperPath);
helperPath = helperPath.replace('app.asar', 'app.asar.unpacked');
helperPath = helperPath.replace('node_modules.asar', 'node_modules.asar.unpacked');
const DEFAULT_FILE = 'sh';

@@ -65,5 +73,6 @@ const DEFAULT_NAME = 'xterm';

this._rows = opt.rows || DEFAULT_ROWS;
const uid = opt.uid || -1;
const gid = opt.gid || -1;
const env = assign({}, opt.env);
const uid = opt.uid ?? -1;
const gid = opt.gid ?? -1;
const closeFDs = opt.closeFDs || false;
const env: IProcessEnv = assign({}, opt.env);

@@ -110,3 +119,3 @@ if (opt.env === process.env) {

// fork
const term = pty.fork(file, args, parsedEnv, cwd, this._cols, this._rows, uid, gid, (encoding === 'utf8'), onexit);
const term = pty.fork(file, args, parsedEnv, cwd, this._cols, this._rows, uid, gid, (encoding === 'utf8'), closeFDs, onexit, helperPath);

@@ -177,2 +186,6 @@ this._socket = new PipeSocket(term.fd);

/* Accessors */
get fd(): number { return this._fd; }
get ptsName(): string { return this._pty; }
/**

@@ -179,0 +192,0 @@ * openpty

@@ -43,3 +43,4 @@ /**

const workerData: IWorkerData = { conoutPipeName: _conoutPipeName };
this._worker = new Worker(join(__dirname, 'worker/conoutSocketWorker.js'), { workerData });
const scriptPath = __dirname.replace('node_modules.asar', 'node_modules.asar.unpacked');
this._worker = new Worker(join(scriptPath, 'worker/conoutSocketWorker.js'), { workerData });
this._worker.on('message', (message: ConoutWorkerMessage) => {

@@ -46,0 +47,0 @@ switch (message) {

@@ -45,3 +45,3 @@ /**

*/
env?: { [key: string]: string };
env?: { [key: string]: string | undefined };

@@ -82,7 +82,13 @@ /**

/**
* Security warning: use this option with great caution, as opened file descriptors
* with higher privileges might leak to the child program.
* Security warning: use this option with great caution unless `closeFDs` is also set,
* as opened file descriptors with higher privileges might leak to the child program.
*/
uid?: number;
gid?: number;
/**
* Close all open file after spawning the child process (UNIX only).
* Carries a performance penalty on Linux.
*/
closeFDs?: boolean;
}

@@ -170,3 +176,3 @@

* Resizes the dimensions of the pty.
* @param columns THe number of columns to use.
* @param columns The number of columns to use.
* @param rows The number of rows to use.

@@ -173,0 +179,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

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

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