@cuxt/sandboxjs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +186 -0
- package/build/Sandbox.d.ts +25 -0
- package/build/Sandbox.js +62 -0
- package/build/SandboxExec.d.ts +66 -0
- package/build/SandboxExec.js +214 -0
- package/build/eval.d.ts +27 -0
- package/build/eval.js +205 -0
- package/build/executor.d.ts +124 -0
- package/build/executor.js +1546 -0
- package/build/parser.d.ts +154 -0
- package/build/parser.js +1527 -0
- package/build/unraw.d.ts +11 -0
- package/build/unraw.js +168 -0
- package/build/utils.d.ts +264 -0
- package/build/utils.js +362 -0
- package/dist/Sandbox.d.ts +25 -0
- package/dist/Sandbox.js +270 -0
- package/dist/Sandbox.js.map +1 -0
- package/dist/Sandbox.min.js +2 -0
- package/dist/Sandbox.min.js.map +1 -0
- package/dist/SandboxExec.d.ts +66 -0
- package/dist/SandboxExec.js +218 -0
- package/dist/SandboxExec.js.map +1 -0
- package/dist/SandboxExec.min.js +2 -0
- package/dist/SandboxExec.min.js.map +1 -0
- package/dist/eval.d.ts +27 -0
- package/dist/executor.d.ts +124 -0
- package/dist/executor.js +1550 -0
- package/dist/executor.js.map +1 -0
- package/dist/node/Sandbox.d.ts +25 -0
- package/dist/node/Sandbox.js +277 -0
- package/dist/node/SandboxExec.d.ts +66 -0
- package/dist/node/SandboxExec.js +225 -0
- package/dist/node/eval.d.ts +27 -0
- package/dist/node/executor.d.ts +124 -0
- package/dist/node/executor.js +1567 -0
- package/dist/node/parser.d.ts +154 -0
- package/dist/node/parser.js +1704 -0
- package/dist/node/unraw.d.ts +11 -0
- package/dist/node/utils.d.ts +264 -0
- package/dist/node/utils.js +385 -0
- package/dist/parser.d.ts +154 -0
- package/dist/parser.js +1690 -0
- package/dist/parser.js.map +1 -0
- package/dist/unraw.d.ts +11 -0
- package/dist/utils.d.ts +264 -0
- package/dist/utils.js +365 -0
- package/dist/utils.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { IEvalContext } from './eval.js';
|
|
2
|
+
import { Change, ExecReturn } from './executor.js';
|
|
3
|
+
import { IContext, IExecContext, IGlobals, IOptionParams, IScope, Scope, SubscriptionSubject, Ticks } from './utils.js';
|
|
4
|
+
export { IOptions, IContext, IExecContext, LocalScope, SandboxExecutionTreeError, SandboxCapabilityError, SandboxAccessError, SandboxError, } from './utils.js';
|
|
5
|
+
export default class SandboxExec {
|
|
6
|
+
evalContext?: IEvalContext | undefined;
|
|
7
|
+
readonly context: IContext;
|
|
8
|
+
readonly setSubscriptions: WeakMap<SubscriptionSubject, Map<string, Set<(modification: Change) => void>>>;
|
|
9
|
+
readonly changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;
|
|
10
|
+
readonly sandboxFunctions: WeakMap<Function, IExecContext>;
|
|
11
|
+
private haltSubscriptions;
|
|
12
|
+
private resumeSubscriptions;
|
|
13
|
+
halted: boolean;
|
|
14
|
+
timeoutHandleCounter: number;
|
|
15
|
+
readonly setTimeoutHandles: Map<number, {
|
|
16
|
+
handle: number;
|
|
17
|
+
haltsub: {
|
|
18
|
+
unsubscribe: () => void;
|
|
19
|
+
};
|
|
20
|
+
contsub: {
|
|
21
|
+
unsubscribe: () => void;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
readonly setIntervalHandles: Map<number, {
|
|
25
|
+
handle: number;
|
|
26
|
+
haltsub: {
|
|
27
|
+
unsubscribe: () => void;
|
|
28
|
+
};
|
|
29
|
+
contsub: {
|
|
30
|
+
unsubscribe: () => void;
|
|
31
|
+
};
|
|
32
|
+
}>;
|
|
33
|
+
constructor(options?: IOptionParams, evalContext?: IEvalContext | undefined);
|
|
34
|
+
static get SAFE_GLOBALS(): IGlobals;
|
|
35
|
+
static get SAFE_PROTOTYPES(): Map<any, Set<string>>;
|
|
36
|
+
subscribeGet(callback: (obj: SubscriptionSubject, name: string) => void, context: IExecContext): {
|
|
37
|
+
unsubscribe: () => void;
|
|
38
|
+
};
|
|
39
|
+
subscribeSet(obj: object, name: string, callback: (modification: Change) => void, context: SandboxExec | IExecContext): {
|
|
40
|
+
unsubscribe: () => void;
|
|
41
|
+
};
|
|
42
|
+
subscribeSetGlobal(obj: SubscriptionSubject, name: string, callback: (modification: Change) => void): {
|
|
43
|
+
unsubscribe: () => void;
|
|
44
|
+
};
|
|
45
|
+
subscribeHalt(cb: (args?: {
|
|
46
|
+
error: Error;
|
|
47
|
+
ticks: Ticks;
|
|
48
|
+
scope: Scope;
|
|
49
|
+
context: IExecContext;
|
|
50
|
+
}) => void): {
|
|
51
|
+
unsubscribe: () => void;
|
|
52
|
+
};
|
|
53
|
+
subscribeResume(cb: () => void): {
|
|
54
|
+
unsubscribe: () => void;
|
|
55
|
+
};
|
|
56
|
+
haltExecution(haltContext?: {
|
|
57
|
+
error: Error;
|
|
58
|
+
ticks: Ticks;
|
|
59
|
+
scope: Scope;
|
|
60
|
+
context: IExecContext;
|
|
61
|
+
}): void;
|
|
62
|
+
resumeExecution(): void;
|
|
63
|
+
getContext(fn: (...args: any[]) => any): IExecContext | undefined;
|
|
64
|
+
executeTree<T>(context: IExecContext, scopes?: IScope[]): ExecReturn<T>;
|
|
65
|
+
executeTreeAsync<T>(context: IExecContext, scopes?: IScope[]): Promise<ExecReturn<T>>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { executeTree, executeTreeAsync } from './executor.js';
|
|
2
|
+
import { createContext, SandboxGlobal, SandboxExecutionQuotaExceededError } from './utils.js';
|
|
3
|
+
export { LocalScope, SandboxAccessError, SandboxCapabilityError, SandboxError, SandboxExecutionTreeError } from './utils.js';
|
|
4
|
+
|
|
5
|
+
function subscribeSet(obj, name, callback, context) {
|
|
6
|
+
const names = context.setSubscriptions.get(obj) || new Map();
|
|
7
|
+
context.setSubscriptions.set(obj, names);
|
|
8
|
+
const callbacks = names.get(name) || new Set();
|
|
9
|
+
names.set(name, callbacks);
|
|
10
|
+
callbacks.add(callback);
|
|
11
|
+
let changeCbs;
|
|
12
|
+
const val = obj[name];
|
|
13
|
+
if (val instanceof Object) {
|
|
14
|
+
changeCbs = context.changeSubscriptions.get(val) || new Set();
|
|
15
|
+
changeCbs.add(callback);
|
|
16
|
+
context.changeSubscriptions.set(val, changeCbs);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
unsubscribe: () => {
|
|
20
|
+
callbacks.delete(callback);
|
|
21
|
+
changeCbs?.delete(callback);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
class SandboxExec {
|
|
26
|
+
constructor(options, evalContext) {
|
|
27
|
+
this.evalContext = evalContext;
|
|
28
|
+
this.setSubscriptions = new WeakMap();
|
|
29
|
+
this.changeSubscriptions = new WeakMap();
|
|
30
|
+
this.sandboxFunctions = new WeakMap();
|
|
31
|
+
this.haltSubscriptions = new Set();
|
|
32
|
+
this.resumeSubscriptions = new Set();
|
|
33
|
+
this.halted = false;
|
|
34
|
+
this.timeoutHandleCounter = 0;
|
|
35
|
+
this.setTimeoutHandles = new Map();
|
|
36
|
+
this.setIntervalHandles = new Map();
|
|
37
|
+
const opt = Object.assign({
|
|
38
|
+
audit: false,
|
|
39
|
+
forbidFunctionCalls: false,
|
|
40
|
+
forbidFunctionCreation: false,
|
|
41
|
+
globals: SandboxExec.SAFE_GLOBALS,
|
|
42
|
+
prototypeWhitelist: SandboxExec.SAFE_PROTOTYPES,
|
|
43
|
+
prototypeReplacements: new Map(),
|
|
44
|
+
}, options || {});
|
|
45
|
+
this.context = createContext(this, opt);
|
|
46
|
+
}
|
|
47
|
+
static get SAFE_GLOBALS() {
|
|
48
|
+
return {
|
|
49
|
+
globalThis,
|
|
50
|
+
Function,
|
|
51
|
+
eval,
|
|
52
|
+
console: {
|
|
53
|
+
debug: console.debug,
|
|
54
|
+
error: console.error,
|
|
55
|
+
info: console.info,
|
|
56
|
+
log: console.log,
|
|
57
|
+
table: console.table,
|
|
58
|
+
warn: console.warn,
|
|
59
|
+
},
|
|
60
|
+
isFinite,
|
|
61
|
+
isNaN,
|
|
62
|
+
parseFloat,
|
|
63
|
+
parseInt,
|
|
64
|
+
decodeURI,
|
|
65
|
+
decodeURIComponent,
|
|
66
|
+
encodeURI,
|
|
67
|
+
encodeURIComponent,
|
|
68
|
+
escape,
|
|
69
|
+
unescape,
|
|
70
|
+
Boolean,
|
|
71
|
+
Number,
|
|
72
|
+
BigInt,
|
|
73
|
+
String,
|
|
74
|
+
Object,
|
|
75
|
+
Array,
|
|
76
|
+
Symbol,
|
|
77
|
+
Error,
|
|
78
|
+
EvalError,
|
|
79
|
+
RangeError,
|
|
80
|
+
ReferenceError,
|
|
81
|
+
SyntaxError,
|
|
82
|
+
TypeError,
|
|
83
|
+
URIError,
|
|
84
|
+
Int8Array,
|
|
85
|
+
Uint8Array,
|
|
86
|
+
Uint8ClampedArray,
|
|
87
|
+
Int16Array,
|
|
88
|
+
Uint16Array,
|
|
89
|
+
Int32Array,
|
|
90
|
+
Uint32Array,
|
|
91
|
+
Float32Array,
|
|
92
|
+
Float64Array,
|
|
93
|
+
Map,
|
|
94
|
+
Set,
|
|
95
|
+
WeakMap,
|
|
96
|
+
WeakSet,
|
|
97
|
+
Promise,
|
|
98
|
+
Intl,
|
|
99
|
+
JSON,
|
|
100
|
+
Math,
|
|
101
|
+
Date,
|
|
102
|
+
RegExp,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
static get SAFE_PROTOTYPES() {
|
|
106
|
+
const protos = [
|
|
107
|
+
SandboxGlobal,
|
|
108
|
+
Function,
|
|
109
|
+
Boolean,
|
|
110
|
+
Number,
|
|
111
|
+
BigInt,
|
|
112
|
+
String,
|
|
113
|
+
Date,
|
|
114
|
+
Error,
|
|
115
|
+
Array,
|
|
116
|
+
Int8Array,
|
|
117
|
+
Uint8Array,
|
|
118
|
+
Uint8ClampedArray,
|
|
119
|
+
Int16Array,
|
|
120
|
+
Uint16Array,
|
|
121
|
+
Int32Array,
|
|
122
|
+
Uint32Array,
|
|
123
|
+
Float32Array,
|
|
124
|
+
Float64Array,
|
|
125
|
+
Map,
|
|
126
|
+
Set,
|
|
127
|
+
WeakMap,
|
|
128
|
+
WeakSet,
|
|
129
|
+
Promise,
|
|
130
|
+
Symbol,
|
|
131
|
+
Date,
|
|
132
|
+
RegExp,
|
|
133
|
+
// Fetch API
|
|
134
|
+
Response,
|
|
135
|
+
Request,
|
|
136
|
+
Headers,
|
|
137
|
+
FormData,
|
|
138
|
+
];
|
|
139
|
+
const map = new Map();
|
|
140
|
+
protos.forEach((proto) => {
|
|
141
|
+
map.set(proto, new Set());
|
|
142
|
+
});
|
|
143
|
+
map.set(Object, new Set([
|
|
144
|
+
'constructor',
|
|
145
|
+
'name',
|
|
146
|
+
'entries',
|
|
147
|
+
'fromEntries',
|
|
148
|
+
'getOwnPropertyNames',
|
|
149
|
+
'is',
|
|
150
|
+
'keys',
|
|
151
|
+
'hasOwnProperty',
|
|
152
|
+
'isPrototypeOf',
|
|
153
|
+
'propertyIsEnumerable',
|
|
154
|
+
'toLocaleString',
|
|
155
|
+
'toString',
|
|
156
|
+
'valueOf',
|
|
157
|
+
'values',
|
|
158
|
+
]));
|
|
159
|
+
return map;
|
|
160
|
+
}
|
|
161
|
+
subscribeGet(callback, context) {
|
|
162
|
+
context.getSubscriptions.add(callback);
|
|
163
|
+
return { unsubscribe: () => context.getSubscriptions.delete(callback) };
|
|
164
|
+
}
|
|
165
|
+
subscribeSet(obj, name, callback, context) {
|
|
166
|
+
return subscribeSet(obj, name, callback, context);
|
|
167
|
+
}
|
|
168
|
+
subscribeSetGlobal(obj, name, callback) {
|
|
169
|
+
return subscribeSet(obj, name, callback, this);
|
|
170
|
+
}
|
|
171
|
+
subscribeHalt(cb) {
|
|
172
|
+
this.haltSubscriptions.add(cb);
|
|
173
|
+
return {
|
|
174
|
+
unsubscribe: () => {
|
|
175
|
+
this.haltSubscriptions.delete(cb);
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
subscribeResume(cb) {
|
|
180
|
+
this.resumeSubscriptions.add(cb);
|
|
181
|
+
return {
|
|
182
|
+
unsubscribe: () => {
|
|
183
|
+
this.resumeSubscriptions.delete(cb);
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
haltExecution(haltContext) {
|
|
188
|
+
if (this.halted)
|
|
189
|
+
return;
|
|
190
|
+
this.halted = true;
|
|
191
|
+
for (const cb of this.haltSubscriptions) {
|
|
192
|
+
cb(haltContext);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
resumeExecution() {
|
|
196
|
+
if (!this.halted)
|
|
197
|
+
return;
|
|
198
|
+
if (this.context.ticks.tickLimit && this.context.ticks.ticks >= this.context.ticks.tickLimit) {
|
|
199
|
+
throw new SandboxExecutionQuotaExceededError('Cannot resume execution: tick limit exceeded');
|
|
200
|
+
}
|
|
201
|
+
this.halted = false;
|
|
202
|
+
for (const cb of this.resumeSubscriptions) {
|
|
203
|
+
cb();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
getContext(fn) {
|
|
207
|
+
return this.sandboxFunctions.get(fn);
|
|
208
|
+
}
|
|
209
|
+
executeTree(context, scopes = []) {
|
|
210
|
+
return executeTree(context.ctx.ticks, context, context.tree, scopes);
|
|
211
|
+
}
|
|
212
|
+
executeTreeAsync(context, scopes = []) {
|
|
213
|
+
return executeTreeAsync(context.ctx.ticks, context, context.tree, scopes);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export { SandboxExec as default };
|
|
218
|
+
//# sourceMappingURL=SandboxExec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SandboxExec.js","sources":["../src/SandboxExec.ts"],"sourcesContent":["import { IEvalContext } from './eval.js';\r\nimport { Change, ExecReturn, executeTree, executeTreeAsync } from './executor.js';\r\nimport {\r\n createContext,\r\n IContext,\r\n IExecContext,\r\n IGlobals,\r\n IOptionParams,\r\n IOptions,\r\n IScope,\r\n replacementCallback,\r\n SandboxExecutionQuotaExceededError,\r\n SandboxGlobal,\r\n Scope,\r\n SubscriptionSubject,\r\n Ticks,\r\n} from './utils.js';\r\n\r\nexport {\r\n IOptions,\r\n IContext,\r\n IExecContext,\r\n LocalScope,\r\n SandboxExecutionTreeError,\r\n SandboxCapabilityError,\r\n SandboxAccessError,\r\n SandboxError,\r\n} from './utils.js';\r\n\r\nfunction subscribeSet(\r\n obj: object,\r\n name: string,\r\n callback: (modification: Change) => void,\r\n context: {\r\n setSubscriptions: WeakMap<\r\n SubscriptionSubject,\r\n Map<string, Set<(modification: Change) => void>>\r\n >;\r\n changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\r\n },\r\n): { unsubscribe: () => void } {\r\n const names =\r\n context.setSubscriptions.get(obj) || new Map<string, Set<(modification: Change) => void>>();\r\n context.setSubscriptions.set(obj, names);\r\n const callbacks = names.get(name) || new Set();\r\n names.set(name, callbacks);\r\n callbacks.add(callback);\r\n let changeCbs: Set<(modification: Change) => void>;\r\n const val = (obj as any)[name] as unknown;\r\n if (val instanceof Object) {\r\n changeCbs = context.changeSubscriptions.get(val) || new Set();\r\n changeCbs.add(callback);\r\n context.changeSubscriptions.set(val, changeCbs);\r\n }\r\n return {\r\n unsubscribe: () => {\r\n callbacks.delete(callback);\r\n changeCbs?.delete(callback);\r\n },\r\n };\r\n}\r\n\r\nexport default class SandboxExec {\r\n public readonly context: IContext;\r\n public readonly setSubscriptions: WeakMap<\r\n SubscriptionSubject,\r\n Map<string, Set<(modification: Change) => void>>\r\n > = new WeakMap();\r\n public readonly changeSubscriptions: WeakMap<\r\n SubscriptionSubject,\r\n Set<(modification: Change) => void>\r\n > = new WeakMap();\r\n public readonly sandboxFunctions: WeakMap<Function, IExecContext> = new WeakMap();\r\n private haltSubscriptions: Set<\r\n (args?: { error: Error; ticks: Ticks; scope: Scope; context: IExecContext }) => void\r\n > = new Set();\r\n private resumeSubscriptions: Set<() => void> = new Set();\r\n public halted = false;\r\n timeoutHandleCounter = 0;\r\n public readonly setTimeoutHandles = new Map<\r\n number,\r\n {\r\n handle: number;\r\n haltsub: { unsubscribe: () => void };\r\n contsub: { unsubscribe: () => void };\r\n }\r\n >();\r\n public readonly setIntervalHandles = new Map<\r\n number,\r\n {\r\n handle: number;\r\n haltsub: { unsubscribe: () => void };\r\n contsub: { unsubscribe: () => void };\r\n }\r\n >();\r\n constructor(\r\n options?: IOptionParams,\r\n public evalContext?: IEvalContext,\r\n ) {\r\n const opt: IOptions = Object.assign(\r\n {\r\n audit: false,\r\n forbidFunctionCalls: false,\r\n forbidFunctionCreation: false,\r\n globals: SandboxExec.SAFE_GLOBALS,\r\n prototypeWhitelist: SandboxExec.SAFE_PROTOTYPES,\r\n prototypeReplacements: new Map<new () => any, replacementCallback>(),\r\n },\r\n options || {},\r\n );\r\n this.context = createContext(this, opt);\r\n }\r\n\r\n static get SAFE_GLOBALS(): IGlobals {\r\n return {\r\n globalThis,\r\n Function,\r\n eval,\r\n console: {\r\n debug: console.debug,\r\n error: console.error,\r\n info: console.info,\r\n log: console.log,\r\n table: console.table,\r\n warn: console.warn,\r\n },\r\n isFinite,\r\n isNaN,\r\n parseFloat,\r\n parseInt,\r\n decodeURI,\r\n decodeURIComponent,\r\n encodeURI,\r\n encodeURIComponent,\r\n escape,\r\n unescape,\r\n Boolean,\r\n Number,\r\n BigInt,\r\n String,\r\n Object,\r\n Array,\r\n Symbol,\r\n Error,\r\n EvalError,\r\n RangeError,\r\n ReferenceError,\r\n SyntaxError,\r\n TypeError,\r\n URIError,\r\n Int8Array,\r\n Uint8Array,\r\n Uint8ClampedArray,\r\n Int16Array,\r\n Uint16Array,\r\n Int32Array,\r\n Uint32Array,\r\n Float32Array,\r\n Float64Array,\r\n Map,\r\n Set,\r\n WeakMap,\r\n WeakSet,\r\n Promise,\r\n Intl,\r\n JSON,\r\n Math,\r\n Date,\r\n RegExp,\r\n };\r\n }\r\n\r\n static get SAFE_PROTOTYPES(): Map<any, Set<string>> {\r\n const protos = [\r\n SandboxGlobal,\r\n Function,\r\n Boolean,\r\n Number,\r\n BigInt,\r\n String,\r\n Date,\r\n Error,\r\n Array,\r\n Int8Array,\r\n Uint8Array,\r\n Uint8ClampedArray,\r\n Int16Array,\r\n Uint16Array,\r\n Int32Array,\r\n Uint32Array,\r\n Float32Array,\r\n Float64Array,\r\n Map,\r\n Set,\r\n WeakMap,\r\n WeakSet,\r\n Promise,\r\n Symbol,\r\n Date,\r\n RegExp,\r\n // Fetch API\r\n Response,\r\n Request,\r\n Headers,\r\n FormData,\r\n ];\r\n const map = new Map<any, Set<string>>();\r\n protos.forEach((proto) => {\r\n map.set(proto, new Set());\r\n });\r\n map.set(\r\n Object,\r\n new Set([\r\n 'constructor',\r\n 'name',\r\n 'entries',\r\n 'fromEntries',\r\n 'getOwnPropertyNames',\r\n 'is',\r\n 'keys',\r\n 'hasOwnProperty',\r\n 'isPrototypeOf',\r\n 'propertyIsEnumerable',\r\n 'toLocaleString',\r\n 'toString',\r\n 'valueOf',\r\n 'values',\r\n ]),\r\n );\r\n return map;\r\n }\r\n\r\n subscribeGet(\r\n callback: (obj: SubscriptionSubject, name: string) => void,\r\n context: IExecContext,\r\n ): { unsubscribe: () => void } {\r\n context.getSubscriptions.add(callback);\r\n return { unsubscribe: () => context.getSubscriptions.delete(callback) };\r\n }\r\n\r\n subscribeSet(\r\n obj: object,\r\n name: string,\r\n callback: (modification: Change) => void,\r\n context: SandboxExec | IExecContext,\r\n ): { unsubscribe: () => void } {\r\n return subscribeSet(obj, name, callback, context);\r\n }\r\n\r\n subscribeSetGlobal(\r\n obj: SubscriptionSubject,\r\n name: string,\r\n callback: (modification: Change) => void,\r\n ): { unsubscribe: () => void } {\r\n return subscribeSet(obj, name, callback, this);\r\n }\r\n\r\n subscribeHalt(\r\n cb: (args?: { error: Error; ticks: Ticks; scope: Scope; context: IExecContext }) => void,\r\n ) {\r\n this.haltSubscriptions.add(cb);\r\n return {\r\n unsubscribe: () => {\r\n this.haltSubscriptions.delete(cb);\r\n },\r\n };\r\n }\r\n subscribeResume(cb: () => void) {\r\n this.resumeSubscriptions.add(cb);\r\n return {\r\n unsubscribe: () => {\r\n this.resumeSubscriptions.delete(cb);\r\n },\r\n };\r\n }\r\n\r\n haltExecution(haltContext?: { error: Error; ticks: Ticks; scope: Scope; context: IExecContext }) {\r\n if (this.halted) return;\r\n this.halted = true;\r\n for (const cb of this.haltSubscriptions) {\r\n cb(haltContext);\r\n }\r\n }\r\n\r\n resumeExecution() {\r\n if (!this.halted) return;\r\n if (this.context.ticks.tickLimit && this.context.ticks.ticks >= this.context.ticks.tickLimit) {\r\n throw new SandboxExecutionQuotaExceededError('Cannot resume execution: tick limit exceeded');\r\n }\r\n this.halted = false;\r\n for (const cb of this.resumeSubscriptions) {\r\n cb();\r\n }\r\n }\r\n\r\n getContext(fn: (...args: any[]) => any) {\r\n return this.sandboxFunctions.get(fn);\r\n }\r\n\r\n executeTree<T>(context: IExecContext, scopes: IScope[] = []): ExecReturn<T> {\r\n return executeTree(context.ctx.ticks, context, context.tree, scopes);\r\n }\r\n\r\n executeTreeAsync<T>(context: IExecContext, scopes: IScope[] = []): Promise<ExecReturn<T>> {\r\n return executeTreeAsync(context.ctx.ticks, context, context.tree, scopes);\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;AA6BA,SAAS,YAAY,CACnB,GAAW,EACX,IAAY,EACZ,QAAwC,EACxC,OAMC,EAAA;AAED,IAAA,MAAM,KAAK,GACT,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,EAA+C;IAC7F,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;AACxC,IAAA,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EA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AAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;IACtC;AAEA,IAAA,WAAW,CAAI,OAAqB,EAAE,MAAA,GAAmB,EAAE,EAAA;AACzD,QAAA,OAAO,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;IACtE;AAEA,IAAA,gBAAgB,CAAI,OAAqB,EAAE,MAAA,GAAmB,EAAE,EAAA;AAC9D,QAAA,OAAO,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;IAC3E;AACD;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.getPrototypeOf(async function(){}).constructor,Object.getPrototypeOf(function*(){}).constructor,Object.getPrototypeOf(async function*(){}).constructor;const t=function(t){for(const e in t)this[e]=t[e]};class e{constructor(t){this.ref={str:""},t instanceof e?(this.ref=t.ref,this.start=t.start,this.end=t.end):(this.ref.str=t,this.start=0,this.end=t.length)}substring(t,o){if(!this.length)return this;(t=this.start+t)<0&&(t=0),t>this.end&&(t=this.end),(o=void 0===o?this.end:this.start+o)<0&&(o=0),o>this.end&&(o=this.end);const n=new e(this);return n.start=t,n.end=o,n}get length(){const t=this.end-this.start;return t<0?0:t}char(t){if(this.start!==this.end)return this.ref.str[this.start+t]}toString(){return this.ref.str.substring(this.start,this.end)}trimStart(){const t=/^\s+/.exec(this.toString()),o=new e(this);return t&&(o.start+=t[0].length),o}slice(t,e){return t<0&&(t=this.end-this.start+t),t<0&&(t=0),void 0===e&&(e=this.end-this.start),e<0&&(e=this.end-this.start+e),e<0&&(e=0),this.substring(t,e)}trim(){const t=this.trimStart(),e=/\s+$/.exec(t.toString());return e&&(t.end-=e[0].length),t}valueOf(){return this.toString()}}function o(t){const e=Object.assign({},t);for(const t in e)e[t]=!0;return e}const n=new Set(["await","break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","false","finally","for","function","if","implements","import","in","instanceof","let","new","null","return","super","switch","this","throw","true","try","typeof","var","void","while","with"]);class r{constructor(t,e={},n){this.const={},this.let={},this.var={};const r=void 0!==n||null===t;this.parent=t,this.allVars=e,this.let=r?this.let:o(e),this.var=r?o(e):this.var,this.globals=null===t?o(e):{},this.functionThis=n}get(t){const e="this"===t,o=this.getWhereValScope(t,e);return o&&e?new u({this:o.functionThis},t,!1,!1,!0):o?new u(o.allVars,t,t in o.const,t in o.globals,!0):new u(void 0,t)}set(t,e){if("this"===t)throw new SyntaxError('"this" cannot be assigned');if(n.has(t))throw new SyntaxError("Unexepected token '"+t+"'");const o=this.get(t);if(void 0===o.context)throw new ReferenceError(`Variable '${t}' was not declared.`);if(null===o.context)throw new TypeError(`Cannot set properties of null, (setting '${t}')`);if(o.isConst)throw new TypeError("Assignment to constant variable");if(o.isGlobal)throw new s(`Cannot override global variable '${t}'`);return o.context[o.prop]=e,o}getWhereValScope(t,e){return e?void 0!==this.functionThis?this:this.parent?.getWhereValScope(t,e)||null:!(t in this.allVars)||t in{}&&!f(this.allVars,t)?this.parent?.getWhereValScope(t,e)||null:this}getWhereVarScope(t,e=!1){return!(t in this.allVars)||t in{}&&!f(this.allVars,t)?null===this.parent||e||void 0!==this.functionThis?this:this.parent.getWhereVarScope(t,e):this}declare(t,e,o=void 0,r=!1){if("this"===t)throw new SyntaxError('"this" cannot be declared');if(n.has(t))throw new SyntaxError("Unexepected token '"+t+"'");const i=this.getWhereVarScope(t,"var"!==e);if("var"===e){if(i.var[t])return i.allVars[t]=o,r?i.globals[t]=!0:delete i.globals[t],new u(i.allVars,t,!1,i.globals[t],!0);if(t in i.allVars)throw new SyntaxError(`Identifier '${t}' has already been declared`)}if(t in i.allVars)throw new SyntaxError(`Identifier '${t}' has already been declared`);return r&&(i.globals[t]=!0),i[e][t]=!0,i.allVars[t]=o,new u(this.allVars,t,"const"===e,r,!0)}}class i{}class s extends Error{}class c extends s{}class a extends s{}class d extends s{}class p extends s{}function l(t){return Array.isArray(t)&&"number"==typeof t[0]&&0!==t[0]&&88!==t[0]}class u{constructor(t,e,o=!1,n=!1,r=!1){this.context=t,this.prop=e,this.isConst=o,this.isGlobal=n,this.isVariable=r}get(t){const e=this.context;if(void 0===e)throw new ReferenceError(`${this.prop.toString()} is not defined`);if(null===e)throw new TypeError(`Cannot read properties of null, (reading '${this.prop.toString()}')`);return t.getSubscriptions.forEach(t=>t(e,this.prop.toString())),e[this.prop]}}function f(t,e){return Object.prototype.hasOwnProperty.call(t,e)}class h{constructor(t,e,o,n=!1,r=!1){this.auditReport=t,this.result=e,this.returned=o,this.breakLoop=n,this.continueLoop=r}}const b={};function v(t,e){const o={};return t.forEach((t,n)=>{t.startsWith("...")?o[t.substring(3)]=e.slice(n):o[t]=e[n]}),o}function x(t,e,o,n,i,s){if(n.ctx.options.forbidFunctionCreation)throw new d("Function creation is forbidden");let c;return c=void 0===s?(...s)=>{const c=v(t,s);return M(o,n,e,void 0===i?[]:[new r(i,c)]).result}:function(...s){const c=v(t,s);return M(o,n,e,void 0===i?[]:[new r(i,c,this)]).result},n.registerSandboxFunction(c),n.ctx.sandboxedFunctions.add(c),c}function w(t,e,o,n,i,s){if(n.ctx.options.forbidFunctionCreation)throw new d("Function creation is forbidden");if(!n.ctx.prototypeWhitelist?.has(Promise.prototype))throw new d("Async/await not permitted");let c;return c=void 0===s?async(...s)=>{const c=v(t,s);return(await _(o,n,e,void 0===i?[]:[new r(i,c)])).result}:async function(...s){const c=v(t,s);return(await _(o,n,e,void 0===i?[]:[new r(i,c,this)])).result},n.registerSandboxFunction(c),n.ctx.sandboxedFunctions.add(c),c}function y(t,e,o="assign"){if(void 0===t.context)throw new ReferenceError(`Cannot ${o} value to undefined.`);if(t.isConst)throw new TypeError("Assignment to constant variable.");if(t.isGlobal)throw new p(`Cannot ${o} property '${t.prop.toString()}' of a global object`);if(null===t.context)throw new TypeError("Cannot set properties of null");if("function"==typeof t.context[t.prop]&&!f(t.context,t.prop))throw new p(`Override prototype property '${t.prop.toString()}' not allowed`);"delete"===o?f(t.context,t.prop)&&(e.changeSubscriptions.get(t.context)?.forEach(e=>e({type:"delete",prop:t.prop.toString()})),e.changeSubscriptionsGlobal.get(t.context)?.forEach(e=>e({type:"delete",prop:t.prop.toString()}))):f(t.context,t.prop)?(e.setSubscriptions.get(t.context)?.get(t.prop.toString())?.forEach(t=>t({type:"replace"})),e.setSubscriptionsGlobal.get(t.context)?.get(t.prop.toString())?.forEach(t=>t({type:"replace"}))):(e.changeSubscriptions.get(t.context)?.forEach(e=>e({type:"create",prop:t.prop.toString()})),e.changeSubscriptionsGlobal.get(t.context)?.forEach(e=>e({type:"create",prop:t.prop.toString()})))}const g=new Set([[].push,[].pop,[].shift,[].unshift,[].splice,[].reverse,[].sort,[].copyWithin]);class S{constructor(t,e){this.key=t,this.val=e}}class m{constructor(t){this.item=t}}class E{constructor(t){this.item=t}}class k{constructor(t,e){this.t=t,this.f=e}}const j=/(\$\$)*(\$)?\${(\d+)}/g,A=new Map;function R(t,e){A.set(t,e)}const I=["string","number","symbol"];function O(t,e,o){if(!t)return;const n="function"==typeof t;t instanceof u&&(o||(o=t),t=t.get(e));const r=o?.prop||"prop";if(t===globalThis)return new u({[r]:e.ctx.sandboxGlobal},r,o?.isConst||!1,!1,o?.isVariable||!1);const i=n&&e.evals.get(t);return i?new u({[r]:i},r,o?.isConst||!1,!0,o?.isVariable||!1):void 0}function W(t,e,o=new WeakSet){if(!Array.isArray(t))return t;if(o.has(t))return t;o.add(t);for(let n=0;n<t.length;n++){const r=t[n];if(r===globalThis)t[n]=e.ctx.sandboxGlobal;else if("function"==typeof r){const o=e.evals.get(r);o&&(t[n]=o)}else W(r,e,o)}return t}function F(t,e){return t instanceof u?t.get(e):t!==b?t:void 0}function C(t,e,o,n,r,i,s){e===U?function(t,e,o,n,r,i){const s=[];for(let c=0;c<e.length;c++){let a=T(o=>U(t,e[c],n,r,o,i)).result;if(a instanceof h&&(a.returned||a.breakLoop||a.continueLoop))return void o(void 0,a);if(l(e[c])&&8===e[c][0])return void o(void 0,new h(r.ctx.auditReport,a,!0));s.push(a)}o(void 0,s)}(t,o,n,r,i,s):async function(t,e,o,n,r,i){const s=[];for(let c=0;c<e.length;c++){let a;try{let o;a=!0===(o=$(o=>L(t,e[c],n,r,o,i))).isInstant?o.instant:(await o.p).result}catch(t){return void o(t)}if(a instanceof h&&(a.returned||a.breakLoop||a.continueLoop))return void o(void 0,a);if(l(e[c])&&8===e[c][0])return void o(void 0,new h(r.ctx.auditReport,a,!0));s.push(a)}o(void 0,s)}(t,o,n,r,i,s).catch(n)}function $(t){let e,o=!1;const n=new Promise((n,r)=>{t((...t)=>{1===t.length?r(t[0]):(o=!0,e=t[1],n({result:t[1]}))})});return{isInstant:o,instant:e,p:n}}function T(t){let e,o;if(t((...t)=>{o=1===t.length?{error:t[0]}:void 0,e=t[1]}),o)throw o.error;return{result:e}}async function L(t,e,o,n,r,i){let s=r;const c=new Promise(t=>{s=(...e)=>{r(...e),t()}});if(!G(t,e,o,n,s,!0,i)&&l(e)){let r,c=e[0];try{let s;r=!0===(s=$(r=>L(t,e[1],o,n,r,i))).isInstant?s.instant:(await s.p).result}catch(t){return void s(t)}let a,d=r;try{d=r instanceof u?r.get(n):r}catch(t){return void s(t)}if(20===c||21===c){if(null==d)return void s(void 0,b);c=20===c?1:5}if(d===b){if(1===c||5===c)return void s(void 0,d);d=void 0}if(89===c&&null!=d)return void s(void 0,d);try{let r;a=!0===(r=$(r=>L(t,e[2],o,n,r,i))).isInstant?r.instant:(await r.p).result}catch(t){return void s(t)}let p=a;try{p=a instanceof u?a.get(n):a}catch(t){return void s(t)}p===b&&(p=void 0),P({op:c,exec:L,done:s,ticks:t,a:d,b:p,obj:r,context:n,scope:o,bobj:a,inLoopOrSwitch:i,tree:e})}await c}function U(t,e,o,n,r,i){if(!G(t,e,o,n,r,!1,i)&&l(e)){let s=e[0],c=T(r=>U(t,e[1],o,n,r,i)).result,a=c instanceof u?c.get(n):c;if(20===s||21===s){if(null==a)return void r(void 0,b);s=20===s?1:5}if(a===b){if(1===s||5===s)return void r(void 0,a);a=void 0}if(89===s&&null!=a)return void r(void 0,a);let d=T(r=>U(t,e[2],o,n,r,i)).result,p=d instanceof u?d.get(n):d;p===b&&(p=void 0),P({op:s,exec:U,done:r,ticks:t,a:a,b:p,obj:c,context:n,scope:o,bobj:d,inLoopOrSwitch:i,tree:e})}}function P(t){const{done:e,op:o,ticks:n,context:r,scope:i}=t;n.ticks++;const d=r.ctx.sandbox;if(!function(t,e=0){const o=t.context.ctx.sandbox,n=t.context.ctx.options,{ticks:r,scope:i,context:a,done:d,op:p}=t;if(o.halted){const e=o.subscribeResume(()=>{e.unsubscribe();try{const e=A.get(p);if(!e)return void d(new SyntaxError("Unknown operator: "+p));e(t)}catch(t){if(n.haltOnSandboxError&&t instanceof s){const e=o.subscribeResume(()=>{e.unsubscribe(),d(t)});o.haltExecution({error:t,ticks:r,scope:i,context:a})}else d(t)}});return!0}if(r.tickLimit&&r.tickLimit<=r.ticks+BigInt(e)){const e=o.subscribeResume(()=>{e.unsubscribe();try{const e=A.get(p);if(!e)return void d(new SyntaxError("Unknown operator: "+p));e(t)}catch(t){if(a.ctx.options.haltOnSandboxError&&t instanceof s){const e=o.subscribeResume(()=>{e.unsubscribe(),d(t)});o.haltExecution({error:t,ticks:r,scope:i,context:a})}else d(t)}}),n=new c("Execution quota exceeded");return o.haltExecution({error:n,ticks:r,scope:i,context:a}),!0}return!1}(t))try{const n=A.get(o);if(!n)return void e(new a("Unknown operator: "+o));n(t)}catch(t){if(r.ctx.options.haltOnSandboxError&&t instanceof s){const o=d.subscribeResume(()=>{o.unsubscribe(),e(t)});d.haltExecution({error:t,ticks:n,scope:i,context:r})}else e(t)}}R(1,({done:t,a:e,b:o,obj:n,context:r,scope:i})=>{if(null===e)throw new TypeError(`Cannot read properties of null (reading '${o?.toString()}')`);if(function(t){return I.includes(typeof t)}(o)||(o=`${o}`),void 0===e&&void 0===n&&"string"==typeof o){const e=i.get(o);e.context===r.ctx.sandboxGlobal&&r.ctx.options.audit&&r.ctx.auditReport?.globalsAccess.add(o);return void t(void 0,O(e.context?e.context[e.prop]:void 0,r,e)||e)}if(void 0===e)throw new TypeError(`Cannot read properties of undefined (reading '${o.toString()}')`);if(!function(t){return null!=t}(e))return void t(void 0,new u(void 0,o));const s="function"==typeof e||!f(e,o);if(r.ctx.options.audit&&s){let t=Object.getPrototypeOf(e);do{f(t,o)&&(r.ctx.auditReport&&!r.ctx.auditReport.prototypeAccess[t.constructor.name]&&(r.ctx.auditReport.prototypeAccess[t.constructor.name]=new Set),r.ctx.auditReport?.prototypeAccess[t.constructor.name].add(o))}while(t=Object.getPrototypeOf(t))}if(s){if("function"==typeof e&&f(e,o)){const n=r.ctx.prototypeWhitelist.get(e.prototype),i=r.ctx.options.prototypeReplacements.get(e);if(i)return void t(void 0,new u(i(e,!0),o));if((!n||n.size&&!n.has(o))&&!r.ctx.sandboxedFunctions.has(e))throw new p(`Static method or property access not permitted: ${e.name}.${o.toString()}`)}if(f(e,o)){const n=r.ctx.options.prototypeReplacements.get(e);if(n)return void t(void 0,new u(n(e,!0),o));if(r.ctx.sandboxedFunctions.has(e))return void t(void 0,new u(e,o,!1,!1));let i=e.prototype;for(;null!==i;){const n=r.ctx.prototypeWhitelist.get(i);if(n&&(!n.size||n.has(o)))return void t(void 0,new u(e,o,!1,!1));i=Object.getPrototypeOf(i)}if("function"==typeof e)throw new p(`Method or property access not permitted: ${e.name}.${o.toString()}`)}let n=e;for(;n=Object.getPrototypeOf(n);)if(f(n,o)||"__proto__"===o){const i=r.ctx.options.prototypeReplacements.get(n.constructor);if(i)return void t(void 0,new u(i(e,!1),o));if(r.ctx.sandboxedFunctions.has(n.constructor))break;let s=n.constructor,c=!1;for(;null!==s;){const t=r.ctx.prototypeWhitelist.get(s);if(t&&(!t.size||t.has(o))){c=!0;break}s=Object.getPrototypeOf(s)}if(c)break;if("__proto__"===o)throw new p("Access to prototype of global object is not permitted");throw new p(`Method or property access not permitted: ${n.constructor.name}.${o.toString()}`)}}const c=e[o];if("function"==typeof e&&"prototype"===o&&!r.ctx.sandboxedFunctions.has(e))throw new p("Access to prototype of global object is not permitted");if("__proto__"===o&&!r.ctx.sandboxedFunctions.has(c?.constructor))throw new p("Access to prototype of global object is not permitted");const a=O(c,r,new u(e,o,!1,!1));if(a)return void t(void 0,a);const d=n instanceof u&&n.isGlobal||"function"==typeof e&&!r.ctx.sandboxedFunctions.has(e)||r.ctx.globalsWhitelist.has(e);t(void 0,new u(e,o,!1,d,!1))}),R(5,({done:t,a:e,b:o,obj:n,context:r})=>{if(r.ctx.options.forbidFunctionCalls)throw new d("Function invocations are not allowed");if("function"!=typeof e)throw new TypeError(`${"symbol"==typeof n?.prop?"Symbol":n?.prop} is not a function`);const i=o.map(t=>t instanceof E?[...t.item]:[t]).flat().map(t=>F(t,r));if("function"==typeof n){const e=r.evals.get(n);let o=e?e(n,...i):n(...i);return o=O(o,r)||o,W(o,r),void t(void 0,o)}if(n.context[n.prop]===JSON.stringify&&r.getSubscriptions.size){const t=new Set,e=o=>{if(o&&"object"==typeof o&&!t.has(o)){t.add(o);for(const t of Object.keys(o))r.getSubscriptions.forEach(e=>e(o,t)),e(o[t])}};e(i[0])}if(n.context instanceof Array&&g.has(n.context[n.prop])&&(r.changeSubscriptions.get(n.context)||r.changeSubscriptionsGlobal.get(n.context))){let t,e=!1;if("push"===n.prop)t={type:"push",added:i},e=!!i.length;else if("pop"===n.prop)t={type:"pop",removed:n.context.slice(-1)},e=!!t.removed.length;else if("shift"===n.prop)t={type:"shift",removed:n.context.slice(0,1)},e=!!t.removed.length;else if("unshift"===n.prop)t={type:"unshift",added:i},e=!!i.length;else if("splice"===n.prop)t={type:"splice",startIndex:i[0],deleteCount:void 0===i[1]?n.context.length:i[1],added:i.slice(2),removed:n.context.slice(i[0],void 0===i[1]?void 0:i[0]+i[1])},e=!!t.added.length||!!t.removed.length;else if("reverse"===n.prop||"sort"===n.prop)t={type:n.prop},e=!!n.context.length;else if("copyWithin"===n.prop){const o=void 0===i[2]?n.context.length-i[1]:Math.min(n.context.length,i[2]-i[1]);t={type:"copyWithin",startIndex:i[0],endIndex:i[0]+o,added:n.context.slice(i[1],i[1]+o),removed:n.context.slice(i[0],i[0]+o)},e=!!t.added.length||!!t.removed.length}e&&(r.changeSubscriptions.get(n.context)?.forEach(e=>e(t)),r.changeSubscriptionsGlobal.get(n.context)?.forEach(e=>e(t)))}n.get(r);const s=r.evals.get(n.context[n.prop]);let c=s?s(n.context[n.prop],...i):n.context[n.prop](...i);c=O(c,r)||c,W(c,r),t(void 0,c)}),R(22,({done:t,b:e})=>{let o={};for(const t of e)t.key instanceof m?o={...o,...t.key.item}:o[t.key]=t.val;t(void 0,o)}),R(6,({done:t,a:e,b:o})=>t(void 0,new S(e,o))),R(12,({done:t,b:e,context:o})=>{t(void 0,e.map(t=>t instanceof E?[...t.item]:[t]).flat().map(t=>F(t,o)))}),R(23,({done:t,b:e})=>t(void 0,e)),R(35,({done:t,b:e})=>{switch(e){case"true":return t(void 0,!0);case"false":return t(void 0,!1);case"null":return t(void 0,null);case"undefined":return t(void 0,void 0);case"NaN":return t(void 0,NaN);case"Infinity":return t(void 0,1/0)}t(new Error("Unknown symbol: "+e))}),R(7,({done:t,b:e})=>t(void 0,Number(e.replace(/_/g,"")))),R(83,({done:t,b:e})=>t(void 0,BigInt(e.replace(/_/g,"")))),R(2,({done:t,b:e,context:o})=>t(void 0,o.constants.strings[parseInt(e)])),R(85,({done:t,b:e,context:o})=>{const n=o.constants.regexes[parseInt(e)];if(!o.ctx.globalsWhitelist.has(RegExp))throw new d("Regex not permitted");t(void 0,new RegExp(n.regex,n.flags))}),R(84,({exec:t,done:e,ticks:o,b:n,context:r,scope:i})=>{const s=r.constants.literals[parseInt(n)],[,c,a]=s,d=[];let p;const l=[];for(;p=j.exec(c);)p[2]||(d.push(a[parseInt(p[3],10)]),l.push(p[3]));t(o,d,i,r,(...t)=>{const o={};if(1===t.length)return void e(t[0]);const n=t[1];for(const t of Object.keys(n)){const e=l[t];o[e]=n[t]}e(void 0,c.replace(/(\\\\)*(\\)?\${(\d+)}/g,(t,e,n,i)=>{if(n)return t;return(e||"")+`${F(o[i],r)}`}))})}),R(18,({done:t,b:e})=>{t(void 0,new E(e))}),R(17,({done:t,b:e})=>{t(void 0,new m(e))}),R(24,({done:t,b:e})=>t(void 0,!e)),R(64,({done:t,b:e})=>t(void 0,~e)),R(25,({done:t,obj:e,context:o})=>{y(e,o),t(void 0,++e.context[e.prop])}),R(26,({done:t,obj:e,context:o})=>{y(e,o),t(void 0,e.context[e.prop]++)}),R(27,({done:t,obj:e,context:o})=>{y(e,o),t(void 0,--e.context[e.prop])}),R(28,({done:t,obj:e,context:o})=>{y(e,o),t(void 0,e.context[e.prop]--)}),R(9,({done:t,b:e,obj:o,context:n,scope:r,bobj:i})=>{if(y(o,n),o.isGlobal=i?.isGlobal||!1,o.isVariable){const n=r.getWhereValScope(o.prop,"this"===o.prop);if(null===n)throw new ReferenceError(`Cannot assign to undeclared variable '${o.prop.toString()}'`);return n.set(o.prop,e),o.isGlobal?n.globals[o.prop.toString()]=!0:delete n.globals[o.prop.toString()],void t(void 0,e)}t(void 0,o.context[o.prop]=e)}),R(66,({done:t,b:e,obj:o,context:n})=>{y(o,n),t(void 0,o.context[o.prop]+=e)}),R(65,({done:t,b:e,obj:o,context:n})=>{y(o,n),t(void 0,o.context[o.prop]-=e)}),R(67,({done:t,b:e,obj:o,context:n})=>{y(o,n),t(void 0,o.context[o.prop]/=e)}),R(69,({done:t,b:e,obj:o,context:n})=>{y(o,n),t(void 0,o.context[o.prop]*=e)}),R(68,({done:t,b:e,obj:o,context:n})=>{y(o,n),t(void 0,o.context[o.prop]**=e)}),R(70,({done:t,b:e,obj:o,context:n})=>{y(o,n),t(void 0,o.context[o.prop]%=e)}),R(71,({done:t,b:e,obj:o,context:n})=>{y(o,n),t(void 0,o.context[o.prop]^=e)}),R(72,({done:t,b:e,obj:o,context:n})=>{y(o,n),t(void 0,o.context[o.prop]&=e)}),R(73,({done:t,b:e,obj:o,context:n})=>{y(o,n),t(void 0,o.context[o.prop]|=e)}),R(76,({done:t,b:e,obj:o,context:n})=>{y(o,n),t(void 0,o.context[o.prop]<<=e)}),R(75,({done:t,b:e,obj:o,context:n})=>{y(o,n),t(void 0,o.context[o.prop]>>=e)}),R(74,({done:t,b:e,obj:o,context:n})=>{y(o,n),t(void 0,o.context[o.prop]>>>=e)}),R(90,({done:t,b:e,obj:o,context:n})=>{var r,i;y(o,n),t(void 0,(r=o.context)[i=o.prop]&&(r[i]=e))}),R(91,({done:t,b:e,obj:o,context:n})=>{var r,i;y(o,n),t(void 0,(r=o.context)[i=o.prop]||(r[i]=e))}),R(92,({done:t,b:e,obj:o,context:n})=>{var r,i;y(o,n),t(void 0,(r=o.context)[i=o.prop]??(r[i]=e))}),R(57,({done:t,a:e,b:o})=>t(void 0,e>o)),R(56,({done:t,a:e,b:o})=>t(void 0,e<o)),R(55,({done:t,a:e,b:o})=>t(void 0,e>=o)),R(54,({done:t,a:e,b:o})=>t(void 0,e<=o)),R(52,({done:t,a:e,b:o})=>t(void 0,e==o)),R(32,({done:t,a:e,b:o})=>t(void 0,e===o)),R(53,({done:t,a:e,b:o})=>t(void 0,e!=o)),R(31,({done:t,a:e,b:o})=>t(void 0,e!==o)),R(29,({done:t,a:e,b:o})=>t(void 0,e&&o)),R(30,({done:t,a:e,b:o})=>t(void 0,e||o)),R(89,({done:t,a:e,b:o})=>t(void 0,e??o)),R(77,({done:t,a:e,b:o})=>t(void 0,e&o)),R(78,({done:t,a:e,b:o})=>t(void 0,e|o)),R(33,({done:t,a:e,b:o})=>t(void 0,e+o)),R(47,({done:t,a:e,b:o})=>t(void 0,e-o)),R(59,({done:t,b:e})=>t(void 0,+e)),R(58,({done:t,b:e})=>t(void 0,-e)),R(48,({done:t,a:e,b:o})=>t(void 0,e/o)),R(49,({done:t,a:e,b:o})=>t(void 0,e**o)),R(79,({done:t,a:e,b:o})=>t(void 0,e^o)),R(50,({done:t,a:e,b:o})=>t(void 0,e*o)),R(51,({done:t,a:e,b:o})=>t(void 0,e%o)),R(80,({done:t,a:e,b:o})=>t(void 0,e<<o)),R(81,({done:t,a:e,b:o})=>t(void 0,e>>o)),R(82,({done:t,a:e,b:o})=>t(void 0,e>>>o)),R(60,({exec:t,done:e,ticks:o,b:n,context:r,scope:i})=>{t(o,n,i,r,(t,o)=>{e(void 0,typeof F(o,r))})}),R(62,({done:t,a:e,b:o})=>t(void 0,e instanceof o)),R(63,({done:t,a:e,b:o})=>t(void 0,e in o)),R(61,({done:t,context:e,bobj:o})=>{o instanceof u?(y(o,e,"delete"),o.isVariable?t(void 0,!1):t(void 0,delete o.context?.[o.prop])):t(void 0,!0)}),R(8,({done:t,b:e})=>t(void 0,e)),R(34,({done:t,a:e,b:o,scope:n,bobj:r})=>{t(void 0,n.declare(e,"var",o,r?.isGlobal||!1))}),R(3,({done:t,a:e,b:o,scope:n,bobj:r})=>{t(void 0,n.declare(e,"let",o,r?.isGlobal||!1))}),R(4,({done:t,a:e,b:o,scope:n,bobj:r})=>{t(void 0,n.declare(e,"const",o,r?.isGlobal||!1))}),R(11,({done:t,ticks:o,a:n,b:r,obj:i,context:s,scope:c})=>{if(n=[...n],"string"==typeof i[2]||i[2]instanceof e){if(!s.allowJit||!s.evalContext)throw new d("Unevaluated code detected, JIT not allowed");i[2]=r=s.evalContext.lispifyFunction(new e(i[2]),s.constants)}n.shift()?t(void 0,w(n,r,o,s,c)):t(void 0,x(n,r,o,s,c))}),R(37,({done:t,ticks:o,a:n,b:r,obj:i,context:s,scope:c})=>{if("string"==typeof i[2]||i[2]instanceof e){if(!s.allowJit||!s.evalContext)throw new d("Unevaluated code detected, JIT not allowed");i[2]=r=s.evalContext.lispifyFunction(new e(i[2]),s.constants)}const a=n.shift(),p=n.shift();let l;l=88===a?w(n,r,o,s,c,p):x(n,r,o,s,c,p),p&&c.declare(p,"var",l),t(void 0,l)}),R(10,({done:t,ticks:o,a:n,b:i,obj:s,context:c,scope:a})=>{if("string"==typeof s[2]||s[2]instanceof e){if(!c.allowJit||!c.evalContext)throw new d("Unevaluated code detected, JIT not allowed");s[2]=i=c.evalContext.lispifyFunction(new e(s[2]),c.constants)}const p=n.shift(),l=n.shift();let u;l&&(a=new r(a,{})),u=88===p?w(n,i,o,c,a,l):x(n,i,o,c,a,l),l&&a.declare(l,"let",u),t(void 0,u)}),R(38,({exec:t,done:e,ticks:o,a:n,b:i,context:s,scope:c})=>{const[a,d,p,l,u,f,b]=n;let v=!0;const x=new r(c,{}),w={$$obj:void 0},y=new r(x,w);if(t===L)(async()=>{let n;for(n=$(e=>t(o,l,x,s,e)),w.$$obj=!0===(n=$(e=>t(o,p,x,s,e))).isInstant?n.instant:(await n.p).result,n=$(e=>t(o,d,y,s,e)),a&&(v=!0===(n=$(e=>t(o,f,y,s,e))).isInstant?n.instant:(await n.p).result);v;){const c={};n=$(e=>t(o,b,new r(y,c),s,e)),!0===n.isInstant?n.instant:(await n.p).result;const a=await _(o,s,i,[new r(x,c)],"loop");if(a instanceof h&&a.returned)return void e(void 0,a);if(a instanceof h&&a.breakLoop)break;n=$(e=>t(o,u,y,s,e)),v=!0===(n=$(e=>t(o,f,y,s,e))).isInstant?n.instant:(await n.p).result}e()})().catch(e);else{for(T(e=>t(o,l,x,s,e)),w.$$obj=T(e=>t(o,p,x,s,e)).result,T(e=>t(o,d,y,s,e)),a&&(v=T(e=>t(o,f,y,s,e)).result);v;){const n={};T(e=>t(o,b,new r(y,n),s,e));const c=M(o,s,i,[new r(x,n)],"loop");if(c instanceof h&&c.returned)return void e(void 0,c);if(c instanceof h&&c.breakLoop)break;T(e=>t(o,u,y,s,e)),v=T(e=>t(o,f,y,s,e)).result}e()}}),R(86,({done:t,a:e,context:o,inLoopOrSwitch:n})=>{if("switch"===n&&"continue"===e||!n)throw new TypeError("Illegal "+e+" statement");t(void 0,new h(o.ctx.auditReport,void 0,!1,"break"===e,"continue"===e))}),R(13,({exec:t,done:e,ticks:o,a:n,b:r,context:i,scope:s,inLoopOrSwitch:c})=>{t(o,F(n,i)?r.t:r.f,s,i,e,c)}),R(15,({exec:t,done:e,ticks:o,a:n,b:r,context:i,scope:s})=>{t(o,F(n,i)?r.t:r.f,s,i,e,void 0)}),R(16,({done:t,a:e,b:o})=>t(void 0,new k(e,o))),R(14,({done:t,a:e,b:o})=>t(void 0,new k(e,o))),R(40,({exec:t,done:e,ticks:o,a:n,b:r,context:i,scope:s})=>{t(o,n,s,i,(...n)=>{if(1===n.length)return void e(n[0]);let c=n[1];if(c=F(c,i),t===U){let n,a=!1;for(const d of r)if(a||(a=!d[1]||c===F(T(e=>t(o,d[1],s,i,e)).result,i))){if(!d[2])continue;if(n=M(o,i,d[2],[s],"switch"),n.breakLoop)break;if(n.returned)return void e(void 0,n);if(!d[1])break}e()}else(async()=>{let n,a=!1;for(const d of r){let r;if(a||(a=!d[1]||c===F(!0===(r=$(e=>t(o,d[1],s,i,e))).isInstant?r.instant:(await r.p).result,i))){if(!d[2])continue;if(n=await _(o,i,d[2],[s],"switch"),n.breakLoop)break;if(n.returned)return void e(void 0,n);if(!d[1])break}}e()})().catch(e)})}),R(39,({exec:t,done:e,ticks:o,a:n,b:i,context:s,scope:c,inLoopOrSwitch:a})=>{const[d,p,l]=i;N(t,(...n)=>{const i=1===n.length,u=i?n[0]:void 0,f=!i&&n.length>1?n[1]:void 0,b=(n,i)=>{l&&l.length>0?N(t,(...t)=>{const o=1===t.length,r=!o&&t.length>1?t[1]:void 0;o?e(t[0]):r instanceof h&&(r.returned||r.breakLoop||r.continueLoop)?e(void 0,r):n?e(i):i instanceof h&&(i.returned||i.breakLoop||i.continueLoop)?e(void 0,i):e()},o,s,l,[new r(c,{})],a):n?e(i):i instanceof h&&(i.returned||i.breakLoop||i.continueLoop)?e(void 0,i):e()};if(i&&p&&p.length>0){const e={};d&&(e[d]=u),N(t,(...t)=>{const e=1===t.length,o=e?t[0]:t.length>1?t[1]:void 0;b(e,o)},o,s,p,[new r(c,e)],a)}else b(i,i?u:f)},o,s,n,[new r(c)],a)}),R(87,({done:t})=>{t()}),R(45,({done:t,a:e,b:o,context:n})=>{if(!n.ctx.globalsWhitelist.has(e)&&!n.ctx.sandboxedFunctions.has(e))throw new p(`Object construction not allowed: ${e.constructor.name}`);t(void 0,new e(...o))}),R(46,({done:t,b:e})=>{t(e)}),R(43,({done:t,a:e})=>t(void 0,e.pop())),R(0,({done:t})=>t());const V=new Set([11,37,10,38,39,40,14,16,60]);function G(t,e,o,n,r,i,s){const c=i?L:U;if(e instanceof u)r(void 0,e.get(n));else if(e===b)r();else if(Array.isArray(e)&&!l(e))0===e[0]?r():C(t,c,e,r,o,n,s);else if(l(e))if(42===e[0])C(t,c,e[1],r,o,n,s);else if(44===e[0])i?n.ctx.prototypeWhitelist?.has(Promise.prototype)?L(t,e[1],o,n,async(...t)=>{if(1===t.length)r(t[0]);else try{r(void 0,await F(t[1],n))}catch(t){r(t)}},s).catch(r):r(new d("Async/await is not permitted")):r(new SyntaxError("Illegal use of 'await', must be inside async function"));else{if(!V.has(e[0]))return!1;P({op:e[0],exec:c,done:r,ticks:t,a:e[1],b:e[2],obj:e,tree:e,context:n,scope:o,bobj:void 0,inLoopOrSwitch:s})}else r(void 0,e);return!0}function M(t,e,o,n=[],r){return T(i=>N(U,i,t,e,o,n,r)).result}async function _(t,e,o,n=[],r){let i;return!0===(i=$(i=>N(L,i,t,e,o,n,r))).isInstant?i.instant:(await i.p).result}function N(t,e,o,n,s,c=[],a){if(!s)return void e();if(!(s instanceof Array))throw new SyntaxError("Bad execution tree");let d,p=n.ctx.globalScope;for(;d=c.shift();)"object"==typeof d&&(p=d instanceof r?d:new r(p,d,d instanceof i?void 0:null));n.ctx.options.audit&&!n.ctx.auditReport&&(n.ctx.auditReport={globalsAccess:new Set,prototypeAccess:{}}),t===U?function(t,e,o,n,r,i){if(!(n instanceof Array))throw new SyntaxError("Bad execution tree");let s=0;for(s=0;s<n.length;s++){let c,a;const d=n[s];try{U(e,d,r,o,(...t)=>{1===t.length?a={error:t[0]}:c=t[1]},i)}catch(t){a={error:t}}if(a)return void t(a.error);if(c instanceof h)return void t(void 0,c);if(l(d)&&8===d[0])return void t(void 0,new h(o.ctx.auditReport,c,!0))}t(void 0,new h(o.ctx.auditReport,void 0,!1))}(e,o,n,s,p,a):async function(t,e,o,n,r,i){if(!(n instanceof Array))throw new SyntaxError("Bad execution tree");let s=0;for(s=0;s<n.length;s++){let c,a;const d=n[s];try{await L(e,d,r,o,(...t)=>{1===t.length?a={error:t[0]}:c=t[1]},i)}catch(t){a={error:t}}if(a)return void t(a.error);if(c instanceof h)return void t(void 0,c);if(l(d)&&8===d[0])return void t(void 0,new h(o.ctx.auditReport,c,!0))}t(void 0,new h(o.ctx.auditReport,void 0,!1))}(e,o,n,s,p,a).catch(e)}function B(t,e,o,n){const r=n.setSubscriptions.get(t)||new Map;n.setSubscriptions.set(t,r);const i=r.get(e)||new Set;let s;r.set(e,i),i.add(o);const c=t[e];return c instanceof Object&&(s=n.changeSubscriptions.get(c)||new Set,s.add(o),n.changeSubscriptions.set(c,s)),{unsubscribe:()=>{i.delete(o),s?.delete(o)}}}class D{constructor(e,o){this.evalContext=o,this.setSubscriptions=new WeakMap,this.changeSubscriptions=new WeakMap,this.sandboxFunctions=new WeakMap,this.haltSubscriptions=new Set,this.resumeSubscriptions=new Set,this.halted=!1,this.timeoutHandleCounter=0,this.setTimeoutHandles=new Map,this.setIntervalHandles=new Map;const n=Object.assign({audit:!1,forbidFunctionCalls:!1,forbidFunctionCreation:!1,globals:D.SAFE_GLOBALS,prototypeWhitelist:D.SAFE_PROTOTYPES,prototypeReplacements:new Map},e||{});this.context=function(e,o){const n=new t(o.globals),i={sandbox:e,globalsWhitelist:new Set(Object.values(o.globals)),prototypeWhitelist:new Map([...o.prototypeWhitelist].map(t=>[t[0].prototype,t[1]])),options:o,globalScope:new r(null,o.globals,n),sandboxGlobal:n,ticks:{ticks:0n,tickLimit:o.executionQuota},sandboxedFunctions:new WeakSet};return i.prototypeWhitelist.set(Object.getPrototypeOf([][Symbol.iterator]()),new Set),"undefined"!=typeof Response&&i.prototypeWhitelist.set(Response.prototype,new Set),"undefined"!=typeof Request&&i.prototypeWhitelist.set(Request.prototype,new Set),"undefined"!=typeof Headers&&i.prototypeWhitelist.set(Headers.prototype,new Set),"undefined"!=typeof FormData&&i.prototypeWhitelist.set(FormData.prototype,new Set),"undefined"!=typeof Blob&&i.prototypeWhitelist.set(Blob.prototype,new Set),"undefined"!=typeof URLSearchParams&&i.prototypeWhitelist.set(URLSearchParams.prototype,new Set),"undefined"!=typeof AbortController&&i.prototypeWhitelist.set(AbortController.prototype,new Set),"undefined"!=typeof ReadableStream&&i.prototypeWhitelist.set(ReadableStream.prototype,new Set),"undefined"!=typeof TransformStream&&i.prototypeWhitelist.set(TransformStream.prototype,new Set),"undefined"!=typeof WritableStream&&i.prototypeWhitelist.set(WritableStream.prototype,new Set),"undefined"!=typeof TextEncoder&&i.prototypeWhitelist.set(TextEncoder.prototype,new Set),"undefined"!=typeof TextDecoder&&i.prototypeWhitelist.set(TextDecoder.prototype,new Set),i}(this,n)}static get SAFE_GLOBALS(){return{globalThis:globalThis,Function:Function,eval:eval,console:{debug:console.debug,error:console.error,info:console.info,log:console.log,table:console.table,warn:console.warn},isFinite:isFinite,isNaN:isNaN,parseFloat:parseFloat,parseInt:parseInt,decodeURI:decodeURI,decodeURIComponent:decodeURIComponent,encodeURI:encodeURI,encodeURIComponent:encodeURIComponent,escape:escape,unescape:unescape,Boolean:Boolean,Number:Number,BigInt:BigInt,String:String,Object:Object,Array:Array,Symbol:Symbol,Error:Error,EvalError:EvalError,RangeError:RangeError,ReferenceError:ReferenceError,SyntaxError:SyntaxError,TypeError:TypeError,URIError:URIError,Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array,Map:Map,Set:Set,WeakMap:WeakMap,WeakSet:WeakSet,Promise:Promise,Intl:Intl,JSON:JSON,Math:Math,Date:Date,RegExp:RegExp}}static get SAFE_PROTOTYPES(){const e=[t,Function,Boolean,Number,BigInt,String,Date,Error,Array,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Map,Set,WeakMap,WeakSet,Promise,Symbol,Date,RegExp,Response,Request,Headers,FormData],o=new Map;return e.forEach(t=>{o.set(t,new Set)}),o.set(Object,new Set(["constructor","name","entries","fromEntries","getOwnPropertyNames","is","keys","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf","values"])),o}subscribeGet(t,e){return e.getSubscriptions.add(t),{unsubscribe:()=>e.getSubscriptions.delete(t)}}subscribeSet(t,e,o,n){return B(t,e,o,n)}subscribeSetGlobal(t,e,o){return B(t,e,o,this)}subscribeHalt(t){return this.haltSubscriptions.add(t),{unsubscribe:()=>{this.haltSubscriptions.delete(t)}}}subscribeResume(t){return this.resumeSubscriptions.add(t),{unsubscribe:()=>{this.resumeSubscriptions.delete(t)}}}haltExecution(t){if(!this.halted){this.halted=!0;for(const e of this.haltSubscriptions)e(t)}}resumeExecution(){if(this.halted){if(this.context.ticks.tickLimit&&this.context.ticks.ticks>=this.context.ticks.tickLimit)throw new c("Cannot resume execution: tick limit exceeded");this.halted=!1;for(const t of this.resumeSubscriptions)t()}}getContext(t){return this.sandboxFunctions.get(t)}executeTree(t,e=[]){return M(t.ctx.ticks,t,t.tree,e)}executeTreeAsync(t,e=[]){return _(t.ctx.ticks,t,t.tree,e)}}export{i as LocalScope,p as SandboxAccessError,d as SandboxCapabilityError,s as SandboxError,a as SandboxExecutionTreeError,D as default};
|
|
2
|
+
//# sourceMappingURL=SandboxExec.min.js.map
|