@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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +186 -0
  3. package/build/Sandbox.d.ts +25 -0
  4. package/build/Sandbox.js +62 -0
  5. package/build/SandboxExec.d.ts +66 -0
  6. package/build/SandboxExec.js +214 -0
  7. package/build/eval.d.ts +27 -0
  8. package/build/eval.js +205 -0
  9. package/build/executor.d.ts +124 -0
  10. package/build/executor.js +1546 -0
  11. package/build/parser.d.ts +154 -0
  12. package/build/parser.js +1527 -0
  13. package/build/unraw.d.ts +11 -0
  14. package/build/unraw.js +168 -0
  15. package/build/utils.d.ts +264 -0
  16. package/build/utils.js +362 -0
  17. package/dist/Sandbox.d.ts +25 -0
  18. package/dist/Sandbox.js +270 -0
  19. package/dist/Sandbox.js.map +1 -0
  20. package/dist/Sandbox.min.js +2 -0
  21. package/dist/Sandbox.min.js.map +1 -0
  22. package/dist/SandboxExec.d.ts +66 -0
  23. package/dist/SandboxExec.js +218 -0
  24. package/dist/SandboxExec.js.map +1 -0
  25. package/dist/SandboxExec.min.js +2 -0
  26. package/dist/SandboxExec.min.js.map +1 -0
  27. package/dist/eval.d.ts +27 -0
  28. package/dist/executor.d.ts +124 -0
  29. package/dist/executor.js +1550 -0
  30. package/dist/executor.js.map +1 -0
  31. package/dist/node/Sandbox.d.ts +25 -0
  32. package/dist/node/Sandbox.js +277 -0
  33. package/dist/node/SandboxExec.d.ts +66 -0
  34. package/dist/node/SandboxExec.js +225 -0
  35. package/dist/node/eval.d.ts +27 -0
  36. package/dist/node/executor.d.ts +124 -0
  37. package/dist/node/executor.js +1567 -0
  38. package/dist/node/parser.d.ts +154 -0
  39. package/dist/node/parser.js +1704 -0
  40. package/dist/node/unraw.d.ts +11 -0
  41. package/dist/node/utils.d.ts +264 -0
  42. package/dist/node/utils.js +385 -0
  43. package/dist/parser.d.ts +154 -0
  44. package/dist/parser.js +1690 -0
  45. package/dist/parser.js.map +1 -0
  46. package/dist/unraw.d.ts +11 -0
  47. package/dist/utils.d.ts +264 -0
  48. package/dist/utils.js +365 -0
  49. package/dist/utils.js.map +1 -0
  50. package/package.json +68 -0
