New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@hapify/vm

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hapify/vm - npm Package Compare versions

Comparing version
0.3.6
to
1.0.1
+18
CHANGELOG.md
# Changelog
All notable changes to this project will be documented in this file. See
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## @hapify/vm [1.0.1](https://github.com/hapify/hapify/compare/@hapify/vm@1.0.0...@hapify/vm@1.0.1) (2021-04-15)
### Bug Fixes
* console accessible ([#12](https://github.com/hapify/hapify/issues/12)) ([68b13fd](https://github.com/hapify/hapify/commit/68b13fdc238bfa0c449f801ff7c0ba323945dfdb))
# @hapify/vm 1.0.0 (2021-04-15)
### Features
* change hapify repo into a monorepo to host all related hapify packages ([#9](https://github.com/hapify/hapify/issues/9)) ([d76feb3](https://github.com/hapify/hapify/commit/d76feb3683a045dad2a38df024c0e2521f64bb23))
export declare class EvaluationError extends Error {
code: number;
name: string;
lineNumber: number;
columnNumber: number;
details: string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EvaluationError = void 0;
class EvaluationError extends Error {
constructor() {
super(...arguments);
this.code = 6002;
this.name = 'VmEvaluationError';
this.lineNumber = null;
this.columnNumber = null;
this.details = null;
}
}
exports.EvaluationError = EvaluationError;
//# sourceMappingURL=EvaluationError.js.map
{"version":3,"file":"EvaluationError.js","sourceRoot":"","sources":["../../src/errors/EvaluationError.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAgB,SAAQ,KAAK;IAA1C;;QACE,SAAI,GAAG,IAAI,CAAC;QAEZ,SAAI,GAAG,mBAAmB,CAAC;QAE3B,eAAU,GAAW,IAAI,CAAC;QAE1B,iBAAY,GAAW,IAAI,CAAC;QAE5B,YAAO,GAAW,IAAI,CAAC;IACzB,CAAC;CAAA;AAVD,0CAUC"}
export declare class IntegrityError extends Error {
code: number;
name: string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntegrityError = void 0;
class IntegrityError extends Error {
constructor() {
super(...arguments);
this.code = 6004;
this.name = 'VmIntegrityError';
}
}
exports.IntegrityError = IntegrityError;
//# sourceMappingURL=IntegrityError.js.map
{"version":3,"file":"IntegrityError.js","sourceRoot":"","sources":["../../src/errors/IntegrityError.ts"],"names":[],"mappings":";;;AAAA,MAAa,cAAe,SAAQ,KAAK;IAAzC;;QACE,SAAI,GAAG,IAAI,CAAC;QAEZ,SAAI,GAAG,kBAAkB,CAAC;IAC5B,CAAC;CAAA;AAJD,wCAIC"}
export declare class OutputError extends Error {
code: number;
name: string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutputError = void 0;
class OutputError extends Error {
constructor() {
super(...arguments);
this.code = 6001;
this.name = 'VmOutputError';
}
}
exports.OutputError = OutputError;
//# sourceMappingURL=OutputError.js.map
{"version":3,"file":"OutputError.js","sourceRoot":"","sources":["../../src/errors/OutputError.ts"],"names":[],"mappings":";;;AAAA,MAAa,WAAY,SAAQ,KAAK;IAAtC;;QACE,SAAI,GAAG,IAAI,CAAC;QAEZ,SAAI,GAAG,eAAe,CAAC;IACzB,CAAC;CAAA;AAJD,kCAIC"}
export declare class TimeoutError extends Error {
code: number;
name: string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeoutError = void 0;
class TimeoutError extends Error {
constructor() {
super(...arguments);
this.code = 6003;
this.name = 'VmTimeoutError';
}
}
exports.TimeoutError = TimeoutError;
//# sourceMappingURL=TimeoutError.js.map
{"version":3,"file":"TimeoutError.js","sourceRoot":"","sources":["../../src/errors/TimeoutError.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAa,SAAQ,KAAK;IAAvC;;QACE,SAAI,GAAG,IAAI,CAAC;QAEZ,SAAI,GAAG,gBAAgB,CAAC;IAC1B,CAAC;CAAA;AAJD,oCAIC"}

Sorry, the diff of this file is not supported yet

+5
-20

@@ -0,1 +1,5 @@

import { EvaluationError } from './errors/EvaluationError';
import { IntegrityError } from './errors/IntegrityError';
import { OutputError } from './errors/OutputError';
import { TimeoutError } from './errors/TimeoutError';
interface HapifyVMOptions {

@@ -6,21 +10,3 @@ timeout: number;

}
export declare class OutputError extends Error {
code: number;
name: string;
}
export declare class EvaluationError extends Error {
code: number;
name: string;
lineNumber: number;
columnNumber: number;
details: string;
}
export declare class TimeoutError extends Error {
code: number;
name: string;
}
export declare class IntegrityError extends Error {
code: number;
name: string;
}
export { EvaluationError, IntegrityError, OutputError, TimeoutError };
export declare class HapifyVM {

@@ -44,2 +30,1 @@ /** Default options */

}
export {};
+24
-44
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HapifyVM = exports.IntegrityError = exports.TimeoutError = exports.EvaluationError = exports.OutputError = void 0;
exports.HapifyVM = exports.TimeoutError = exports.OutputError = exports.IntegrityError = exports.EvaluationError = void 0;
const vm2_1 = require("vm2");
const EvaluationError_1 = require("./errors/EvaluationError");
Object.defineProperty(exports, "EvaluationError", { enumerable: true, get: function () { return EvaluationError_1.EvaluationError; } });
const IntegrityError_1 = require("./errors/IntegrityError");
Object.defineProperty(exports, "IntegrityError", { enumerable: true, get: function () { return IntegrityError_1.IntegrityError; } });
const OutputError_1 = require("./errors/OutputError");
Object.defineProperty(exports, "OutputError", { enumerable: true, get: function () { return OutputError_1.OutputError; } });
const TimeoutError_1 = require("./errors/TimeoutError");
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return TimeoutError_1.TimeoutError; } });
const SECOND = 1000;
class OutputError extends Error {
constructor() {
super(...arguments);
this.code = 6001;
this.name = 'VmOutputError';
}
}
exports.OutputError = OutputError;
class EvaluationError extends Error {
constructor() {
super(...arguments);
this.code = 6002;
this.name = 'VmEvaluationError';
this.lineNumber = null;
this.columnNumber = null;
this.details = null;
}
}
exports.EvaluationError = EvaluationError;
class TimeoutError extends Error {
constructor() {
super(...arguments);
this.code = 6003;
this.name = 'VmTimeoutError';
}
}
exports.TimeoutError = TimeoutError;
class IntegrityError extends Error {
constructor() {
super(...arguments);
this.code = 6004;
this.name = 'VmIntegrityError';
}
}
exports.IntegrityError = IntegrityError;
class HapifyVM {

@@ -50,5 +23,9 @@ /** Constructor */

};
/** Built-in objects to remove from sandbox */
this.forbiddenObjects = {
console: undefined,
};
/** RegEx used to extract error's line & column */
this.stackRegex = /vm\.js:([0-9]+):([0-9]+)/m;
this.options = Object.assign({}, this.defaultOptions, options);
this.options = Object.assign(Object.assign({}, this.defaultOptions), options);
}

@@ -71,14 +48,15 @@ /** Wrap content in auto-executable function */

try {
result = vm.run(wrappedContent);
result = vm.run(wrappedContent, 'vm.js');
}
catch (error) {
// Check error
if (typeof error.message !== 'string' || typeof error.stack !== 'string') {
throw new IntegrityError('Invalid error');
if (typeof error.message !== 'string' ||
typeof error.stack !== 'string') {
throw new IntegrityError_1.IntegrityError('Invalid error');
}
if (error.message.startsWith('Script execution timed out')) {
throw new TimeoutError(error.message);
throw new TimeoutError_1.TimeoutError(error.message);
}
// Parse error
const evalError = new EvaluationError(error.message);
const evalError = new EvaluationError_1.EvaluationError(error.message);
const matches = this.stackRegex.exec(error.stack);

@@ -94,4 +72,6 @@ if (matches) {

}
if (!this.options.allowAnyOutput && typeof result !== 'undefined' && typeof result !== 'string') {
throw new OutputError('Must return a string');
if (!this.options.allowAnyOutput &&
typeof result !== 'undefined' &&
typeof result !== 'string') {
throw new OutputError_1.OutputError('Must return a string');
}

@@ -98,0 +78,0 @@ return result;

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

{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6BAAyB;AAEzB,MAAM,MAAM,GAAG,IAAI,CAAC;AAQpB,MAAa,WAAY,SAAQ,KAAK;IAAtC;;QACC,SAAI,GAAG,IAAI,CAAC;QACZ,SAAI,GAAG,eAAe,CAAC;IACxB,CAAC;CAAA;AAHD,kCAGC;AACD,MAAa,eAAgB,SAAQ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CAAC;IAChB,CAAC;CACF;AAjFD,4BAiFC"}
{
"name": "@hapify/vm",
"version": "0.3.6",
"version": "1.0.1",
"description": "Sandbox for JavaScript code",
"keywords": [
"hapify",
"vm"
],
"license": "MIT",
"author": "Edouard Demotes-Mainard <edouard@tractr.net>",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"update": "npm-check -u",
"build": "rimraf dist && tsc -p .",
"clean": "rimraf dist node_modules coverage .nyc_output",
"prepublishOnly": "npm run build",
"lint": "npm run lint:tsc && npm run lint:prettier && npm run lint:eslint",
"lint:eslint": "eslint \"{src,test}/**/*.{ts,js}\"",
"lint:eslint:fix": "npm run lint:eslint -- --fix",
"lint:fix": "npm run lint:tsc:fix && npm run lint:prettier:fix && npm run lint:eslint:fix",
"lint:prettier": "prettier --check \"{src,test}/**/*.{ts,js}\" ",
"lint:prettier:fix": "prettier --write \"{src,test}/**/*.{ts,js}\"",
"lint:tsc": "tsc --noEmit",
"lint:tsc:fix": "npm run lint:tsc",
"test": "nyc mocha",
"lint": "prettier --write '**/*.ts'",
"build": "rimraf dist && tsc -p ."
"update": "npm-check -u"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com:hapify/vm.git"
"dependencies": {
"vm2": "^3.9.2"
},
"keywords": [
"hapify",
"vm"
],
"author": "Edouard Demotes-Mainard <edouard@tractr.net>",
"license": "MIT",
"homepage": "https://github.com/hapify/vm#readme",
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@hapi/code": "^8.0.2",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.22",
"husky": "^4.3.8",
"mocha": "^8.2.1",
"npm-check": "^5.9.2",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0",
"rimraf": "^3.0.2",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"mocha": "^8.2.1"
},
"dependencies": {
"vm2": "^3.9.2"
},
"engines": {
"node": ">=9"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "pretty-quick --staged --pattern \"**/*.ts\""
}
}
}

@@ -7,3 +7,3 @@ # Hapify VM

[![Build Status](https://travis-ci.org/hapify/vm.svg?branch=master)](https://travis-ci.org/hapify/vm) [![codecov](https://codecov.io/gh/hapify/vm/branch/master/graph/badge.svg)](https://codecov.io/gh/hapify/vm)
[![Release and Deploy](https://github.com/hapify/hapify/actions/workflows/deploy.yml/badge.svg)](https://github.com/hapify/hapify/actions/workflows/deploy.yml)

@@ -10,0 +10,0 @@ ## Usage