@@ -4,11 +4,12 @@ import {EventEmitter} from 'events';
4
4
* Require options for a VM
5
5
*/
6
6
export interface VMRequire {
7
- /** Array of allowed builtin modules, accepts ["*"] for all (default: none) */
7
+ /** Array of allowed built-in modules, accepts ["*"] for all. Using "*" increases the attack surface and potential
8
+ * new modules allow to escape the sandbox. (default: none) */
8
9
builtin ?: string [ ] ;
9
10
/*
10
11
* `host` (default) to require modules in host and proxy them to sandbox. `sandbox` to load, compile and
11
- * require modules in sandbox. Builtin modules except `events` always required in host and proxied to sandbox
12
+ * require modules in sandbox. Built-in modules except `events` always required in host and proxied to sandbox
12
13
*/
13
14
context ?: "host" | "sandbox" ;
14
15
/** `true`, an array of allowed external modules or an object with external options (default: `false`) */
@@ -17,7 +18,7 @@ export interface VMRequire {
17
18
import ?: string [ ] ;
18
19
/** Restricted path(s) where local modules can be required (default: every path). */
19
20
root ?: string | string [ ] ;
20
- /** Collection of mock modules (both external or builtin ). */
21
+ /** Collection of mock modules (both external or built-in ). */
21
22
mock ?: any ;
22
23
/* An additional lookup function in case a module wasn't found in one of the traditional node lookup paths. */
23
24
resolve ?: ( moduleName : string , parentDirname : string ) => string | undefined ;
@@ -36,7 +37,7 @@ type CompilerFunction = (code: string, filename: string) => string;
36
37
*/
37
38
export interface VMOptions {
38
39
/**
39
- * `javascript` (default) or `coffeescript` or custom compiler function (which receives the code, and it's filepath ).
40
+ * `javascript` (default) or `coffeescript` or custom compiler function (which receives the code, and it's file path ).
40
41
* The library expects you to have coffee-script pre-installed if the compiler is set to `coffeescript`.
41
42
*/
42
43
compiler ?: "javascript" | "coffeescript" | CompilerFunction ;
@@ -48,7 +49,7 @@ export interface VMOptions {
48
49
*/
49
50
timeout ?: number ;
50
51
/**
51
- * If set to `false` any calls to eval or function constructors (`Function`, `GeneratorFunction`, etc) will throw an
52
+ * If set to `false` any calls to eval or function constructors (`Function`, `GeneratorFunction`, etc. ) will throw an
52
53
* `EvalError` (default: `true`).
53
54
*/
54
55
eval ?: boolean ;
@@ -58,7 +59,7 @@ export interface VMOptions {
58
59
wasm ?: boolean ;
59
60
/**
60
61
* If set to `true` any attempt to run code using async will throw a `VMError` (default: `false`).
61
- * @deprecated Use `` allowAsync` instead
62
+ * @deprecated Use `allowAsync` instead.
62
63
*/
63
64
fixAsync ?: boolean ;
64
65
@@ -76,7 +77,8 @@ export interface NodeVMOptions extends VMOptions {
76
77
console ?: "inherit" | "redirect" | "off" ;
77
78
/** `true` or an object to enable `require` options (default: `false`). */
78
79
require ?: true | VMRequire ;
79
- /** `true` to enable VMs nesting (default: `false`). */
80
+ /** **WARNING**: This should be disabled. It allows to create a NodeVM form within the sandbox which could return any host module.
81
+ * `true` to enable VMs nesting (default: `false`). */
80
82
nesting ?: boolean ;
81
83
/** `commonjs` (default) to wrap script into CommonJS wrapper, `none` to retrieve value returned by the script. */
82
84
wrapper ?: "commonjs" | "none" ;
@@ -119,6 +121,8 @@ export class VM {
119
121
getGlobal ( name : string ) : any ;
120
122
/** Freezes the object inside VM making it read-only. Not available for primitive values. */
121
123
freeze ( object : any , name ?: string ) : any ;
124
+ /** Freezes the object inside VM making it read-only. Not available for primitive values. */
125
+ readonly ( object : any ) : any ;
122
126
/** Protects the object inside VM making impossible to set functions as it's properties. Not available for primitive values */
123
127
protect ( object : any , name ?: string ) : any ;
124
128
}
@@ -135,7 +139,7 @@ export class NodeVM extends EventEmitter implements VM {
135
139
/**
136
140
* Create NodeVM and run code inside it.
137
141
*
138
- * @param {string } script Javascript code.
142
+ * @param {string } script JavaScript code.
139
143
* @param {string } [filename] File name (used in stack traces only).
140
144
* @param {Object } [options] VM options.
141
145
*/
0 commit comments