package/dist/utils.js ADDED
@@ -0,0 +1,365 @@
1
+ // Reusable AsyncFunction constructor reference
2
+ const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
3
+ const GeneratorFunction = Object.getPrototypeOf(function* () { }).constructor;
4
+ const AsyncGeneratorFunction = Object.getPrototypeOf(async function* () { }).constructor;
5
+ const SandboxGlobal = function SandboxGlobal(globals) {
6
+ for (const i in globals) {
7
+ this[i] = globals[i];
8
+ }
9
+ };
10
+ class ExecContext {
11
+ constructor(ctx, constants, tree, getSubscriptions, setSubscriptions, changeSubscriptions, setSubscriptionsGlobal, changeSubscriptionsGlobal, evals, registerSandboxFunction, allowJit, evalContext) {
12
+ this.ctx = ctx;
13
+ this.constants = constants;
14
+ this.tree = tree;
15
+ this.getSubscriptions = getSubscriptions;
16
+ this.setSubscriptions = setSubscriptions;
17
+ this.changeSubscriptions = changeSubscriptions;
18
+ this.setSubscriptionsGlobal = setSubscriptionsGlobal;
19
+ this.changeSubscriptionsGlobal = changeSubscriptionsGlobal;
20
+ this.evals = evals;
21
+ this.registerSandboxFunction = registerSandboxFunction;
22
+ this.allowJit = allowJit;
23
+ this.evalContext = evalContext;
24
+ }
25
+ }
26
+ function createContext(sandbox, options) {
27
+ const sandboxGlobal = new SandboxGlobal(options.globals);
28
+ const context = {
29
+ sandbox: sandbox,
30
+ globalsWhitelist: new Set(Object.values(options.globals)),
31
+ prototypeWhitelist: new Map([...options.prototypeWhitelist].map((a) => [a[0].prototype, a[1]])),
32
+ options,
33
+ globalScope: new Scope(null, options.globals, sandboxGlobal),
34
+ sandboxGlobal,
35
+ ticks: { ticks: 0n, tickLimit: options.executionQuota },
36
+ sandboxedFunctions: new WeakSet(),
37
+ };
38
+ context.prototypeWhitelist.set(Object.getPrototypeOf([][Symbol.iterator]()), new Set());
39
+ // Fetch API 构造函数本身(静态方法如 Response.json)也加白名单
40
+ if (typeof Response !== 'undefined')
41
+ context.prototypeWhitelist.set(Response.prototype, new Set());
42
+ if (typeof Request !== 'undefined')
43
+ context.prototypeWhitelist.set(Request.prototype, new Set());
44
+ if (typeof Headers !== 'undefined')
45
+ context.prototypeWhitelist.set(Headers.prototype, new Set());
46
+ if (typeof FormData !== 'undefined')
47
+ context.prototypeWhitelist.set(FormData.prototype, new Set());
48
+ if (typeof Blob !== 'undefined')
49
+ context.prototypeWhitelist.set(Blob.prototype, new Set());
50
+ if (typeof URLSearchParams !== 'undefined')
51
+ context.prototypeWhitelist.set(URLSearchParams.prototype, new Set());
52
+ if (typeof AbortController !== 'undefined')
53
+ context.prototypeWhitelist.set(AbortController.prototype, new Set());
54
+ if (typeof ReadableStream !== 'undefined')
55
+ context.prototypeWhitelist.set(ReadableStream.prototype, new Set());
56
+ if (typeof TransformStream !== 'undefined')
57
+ context.prototypeWhitelist.set(TransformStream.prototype, new Set());
58
+ if (typeof WritableStream !== 'undefined')
59
+ context.prototypeWhitelist.set(WritableStream.prototype, new Set());
60
+ if (typeof TextEncoder !== 'undefined')
61
+ context.prototypeWhitelist.set(TextEncoder.prototype, new Set());
62
+ if (typeof TextDecoder !== 'undefined')
63
+ context.prototypeWhitelist.set(TextDecoder.prototype, new Set());
64
+ return context;
65
+ }
66
+ function createExecContext(sandbox, executionTree, evalContext) {
67
+ const evals = new Map();
68
+ const execContext = new ExecContext(sandbox.context, executionTree.constants, executionTree.tree, new Set(), new WeakMap(), new WeakMap(), sandbox.setSubscriptions, sandbox.changeSubscriptions, evals, (fn) => sandbox.sandboxFunctions.set(fn, execContext), !!evalContext, evalContext);
69
+ if (evalContext) {
70
+ const func = evalContext.sandboxFunction(execContext);
71
+ const asyncFunc = evalContext.sandboxAsyncFunction(execContext);
72
+ evals.set(Function, func);
73
+ evals.set(AsyncFunction, asyncFunc);
74
+ evals.set(GeneratorFunction, func);
75
+ evals.set(AsyncGeneratorFunction, asyncFunc);
76
+ evals.set(eval, evalContext.sandboxedEval(func, execContext));
77
+ evals.set(setTimeout, evalContext.sandboxedSetTimeout(func, execContext));
78
+ evals.set(setInterval, evalContext.sandboxedSetInterval(func, execContext));
79
+ evals.set(clearTimeout, evalContext.sandboxedClearTimeout(execContext));
80
+ evals.set(clearInterval, evalContext.sandboxedClearInterval(execContext));
81
+ for (const [key, value] of evals) {
82
+ sandbox.context.prototypeWhitelist.set(value.prototype, new Set());
83
+ sandbox.context.prototypeWhitelist.set(key.prototype, new Set());
84
+ }
85
+ }
86
+ return execContext;
87
+ }
88
+ class CodeString {
89
+ constructor(str) {
90
+ this.ref = { str: '' };
91
+ if (str instanceof CodeString) {
92
+ this.ref = str.ref;
93
+ this.start = str.start;
94
+ this.end = str.end;
95
+ }
96
+ else {
97
+ this.ref.str = str;
98
+ this.start = 0;
99
+ this.end = str.length;
100
+ }
101
+ }
102
+ substring(start, end) {
103
+ if (!this.length)
104
+ return this;
105
+ start = this.start + start;
106
+ if (start < 0) {
107
+ start = 0;
108
+ }
109
+ if (start > this.end) {
110
+ start = this.end;
111
+ }
112
+ end = end === undefined ? this.end : this.start + end;
113
+ if (end < 0) {
114
+ end = 0;
115
+ }
116
+ if (end > this.end) {
117
+ end = this.end;
118
+ }
119
+ const code = new CodeString(this);
120
+ code.start = start;
121
+ code.end = end;
122
+ return code;
123
+ }
124
+ get length() {
125
+ const len = this.end - this.start;
126
+ return len < 0 ? 0 : len;
127
+ }
128
+ char(i) {
129
+ if (this.start === this.end)
130
+ return undefined;
131
+ return this.ref.str[this.start + i];
132
+ }
133
+ toString() {
134
+ return this.ref.str.substring(this.start, this.end);
135
+ }
136
+ trimStart() {
137
+ const found = /^\s+/.exec(this.toString());
138
+ const code = new CodeString(this);
139
+ if (found) {
140
+ code.start += found[0].length;
141
+ }
142
+ return code;
143
+ }
144
+ slice(start, end) {
145
+ if (start < 0) {
146
+ start = this.end - this.start + start;
147
+ }
148
+ if (start < 0) {
149
+ start = 0;
150
+ }
151
+ if (end === undefined) {
152
+ end = this.end - this.start;
153
+ }
154
+ if (end < 0) {
155
+ end = this.end - this.start + end;
156
+ }
157
+ if (end < 0) {
158
+ end = 0;
159
+ }
160
+ return this.substring(start, end);
161
+ }
162
+ trim() {
163
+ const code = this.trimStart();
164
+ const found = /\s+$/.exec(code.toString());
165
+ if (found) {
166
+ code.end -= found[0].length;
167
+ }
168
+ return code;
169
+ }
170
+ valueOf() {
171
+ return this.toString();
172
+ }
173
+ }
174
+ function keysOnly(obj) {
175
+ const ret = Object.assign({}, obj);
176
+ for (const key in ret) {
177
+ ret[key] = true;
178
+ }
179
+ return ret;
180
+ }
181
+ const reservedWords = new Set([
182
+ 'await',
183
+ 'break',
184
+ 'case',
185
+ 'catch',
186
+ 'class',
187
+ 'const',
188
+ 'continue',
189
+ 'debugger',
190
+ 'default',
191
+ 'delete',
192
+ 'do',
193
+ 'else',
194
+ 'enum',
195
+ 'export',
196
+ 'extends',
197
+ 'false',
198
+ 'finally',
199
+ 'for',
200
+ 'function',
201
+ 'if',
202
+ 'implements',
203
+ 'import',
204
+ 'in',
205
+ 'instanceof',
206
+ 'let',
207
+ 'new',
208
+ 'null',
209
+ 'return',
210
+ 'super',
211
+ 'switch',
212
+ 'this',
213
+ 'throw',
214
+ 'true',
215
+ 'try',
216
+ 'typeof',
217
+ 'var',
218
+ 'void',
219
+ 'while',
220
+ 'with',
221
+ ]);
222
+ class Scope {
223
+ constructor(parent, vars = {}, functionThis) {
224
+ this.const = {};
225
+ this.let = {};
226
+ this.var = {};
227
+ const isFuncScope = functionThis !== undefined || parent === null;
228
+ this.parent = parent;
229
+ this.allVars = vars;
230
+ this.let = isFuncScope ? this.let : keysOnly(vars);
231
+ this.var = isFuncScope ? keysOnly(vars) : this.var;
232
+ this.globals = parent === null ? keysOnly(vars) : {};
233
+ this.functionThis = functionThis;
234
+ }
235
+ get(key) {
236
+ const isThis = key === 'this';
237
+ const scope = this.getWhereValScope(key, isThis);
238
+ if (scope && isThis) {
239
+ return new Prop({ this: scope.functionThis }, key, false, false, true);
240
+ }
241
+ if (!scope) {
242
+ return new Prop(undefined, key);
243
+ }
244
+ return new Prop(scope.allVars, key, key in scope.const, key in scope.globals, true);
245
+ }
246
+ set(key, val) {
247
+ if (key === 'this')
248
+ throw new SyntaxError('"this" cannot be assigned');
249
+ if (reservedWords.has(key))
250
+ throw new SyntaxError("Unexepected token '" + key + "'");
251
+ const prop = this.get(key);
252
+ if (prop.context === undefined) {
253
+ throw new ReferenceError(`Variable '${key}' was not declared.`);
254
+ }
255
+ if (prop.context === null) {
256
+ throw new TypeError(`Cannot set properties of null, (setting '${key}')`);
257
+ }
258
+ if (prop.isConst) {
259
+ throw new TypeError(`Assignment to constant variable`);
260
+ }
261
+ if (prop.isGlobal) {
262
+ throw new SandboxError(`Cannot override global variable '${key}'`);
263
+ }
264
+ prop.context[prop.prop] = val;
265
+ return prop;
266
+ }
267
+ getWhereValScope(key, isThis) {
268
+ if (isThis) {
269
+ if (this.functionThis !== undefined) {
270
+ return this;
271
+ }
272
+ else {
273
+ return this.parent?.getWhereValScope(key, isThis) || null;
274
+ }
275
+ }
276
+ if (key in this.allVars && !(key in {} && !hasOwnProperty(this.allVars, key))) {
277
+ return this;
278
+ }
279
+ return this.parent?.getWhereValScope(key, isThis) || null;
280
+ }
281
+ getWhereVarScope(key, localScope = false) {
282
+ if (key in this.allVars && !(key in {} && !hasOwnProperty(this.allVars, key))) {
283
+ return this;
284
+ }
285
+ if (this.parent === null || localScope || this.functionThis !== undefined) {
286
+ return this;
287
+ }
288
+ return this.parent.getWhereVarScope(key, localScope);
289
+ }
290
+ declare(key, type, value = undefined, isGlobal = false) {
291
+ if (key === 'this')
292
+ throw new SyntaxError('"this" cannot be declared');
293
+ if (reservedWords.has(key))
294
+ throw new SyntaxError("Unexepected token '" + key + "'");
295
+ const existingScope = this.getWhereVarScope(key, type !== "var" /* VarType.var */);
296
+ if (type === "var" /* VarType.var */) {
297
+ if (existingScope.var[key]) {
298
+ existingScope.allVars[key] = value;
299
+ if (!isGlobal) {
300
+ delete existingScope.globals[key];
301
+ }
302
+ else {
303
+ existingScope.globals[key] = true;
304
+ }
305
+ return new Prop(existingScope.allVars, key, false, existingScope.globals[key], true);
306
+ }
307
+ else if (key in existingScope.allVars) {
308
+ throw new SyntaxError(`Identifier '${key}' has already been declared`);
309
+ }
310
+ }
311
+ if (key in existingScope.allVars) {
312
+ throw new SyntaxError(`Identifier '${key}' has already been declared`);
313
+ }
314
+ if (isGlobal) {
315
+ existingScope.globals[key] = true;
316
+ }
317
+ existingScope[type][key] = true;
318
+ existingScope.allVars[key] = value;
319
+ return new Prop(this.allVars, key, type === "const" /* VarType.const */, isGlobal, true);
320
+ }
321
+ }
322
+ class FunctionScope {
323
+ }
324
+ class LocalScope {
325
+ }
326
+ class SandboxError extends Error {
327
+ }
328
+ class SandboxExecutionQuotaExceededError extends SandboxError {
329
+ }
330
+ class SandboxExecutionTreeError extends SandboxError {
331
+ }
332
+ class SandboxCapabilityError extends SandboxError {
333
+ }
334
+ class SandboxAccessError extends SandboxError {
335
+ }
336
+ function isLisp(item) {
337
+ return (Array.isArray(item) &&
338
+ typeof item[0] === 'number' &&
339
+ item[0] !== 0 /* LispType.None */ &&
340
+ item[0] !== 88 /* LispType.True */);
341
+ }
342
+ class Prop {
343
+ constructor(context, prop, isConst = false, isGlobal = false, isVariable = false) {
344
+ this.context = context;
345
+ this.prop = prop;
346
+ this.isConst = isConst;
347
+ this.isGlobal = isGlobal;
348
+ this.isVariable = isVariable;
349
+ }
350
+ get(context) {
351
+ const ctx = this.context;
352
+ if (ctx === undefined)
353
+ throw new ReferenceError(`${this.prop.toString()} is not defined`);
354
+ if (ctx === null)
355
+ throw new TypeError(`Cannot read properties of null, (reading '${this.prop.toString()}')`);
356
+ context.getSubscriptions.forEach((cb) => cb(ctx, this.prop.toString()));
357
+ return ctx[this.prop];
358
+ }
359
+ }
360
+ function hasOwnProperty(obj, prop) {
361
+ return Object.prototype.hasOwnProperty.call(obj, prop);
362
+ }
363
+
364
+ export { AsyncFunction, AsyncGeneratorFunction, CodeString, ExecContext, FunctionScope, GeneratorFunction, LocalScope, Prop, SandboxAccessError, SandboxCapabilityError, SandboxError, SandboxExecutionQuotaExceededError, SandboxExecutionTreeError, SandboxGlobal, Scope, createContext, createExecContext, hasOwnProperty, isLisp, reservedWords };
365
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":["// Reusable AsyncFunction constructor reference\r\nexport const AsyncFunction: Function = Object.getPrototypeOf(async function () {}).constructor;\r\nexport const GeneratorFunction: Function = Object.getPrototypeOf(function* () {}).constructor;\r\nexport const AsyncGeneratorFunction: Function = Object.getPrototypeOf(\r\n async function* () {},\r\n).constructor;\r\n\r\nimport { IEvalContext } from './eval';\r\nimport { Change, Unknown } from './executor';\r\nimport { IConstants, IExecutionTree, Lisp, LispItem } from './parser';\r\nimport SandboxExec from './SandboxExec';\r\n\r\nexport type replacementCallback = (obj: any, isStaticAccess: boolean) => any;\r\n\r\nexport interface IOptionParams {\r\n audit?: boolean;\r\n forbidFunctionCalls?: boolean;\r\n forbidFunctionCreation?: boolean;\r\n prototypeReplacements?: Map<Function, replacementCallback>;\r\n prototypeWhitelist?: Map<Function, Set<string>>;\r\n globals?: IGlobals;\r\n executionQuota?: bigint;\r\n haltOnSandboxError?: boolean;\r\n}\r\n\r\nexport interface IOptions {\r\n audit: boolean;\r\n forbidFunctionCalls: boolean;\r\n forbidFunctionCreation: boolean;\r\n prototypeReplacements: Map<Function, replacementCallback>;\r\n prototypeWhitelist: Map<Function, Set<string>>;\r\n globals: IGlobals;\r\n executionQuota?: bigint;\r\n haltOnSandboxError?: boolean;\r\n}\r\n\r\nexport interface IContext {\r\n sandbox: SandboxExec;\r\n globalScope: Scope;\r\n sandboxGlobal: ISandboxGlobal;\r\n globalsWhitelist: Set<any>;\r\n prototypeWhitelist: Map<any, Set<PropertyKey>>;\r\n sandboxedFunctions: WeakSet<Function>;\r\n options: IOptions;\r\n auditReport?: IAuditReport;\r\n ticks: Ticks;\r\n}\r\n\r\nexport interface IAuditReport {\r\n globalsAccess: Set<unknown>;\r\n prototypeAccess: { [name: string]: Set<PropertyKey> };\r\n}\r\n\r\nexport interface Ticks {\r\n ticks: bigint;\r\n tickLimit?: bigint;\r\n}\r\n\r\nexport type SubscriptionSubject = object;\r\n\r\nexport interface IExecContext extends IExecutionTree {\r\n ctx: IContext;\r\n getSubscriptions: Set<(obj: SubscriptionSubject, name: string) => void>;\r\n setSubscriptions: WeakMap<SubscriptionSubject, Map<string, Set<(modification: Change) => void>>>;\r\n changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\r\n setSubscriptionsGlobal: WeakMap<\r\n SubscriptionSubject,\r\n Map<string, Set<(modification: Change) => void>>\r\n >;\r\n changeSubscriptionsGlobal: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\r\n registerSandboxFunction: (fn: (...args: any[]) => any) => void;\r\n evals: Map<Function, Function>;\r\n allowJit: boolean;\r\n evalContext?: IEvalContext;\r\n}\r\n\r\nexport interface ISandboxGlobal {\r\n [key: string]: unknown;\r\n}\r\ninterface SandboxGlobalConstructor {\r\n new (globals: IGlobals): ISandboxGlobal;\r\n}\r\n\r\nexport const SandboxGlobal = function SandboxGlobal(this: ISandboxGlobal, globals: IGlobals) {\r\n for (const i in globals) {\r\n this[i] = globals[i];\r\n }\r\n} as any as SandboxGlobalConstructor;\r\n\r\nexport type IGlobals = ISandboxGlobal;\r\n\r\nexport class ExecContext implements IExecContext {\r\n constructor(\r\n public ctx: IContext,\r\n public constants: IConstants,\r\n public tree: Lisp[],\r\n public getSubscriptions: Set<(obj: SubscriptionSubject, name: string) => void>,\r\n public setSubscriptions: WeakMap<\r\n SubscriptionSubject,\r\n Map<string, Set<(modification: Change) => void>>\r\n >,\r\n public changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>,\r\n public setSubscriptionsGlobal: WeakMap<\r\n SubscriptionSubject,\r\n Map<string, Set<(modification: Change) => void>>\r\n >,\r\n public changeSubscriptionsGlobal: WeakMap<\r\n SubscriptionSubject,\r\n Set<(modification: Change) => void>\r\n >,\r\n public evals: Map<any, any>,\r\n public registerSandboxFunction: (fn: (...args: any[]) => any) => void,\r\n public allowJit: boolean,\r\n public evalContext?: IEvalContext,\r\n ) {}\r\n}\r\n\r\nexport function createContext(sandbox: SandboxExec, options: IOptions): IContext {\r\n const sandboxGlobal = new SandboxGlobal(options.globals);\r\n const context: IContext = {\r\n sandbox: sandbox,\r\n globalsWhitelist: new Set(Object.values(options.globals)),\r\n prototypeWhitelist: new Map([...options.prototypeWhitelist].map((a) => [a[0].prototype, a[1]])),\r\n options,\r\n globalScope: new Scope(null, options.globals, sandboxGlobal),\r\n sandboxGlobal,\r\n ticks: { ticks: 0n, tickLimit: options.executionQuota },\r\n sandboxedFunctions: new WeakSet<Function>(),\r\n };\r\n context.prototypeWhitelist.set(Object.getPrototypeOf([][Symbol.iterator]()) as object, new Set());\r\n // Fetch API 构造函数本身(静态方法如 Response.json)也加白名单\r\n if (typeof Response !== 'undefined') context.prototypeWhitelist.set(Response.prototype, new Set());\r\n if (typeof Request !== 'undefined') context.prototypeWhitelist.set(Request.prototype, new Set());\r\n if (typeof Headers !== 'undefined') context.prototypeWhitelist.set(Headers.prototype, new Set());\r\n if (typeof FormData !== 'undefined') context.prototypeWhitelist.set(FormData.prototype, new Set());\r\n if (typeof Blob !== 'undefined') context.prototypeWhitelist.set(Blob.prototype, new Set());\r\n if (typeof URLSearchParams !== 'undefined') context.prototypeWhitelist.set(URLSearchParams.prototype, new Set());\r\n if (typeof AbortController !== 'undefined') context.prototypeWhitelist.set(AbortController.prototype, new Set());\r\n if (typeof ReadableStream !== 'undefined') context.prototypeWhitelist.set(ReadableStream.prototype, new Set());\r\n if (typeof TransformStream !== 'undefined') context.prototypeWhitelist.set(TransformStream.prototype, new Set());\r\n if (typeof WritableStream !== 'undefined') context.prototypeWhitelist.set(WritableStream.prototype, new Set());\r\n if (typeof TextEncoder !== 'undefined') context.prototypeWhitelist.set(TextEncoder.prototype, new Set());\r\n if (typeof TextDecoder !== 'undefined') context.prototypeWhitelist.set(TextDecoder.prototype, new Set());\r\n return context;\r\n}\r\n\r\nexport function createExecContext(\r\n sandbox: {\r\n readonly setSubscriptions: WeakMap<\r\n SubscriptionSubject,\r\n Map<string, Set<(modification: Change) => void>>\r\n >;\r\n readonly changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\r\n readonly sandboxFunctions: WeakMap<(...args: any[]) => any, IExecContext>;\r\n readonly context: IContext;\r\n },\r\n executionTree: IExecutionTree,\r\n evalContext?: IEvalContext,\r\n): IExecContext {\r\n const evals = new Map();\r\n const execContext: IExecContext = new ExecContext(\r\n sandbox.context,\r\n executionTree.constants,\r\n executionTree.tree,\r\n new Set<(obj: SubscriptionSubject, name: string) => void>(),\r\n new WeakMap<SubscriptionSubject, Map<string, Set<(modification: Change) => void>>>(),\r\n new WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>(),\r\n sandbox.setSubscriptions,\r\n sandbox.changeSubscriptions,\r\n evals,\r\n (fn) => sandbox.sandboxFunctions.set(fn, execContext),\r\n !!evalContext,\r\n evalContext,\r\n );\r\n if (evalContext) {\r\n const func = evalContext.sandboxFunction(execContext);\r\n const asyncFunc = evalContext.sandboxAsyncFunction(execContext);\r\n evals.set(Function, func);\r\n evals.set(AsyncFunction, asyncFunc);\r\n evals.set(GeneratorFunction, func);\r\n evals.set(AsyncGeneratorFunction, asyncFunc);\r\n evals.set(eval, evalContext.sandboxedEval(func, execContext));\r\n evals.set(setTimeout, evalContext.sandboxedSetTimeout(func, execContext));\r\n evals.set(setInterval, evalContext.sandboxedSetInterval(func, execContext));\r\n evals.set(clearTimeout, evalContext.sandboxedClearTimeout(execContext));\r\n evals.set(clearInterval, evalContext.sandboxedClearInterval(execContext));\r\n\r\n for (const [key, value] of evals) {\r\n sandbox.context.prototypeWhitelist.set(value.prototype, new Set());\r\n sandbox.context.prototypeWhitelist.set(key.prototype, new Set());\r\n }\r\n }\r\n return execContext;\r\n}\r\n\r\nexport class CodeString {\r\n start: number;\r\n end: number;\r\n ref: { str: string };\r\n constructor(str: string | CodeString) {\r\n this.ref = { str: '' };\r\n if (str instanceof CodeString) {\r\n this.ref = str.ref;\r\n this.start = str.start;\r\n this.end = str.end;\r\n } else {\r\n this.ref.str = str;\r\n this.start = 0;\r\n this.end = str.length;\r\n }\r\n }\r\n\r\n substring(start: number, end?: number): CodeString {\r\n if (!this.length) return this;\r\n start = this.start + start;\r\n if (start < 0) {\r\n start = 0;\r\n }\r\n if (start > this.end) {\r\n start = this.end;\r\n }\r\n end = end === undefined ? this.end : this.start + end;\r\n if (end < 0) {\r\n end = 0;\r\n }\r\n if (end > this.end) {\r\n end = this.end;\r\n }\r\n const code = new CodeString(this);\r\n code.start = start;\r\n code.end = end;\r\n return code;\r\n }\r\n\r\n get length() {\r\n const len = this.end - this.start;\r\n return len < 0 ? 0 : len;\r\n }\r\n\r\n char(i: number) {\r\n if (this.start === this.end) return undefined;\r\n return this.ref.str[this.start + i];\r\n }\r\n\r\n toString() {\r\n return this.ref.str.substring(this.start, this.end);\r\n }\r\n\r\n trimStart() {\r\n const found = /^\\s+/.exec(this.toString());\r\n const code = new CodeString(this);\r\n if (found) {\r\n code.start += found[0].length;\r\n }\r\n return code;\r\n }\r\n\r\n slice(start: number, end?: number) {\r\n if (start < 0) {\r\n start = this.end - this.start + start;\r\n }\r\n if (start < 0) {\r\n start = 0;\r\n }\r\n if (end === undefined) {\r\n end = this.end - this.start;\r\n }\r\n\r\n if (end < 0) {\r\n end = this.end - this.start + end;\r\n }\r\n if (end < 0) {\r\n end = 0;\r\n }\r\n return this.substring(start, end);\r\n }\r\n\r\n trim() {\r\n const code = this.trimStart();\r\n const found = /\\s+$/.exec(code.toString());\r\n if (found) {\r\n code.end -= found[0].length;\r\n }\r\n return code;\r\n }\r\n\r\n valueOf() {\r\n return this.toString();\r\n }\r\n}\r\n\r\nfunction keysOnly(obj: unknown): Record<string, true> {\r\n const ret: Record<string, true> = Object.assign({}, obj);\r\n for (const key in ret) {\r\n ret[key] = true;\r\n }\r\n return ret;\r\n}\r\n\r\nexport const reservedWords = new Set([\r\n 'await',\r\n 'break',\r\n 'case',\r\n 'catch',\r\n 'class',\r\n 'const',\r\n 'continue',\r\n 'debugger',\r\n 'default',\r\n 'delete',\r\n 'do',\r\n 'else',\r\n 'enum',\r\n 'export',\r\n 'extends',\r\n 'false',\r\n 'finally',\r\n 'for',\r\n 'function',\r\n 'if',\r\n 'implements',\r\n 'import',\r\n 'in',\r\n 'instanceof',\r\n 'let',\r\n 'new',\r\n 'null',\r\n 'return',\r\n 'super',\r\n 'switch',\r\n 'this',\r\n 'throw',\r\n 'true',\r\n 'try',\r\n 'typeof',\r\n 'var',\r\n 'void',\r\n 'while',\r\n 'with',\r\n]);\r\n\r\nexport const enum VarType {\r\n let = 'let',\r\n const = 'const',\r\n var = 'var',\r\n}\r\n\r\nexport class Scope {\r\n parent: Scope | null;\r\n const: { [key: string]: true } = {};\r\n let: { [key: string]: true } = {};\r\n var: { [key: string]: true } = {};\r\n globals: { [key: string]: true };\r\n allVars: { [key: string]: unknown } & object;\r\n functionThis?: Unknown;\r\n constructor(parent: Scope | null, vars = {}, functionThis?: Unknown) {\r\n const isFuncScope = functionThis !== undefined || parent === null;\r\n this.parent = parent;\r\n this.allVars = vars;\r\n this.let = isFuncScope ? this.let : keysOnly(vars);\r\n this.var = isFuncScope ? keysOnly(vars) : this.var;\r\n this.globals = parent === null ? keysOnly(vars) : {};\r\n this.functionThis = functionThis;\r\n }\r\n\r\n get(key: string): Prop {\r\n const isThis = key === 'this';\r\n const scope = this.getWhereValScope(key, isThis);\r\n if (scope && isThis) {\r\n return new Prop({ this: scope.functionThis }, key, false, false, true);\r\n }\r\n if (!scope) {\r\n return new Prop(undefined, key);\r\n }\r\n return new Prop(scope.allVars, key, key in scope.const, key in scope.globals, true);\r\n }\r\n\r\n set(key: string, val: unknown) {\r\n if (key === 'this') throw new SyntaxError('\"this\" cannot be assigned');\r\n if (reservedWords.has(key)) throw new SyntaxError(\"Unexepected token '\" + key + \"'\");\r\n const prop = this.get(key);\r\n if (prop.context === undefined) {\r\n throw new ReferenceError(`Variable '${key}' was not declared.`);\r\n }\r\n if (prop.context === null) {\r\n throw new TypeError(`Cannot set properties of null, (setting '${key}')`);\r\n }\r\n if (prop.isConst) {\r\n throw new TypeError(`Assignment to constant variable`);\r\n }\r\n if (prop.isGlobal) {\r\n throw new SandboxError(`Cannot override global variable '${key}'`);\r\n }\r\n (prop.context as any)[prop.prop] = val;\r\n return prop;\r\n }\r\n\r\n getWhereValScope(key: string, isThis: boolean): Scope | null {\r\n if (isThis) {\r\n if (this.functionThis !== undefined) {\r\n return this;\r\n } else {\r\n return this.parent?.getWhereValScope(key, isThis) || null;\r\n }\r\n }\r\n if (key in this.allVars && !(key in {} && !hasOwnProperty(this.allVars, key))) {\r\n return this;\r\n }\r\n return this.parent?.getWhereValScope(key, isThis) || null;\r\n }\r\n\r\n getWhereVarScope(key: string, localScope = false): Scope {\r\n if (key in this.allVars && !(key in {} && !hasOwnProperty(this.allVars, key))) {\r\n return this;\r\n }\r\n if (this.parent === null || localScope || this.functionThis !== undefined) {\r\n return this;\r\n }\r\n return this.parent.getWhereVarScope(key, localScope);\r\n }\r\n\r\n declare(key: string, type: VarType, value: unknown = undefined, isGlobal = false): Prop {\r\n if (key === 'this') throw new SyntaxError('\"this\" cannot be declared');\r\n if (reservedWords.has(key)) throw new SyntaxError(\"Unexepected token '\" + key + \"'\");\r\n const existingScope = this.getWhereVarScope(key, type !== VarType.var);\r\n if (type === VarType.var) {\r\n if (existingScope.var[key]) {\r\n existingScope.allVars[key] = value;\r\n if (!isGlobal) {\r\n delete existingScope.globals[key];\r\n } else {\r\n existingScope.globals[key] = true;\r\n }\r\n return new Prop(existingScope.allVars, key, false, existingScope.globals[key], true);\r\n } else if (key in existingScope.allVars) {\r\n throw new SyntaxError(`Identifier '${key}' has already been declared`);\r\n }\r\n }\r\n if (key in existingScope.allVars) {\r\n throw new SyntaxError(`Identifier '${key}' has already been declared`);\r\n }\r\n\r\n if (isGlobal) {\r\n existingScope.globals[key] = true;\r\n }\r\n existingScope[type][key] = true;\r\n existingScope.allVars[key] = value;\r\n\r\n return new Prop(this.allVars, key, type === VarType.const, isGlobal, true);\r\n }\r\n}\r\n\r\nexport interface IScope {\r\n [key: string]: any;\r\n}\r\n\r\nexport class FunctionScope implements IScope {}\r\n\r\nexport class LocalScope implements IScope {}\r\n\r\nexport class SandboxError extends Error {}\r\n\r\nexport class SandboxExecutionQuotaExceededError extends SandboxError {}\r\n\r\nexport class SandboxExecutionTreeError extends SandboxError {}\r\n\r\nexport class SandboxCapabilityError extends SandboxError {}\r\n\r\nexport class SandboxAccessError extends SandboxError {}\r\n\r\nexport function isLisp<Type extends Lisp = Lisp>(item: LispItem | LispItem): item is Type {\r\n return (\r\n Array.isArray(item) &&\r\n typeof item[0] === 'number' &&\r\n item[0] !== LispType.None &&\r\n item[0] !== LispType.True\r\n );\r\n}\r\n\r\nexport const enum LispType {\r\n None,\r\n Prop,\r\n StringIndex,\r\n Let,\r\n Const,\r\n Call,\r\n KeyVal,\r\n Number,\r\n Return,\r\n Assign,\r\n InlineFunction,\r\n ArrowFunction,\r\n CreateArray,\r\n If,\r\n IfCase,\r\n InlineIf,\r\n InlineIfCase,\r\n SpreadObject,\r\n SpreadArray,\r\n ArrayProp,\r\n PropOptional,\r\n CallOptional,\r\n CreateObject,\r\n Group,\r\n Not,\r\n IncrementBefore,\r\n IncrementAfter,\r\n DecrementBefore,\r\n DecrementAfter,\r\n And,\r\n Or,\r\n StrictNotEqual,\r\n StrictEqual,\r\n Plus,\r\n Var,\r\n GlobalSymbol,\r\n Literal,\r\n Function,\r\n Loop,\r\n Try,\r\n Switch,\r\n SwitchCase,\r\n Block,\r\n Expression,\r\n Await,\r\n New,\r\n Throw,\r\n Minus,\r\n Divide,\r\n Power,\r\n Multiply,\r\n Modulus,\r\n Equal,\r\n NotEqual,\r\n SmallerEqualThan,\r\n LargerEqualThan,\r\n SmallerThan,\r\n LargerThan,\r\n Negative,\r\n Positive,\r\n Typeof,\r\n Delete,\r\n Instanceof,\r\n In,\r\n Inverse,\r\n SubractEquals,\r\n AddEquals,\r\n DivideEquals,\r\n PowerEquals,\r\n MultiplyEquals,\r\n ModulusEquals,\r\n BitNegateEquals,\r\n BitAndEquals,\r\n BitOrEquals,\r\n UnsignedShiftRightEquals,\r\n ShiftRightEquals,\r\n ShiftLeftEquals,\r\n BitAnd,\r\n BitOr,\r\n BitNegate,\r\n BitShiftLeft,\r\n BitShiftRight,\r\n BitUnsignedShiftRight,\r\n BigInt,\r\n LiteralIndex,\r\n RegexIndex,\r\n LoopAction,\r\n Void,\r\n True,\r\n NullishCoalescing,\r\n AndEquals,\r\n OrEquals,\r\n NullishCoalescingEquals,\r\n\r\n LispEnumSize,\r\n}\r\n\r\nexport class Prop<T = unknown> {\r\n constructor(\r\n public context: T,\r\n public prop: PropertyKey,\r\n public isConst = false,\r\n public isGlobal = false,\r\n public isVariable = false,\r\n ) {}\r\n\r\n get<T = unknown>(context: IExecContext): T {\r\n const ctx = this.context;\r\n if (ctx === undefined) throw new ReferenceError(`${this.prop.toString()} is not defined`);\r\n if (ctx === null)\r\n throw new TypeError(`Cannot read properties of null, (reading '${this.prop.toString()}')`);\r\n context.getSubscriptions.forEach((cb) => cb(ctx, this.prop.toString()));\r\n return (ctx as any)[this.prop] as T;\r\n }\r\n}\r\n\r\nexport function hasOwnProperty(obj: unknown, prop: PropertyKey): boolean {\r\n return Object.prototype.hasOwnProperty.call(obj, prop);\r\n}\r\n"],"names":[],"mappings":"AAAA;AACO,MAAM,aAAa,GAAa,MAAM,CAAC,cAAc,CAAC,kBAA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C,CAAA,0CAAA,EAA6C,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA,EAAA,CAAI,CAAC;QAC5F,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;AACvE,QAAA,OAAQ,GAAW,CAAC,IAAI,CAAC,IAAI,CAAM;IACrC;AACD;AAEK,SAAU,cAAc,CAAC,GAAY,EAAE,IAAiB,EAAA;AAC5D,IAAA,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC;AACxD;;;;"}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@cuxt/sandboxjs",
3
+ "version": "0.1.0",
4
+ "description": "JavaScript sandboxing library with prototype whitelist and safe globals.",
5
+ "main": "dist/node/Sandbox.js",
6
+ "module": "build/Sandbox.js",
7
+ "browser": "dist/Sandbox.min.js",
8
+ "type": "module",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./build/Sandbox.js",
12
+ "require": "./dist/node/Sandbox.js",
13
+ "types": "./build/Sandbox.d.ts"
14
+ }
15
+ },
16
+ "files": [
17
+ "build",
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "test": "NODE_OPTIONS='--no-warnings=ExperimentalWarning' jest",
22
+ "build": "tsc --project tsconfig.json --outDir build --declaration && rollup -c",
23
+ "lint": "prettier --check \"**/*.+(ts|json)\" && eslint --ext .ts .",
24
+ "lint:fix": "prettier --write \"**/*.+(ts|json)\" && eslint --ext .ts --fix .",
25
+ "patch": "npm version patch",
26
+ "minor": "npm version minor",
27
+ "major": "npm version major"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git@github.com:cuxt/SandboxJS.git"
32
+ },
33
+ "author": "",
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/cuxt/SandboxJS/issues"
37
+ },
38
+ "homepage": "https://github.com/cuxt/SandboxJS#readme",
39
+ "devDependencies": {
40
+ "@rollup/plugin-node-resolve": "^16.0.3",
41
+ "@rollup/plugin-terser": "^1.0.0",
42
+ "@rollup/plugin-typescript": "^12.3.0",
43
+ "@types/jest": "^30.0.0",
44
+ "@typescript-eslint/eslint-plugin": "^8.53.0",
45
+ "@typescript-eslint/parser": "^8.53.0",
46
+ "eslint": "^9.39.2",
47
+ "eslint-config-prettier": "^10.1.8",
48
+ "husky": "^9.1.7",
49
+ "jest": "^30.2.0",
50
+ "lint-staged": "^16.2.7",
51
+ "node-fetch": "^3.3.2",
52
+ "prettier": "^3.8.0",
53
+ "rollup": "^4.55.2",
54
+ "rollup-plugin-bundle-stats": "^4.21.8",
55
+ "ts-jest": "^29.4.6",
56
+ "tslib": "^2.8.1",
57
+ "typescript": "^5.9.3"
58
+ },
59
+ "lint-staged": {
60
+ "*.ts": [
61
+ "prettier --write",
62
+ "eslint --fix"
63
+ ],
64
+ "*.json": [
65
+ "prettier --write"
66
+ ]
67
+ }
68
+ }