vercel 31.0.4 → 31.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/dist/index.js +44799 -51753
- package/package.json +6 -6
- package/dist/bridge.js +0 -1010
- package/dist/events.js +0 -977
- package/dist/setup-node-sandbox.js +0 -469
- package/dist/setup-sandbox.js +0 -487
package/dist/setup-sandbox.js
DELETED
@@ -1,487 +0,0 @@
|
|
1
|
-
/* global host, bridge, data, context */
|
2
|
-
|
3
|
-
'use strict';
|
4
|
-
|
5
|
-
const {
|
6
|
-
Object: localObject,
|
7
|
-
Array: localArray,
|
8
|
-
Error: LocalError,
|
9
|
-
Reflect: localReflect,
|
10
|
-
Proxy: LocalProxy,
|
11
|
-
WeakMap: LocalWeakMap,
|
12
|
-
Function: localFunction,
|
13
|
-
Promise: localPromise,
|
14
|
-
eval: localEval
|
15
|
-
} = global;
|
16
|
-
|
17
|
-
const {
|
18
|
-
freeze: localObjectFreeze
|
19
|
-
} = localObject;
|
20
|
-
|
21
|
-
const {
|
22
|
-
getPrototypeOf: localReflectGetPrototypeOf,
|
23
|
-
apply: localReflectApply,
|
24
|
-
deleteProperty: localReflectDeleteProperty,
|
25
|
-
has: localReflectHas,
|
26
|
-
defineProperty: localReflectDefineProperty,
|
27
|
-
setPrototypeOf: localReflectSetPrototypeOf,
|
28
|
-
getOwnPropertyDescriptor: localReflectGetOwnPropertyDescriptor
|
29
|
-
} = localReflect;
|
30
|
-
|
31
|
-
const {
|
32
|
-
isArray: localArrayIsArray
|
33
|
-
} = localArray;
|
34
|
-
|
35
|
-
const {
|
36
|
-
ensureThis,
|
37
|
-
ReadOnlyHandler,
|
38
|
-
from,
|
39
|
-
fromWithFactory,
|
40
|
-
readonlyFactory,
|
41
|
-
connect,
|
42
|
-
addProtoMapping,
|
43
|
-
VMError,
|
44
|
-
ReadOnlyMockHandler
|
45
|
-
} = bridge;
|
46
|
-
|
47
|
-
const {
|
48
|
-
allowAsync,
|
49
|
-
GeneratorFunction,
|
50
|
-
AsyncFunction,
|
51
|
-
AsyncGeneratorFunction
|
52
|
-
} = data;
|
53
|
-
|
54
|
-
const {
|
55
|
-
get: localWeakMapGet,
|
56
|
-
set: localWeakMapSet
|
57
|
-
} = LocalWeakMap.prototype;
|
58
|
-
|
59
|
-
function localUnexpected() {
|
60
|
-
return new VMError('Should not happen');
|
61
|
-
}
|
62
|
-
|
63
|
-
// global is originally prototype of host.Object so it can be used to climb up from the sandbox.
|
64
|
-
if (!localReflectSetPrototypeOf(context, localObject.prototype)) throw localUnexpected();
|
65
|
-
|
66
|
-
Object.defineProperties(global, {
|
67
|
-
global: {value: global, writable: true, configurable: true, enumerable: true},
|
68
|
-
globalThis: {value: global, writable: true, configurable: true},
|
69
|
-
GLOBAL: {value: global, writable: true, configurable: true},
|
70
|
-
root: {value: global, writable: true, configurable: true},
|
71
|
-
Error: {value: LocalError}
|
72
|
-
});
|
73
|
-
|
74
|
-
if (!localReflectDefineProperty(global, 'VMError', {
|
75
|
-
__proto__: null,
|
76
|
-
value: VMError,
|
77
|
-
writable: true,
|
78
|
-
enumerable: false,
|
79
|
-
configurable: true
|
80
|
-
})) throw localUnexpected();
|
81
|
-
|
82
|
-
// Fixes buffer unsafe allocation
|
83
|
-
/* eslint-disable no-use-before-define */
|
84
|
-
class BufferHandler extends ReadOnlyHandler {
|
85
|
-
|
86
|
-
apply(target, thiz, args) {
|
87
|
-
if (args.length > 0 && typeof args[0] === 'number') {
|
88
|
-
return LocalBuffer.alloc(args[0]);
|
89
|
-
}
|
90
|
-
return localReflectApply(LocalBuffer.from, LocalBuffer, args);
|
91
|
-
}
|
92
|
-
|
93
|
-
construct(target, args, newTarget) {
|
94
|
-
if (args.length > 0 && typeof args[0] === 'number') {
|
95
|
-
return LocalBuffer.alloc(args[0]);
|
96
|
-
}
|
97
|
-
return localReflectApply(LocalBuffer.from, LocalBuffer, args);
|
98
|
-
}
|
99
|
-
|
100
|
-
}
|
101
|
-
/* eslint-enable no-use-before-define */
|
102
|
-
|
103
|
-
const LocalBuffer = fromWithFactory(obj => new BufferHandler(obj), host.Buffer);
|
104
|
-
|
105
|
-
|
106
|
-
if (!localReflectDefineProperty(global, 'Buffer', {
|
107
|
-
__proto__: null,
|
108
|
-
value: LocalBuffer,
|
109
|
-
writable: true,
|
110
|
-
enumerable: false,
|
111
|
-
configurable: true
|
112
|
-
})) throw localUnexpected();
|
113
|
-
|
114
|
-
addProtoMapping(LocalBuffer.prototype, host.Buffer.prototype, 'Uint8Array');
|
115
|
-
|
116
|
-
/**
|
117
|
-
*
|
118
|
-
* @param {*} size Size of new buffer
|
119
|
-
* @this LocalBuffer
|
120
|
-
* @return {LocalBuffer}
|
121
|
-
*/
|
122
|
-
function allocUnsafe(size) {
|
123
|
-
return LocalBuffer.alloc(size);
|
124
|
-
}
|
125
|
-
|
126
|
-
connect(allocUnsafe, host.Buffer.allocUnsafe);
|
127
|
-
|
128
|
-
/**
|
129
|
-
*
|
130
|
-
* @param {*} size Size of new buffer
|
131
|
-
* @this LocalBuffer
|
132
|
-
* @return {LocalBuffer}
|
133
|
-
*/
|
134
|
-
function allocUnsafeSlow(size) {
|
135
|
-
return LocalBuffer.alloc(size);
|
136
|
-
}
|
137
|
-
|
138
|
-
connect(allocUnsafeSlow, host.Buffer.allocUnsafeSlow);
|
139
|
-
|
140
|
-
/**
|
141
|
-
* Replacement for Buffer inspect
|
142
|
-
*
|
143
|
-
* @param {*} recurseTimes
|
144
|
-
* @param {*} ctx
|
145
|
-
* @this LocalBuffer
|
146
|
-
* @return {string}
|
147
|
-
*/
|
148
|
-
function inspect(recurseTimes, ctx) {
|
149
|
-
// Mimic old behavior, could throw but didn't pass a test.
|
150
|
-
const max = host.INSPECT_MAX_BYTES;
|
151
|
-
const actualMax = Math.min(max, this.length);
|
152
|
-
const remaining = this.length - max;
|
153
|
-
let str = this.hexSlice(0, actualMax).replace(/(.{2})/g, '$1 ').trim();
|
154
|
-
if (remaining > 0) str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`;
|
155
|
-
return `<${this.constructor.name} ${str}>`;
|
156
|
-
}
|
157
|
-
|
158
|
-
connect(inspect, host.Buffer.prototype.inspect);
|
159
|
-
|
160
|
-
connect(localFunction.prototype.bind, host.Function.prototype.bind);
|
161
|
-
|
162
|
-
connect(localObject.prototype.__defineGetter__, host.Object.prototype.__defineGetter__);
|
163
|
-
connect(localObject.prototype.__defineSetter__, host.Object.prototype.__defineSetter__);
|
164
|
-
connect(localObject.prototype.__lookupGetter__, host.Object.prototype.__lookupGetter__);
|
165
|
-
connect(localObject.prototype.__lookupSetter__, host.Object.prototype.__lookupSetter__);
|
166
|
-
|
167
|
-
/*
|
168
|
-
* PrepareStackTrace sanitization
|
169
|
-
*/
|
170
|
-
|
171
|
-
const oldPrepareStackTraceDesc = localReflectGetOwnPropertyDescriptor(LocalError, 'prepareStackTrace');
|
172
|
-
|
173
|
-
let currentPrepareStackTrace = LocalError.prepareStackTrace;
|
174
|
-
const wrappedPrepareStackTrace = new LocalWeakMap();
|
175
|
-
if (typeof currentPrepareStackTrace === 'function') {
|
176
|
-
wrappedPrepareStackTrace.set(currentPrepareStackTrace, currentPrepareStackTrace);
|
177
|
-
}
|
178
|
-
|
179
|
-
let OriginalCallSite;
|
180
|
-
LocalError.prepareStackTrace = (e, sst) => {
|
181
|
-
OriginalCallSite = sst[0].constructor;
|
182
|
-
};
|
183
|
-
new LocalError().stack;
|
184
|
-
if (typeof OriginalCallSite === 'function') {
|
185
|
-
LocalError.prepareStackTrace = undefined;
|
186
|
-
|
187
|
-
function makeCallSiteGetters(list) {
|
188
|
-
const callSiteGetters = [];
|
189
|
-
for (let i=0; i<list.length; i++) {
|
190
|
-
const name = list[i];
|
191
|
-
const func = OriginalCallSite.prototype[name];
|
192
|
-
callSiteGetters[i] = {__proto__: null,
|
193
|
-
name,
|
194
|
-
propName: '_' + name,
|
195
|
-
func: (thiz) => {
|
196
|
-
return localReflectApply(func, thiz, []);
|
197
|
-
}
|
198
|
-
};
|
199
|
-
}
|
200
|
-
return callSiteGetters;
|
201
|
-
}
|
202
|
-
|
203
|
-
function applyCallSiteGetters(thiz, callSite, getters) {
|
204
|
-
for (let i=0; i<getters.length; i++) {
|
205
|
-
const getter = getters[i];
|
206
|
-
localReflectDefineProperty(thiz, getter.propName, {
|
207
|
-
__proto__: null,
|
208
|
-
value: getter.func(callSite)
|
209
|
-
});
|
210
|
-
}
|
211
|
-
}
|
212
|
-
|
213
|
-
const callSiteGetters = makeCallSiteGetters([
|
214
|
-
'getTypeName',
|
215
|
-
'getFunctionName',
|
216
|
-
'getMethodName',
|
217
|
-
'getFileName',
|
218
|
-
'getLineNumber',
|
219
|
-
'getColumnNumber',
|
220
|
-
'getEvalOrigin',
|
221
|
-
'isToplevel',
|
222
|
-
'isEval',
|
223
|
-
'isNative',
|
224
|
-
'isConstructor',
|
225
|
-
'isAsync',
|
226
|
-
'isPromiseAll',
|
227
|
-
'getPromiseIndex'
|
228
|
-
]);
|
229
|
-
|
230
|
-
class CallSite {
|
231
|
-
constructor(callSite) {
|
232
|
-
applyCallSiteGetters(this, callSite, callSiteGetters);
|
233
|
-
}
|
234
|
-
getThis() {
|
235
|
-
return undefined;
|
236
|
-
}
|
237
|
-
getFunction() {
|
238
|
-
return undefined;
|
239
|
-
}
|
240
|
-
toString() {
|
241
|
-
return 'CallSite {}';
|
242
|
-
}
|
243
|
-
}
|
244
|
-
|
245
|
-
|
246
|
-
for (let i=0; i<callSiteGetters.length; i++) {
|
247
|
-
const name = callSiteGetters[i].name;
|
248
|
-
const funcProp = localReflectGetOwnPropertyDescriptor(OriginalCallSite.prototype, name);
|
249
|
-
if (!funcProp) continue;
|
250
|
-
const propertyName = callSiteGetters[i].propName;
|
251
|
-
const func = {func() {
|
252
|
-
return this[propertyName];
|
253
|
-
}}.func;
|
254
|
-
const nameProp = localReflectGetOwnPropertyDescriptor(func, 'name');
|
255
|
-
if (!nameProp) throw localUnexpected();
|
256
|
-
nameProp.value = name;
|
257
|
-
if (!localReflectDefineProperty(func, 'name', nameProp)) throw localUnexpected();
|
258
|
-
funcProp.value = func;
|
259
|
-
if (!localReflectDefineProperty(CallSite.prototype, name, funcProp)) throw localUnexpected();
|
260
|
-
}
|
261
|
-
|
262
|
-
if (!localReflectDefineProperty(LocalError, 'prepareStackTrace', {
|
263
|
-
configurable: false,
|
264
|
-
enumerable: false,
|
265
|
-
get() {
|
266
|
-
return currentPrepareStackTrace;
|
267
|
-
},
|
268
|
-
set(value) {
|
269
|
-
if (typeof(value) !== 'function') {
|
270
|
-
currentPrepareStackTrace = value;
|
271
|
-
return;
|
272
|
-
}
|
273
|
-
const wrapped = localReflectApply(localWeakMapGet, wrappedPrepareStackTrace, [value]);
|
274
|
-
if (wrapped) {
|
275
|
-
currentPrepareStackTrace = wrapped;
|
276
|
-
return;
|
277
|
-
}
|
278
|
-
const newWrapped = (error, sst) => {
|
279
|
-
const sandboxSst = ensureThis(sst);
|
280
|
-
if (localArrayIsArray(sst)) {
|
281
|
-
if (sst === sandboxSst) {
|
282
|
-
for (let i=0; i < sst.length; i++) {
|
283
|
-
const cs = sst[i];
|
284
|
-
if (typeof cs === 'object' && localReflectGetPrototypeOf(cs) === OriginalCallSite.prototype) {
|
285
|
-
sst[i] = new CallSite(cs);
|
286
|
-
}
|
287
|
-
}
|
288
|
-
} else {
|
289
|
-
sst = [];
|
290
|
-
for (let i=0; i < sandboxSst.length; i++) {
|
291
|
-
const cs = sandboxSst[i];
|
292
|
-
localReflectDefineProperty(sst, i, {
|
293
|
-
__proto__: null,
|
294
|
-
value: new CallSite(cs),
|
295
|
-
enumerable: true,
|
296
|
-
configurable: true,
|
297
|
-
writable: true
|
298
|
-
});
|
299
|
-
}
|
300
|
-
}
|
301
|
-
} else {
|
302
|
-
sst = sandboxSst;
|
303
|
-
}
|
304
|
-
return value(error, sst);
|
305
|
-
};
|
306
|
-
localReflectApply(localWeakMapSet, wrappedPrepareStackTrace, [value, newWrapped]);
|
307
|
-
localReflectApply(localWeakMapSet, wrappedPrepareStackTrace, [newWrapped, newWrapped]);
|
308
|
-
currentPrepareStackTrace = newWrapped;
|
309
|
-
}
|
310
|
-
})) throw localUnexpected();
|
311
|
-
} else if (oldPrepareStackTraceDesc) {
|
312
|
-
localReflectDefineProperty(LocalError, 'prepareStackTrace', oldPrepareStackTraceDesc);
|
313
|
-
} else {
|
314
|
-
localReflectDeleteProperty(LocalError, 'prepareStackTrace');
|
315
|
-
}
|
316
|
-
|
317
|
-
/*
|
318
|
-
* Exception sanitization
|
319
|
-
*/
|
320
|
-
|
321
|
-
const withProxy = localObjectFreeze({
|
322
|
-
__proto__: null,
|
323
|
-
has(target, key) {
|
324
|
-
if (key === host.INTERNAL_STATE_NAME) return false;
|
325
|
-
return localReflectHas(target, key);
|
326
|
-
}
|
327
|
-
});
|
328
|
-
|
329
|
-
const interanState = localObjectFreeze({
|
330
|
-
__proto__: null,
|
331
|
-
wrapWith(x) {
|
332
|
-
if (x === null || x === undefined) return x;
|
333
|
-
return new LocalProxy(localObject(x), withProxy);
|
334
|
-
},
|
335
|
-
handleException: ensureThis,
|
336
|
-
import(what) {
|
337
|
-
throw new VMError('Dynamic Import not supported');
|
338
|
-
}
|
339
|
-
});
|
340
|
-
|
341
|
-
if (!localReflectDefineProperty(global, host.INTERNAL_STATE_NAME, {
|
342
|
-
__proto__: null,
|
343
|
-
configurable: false,
|
344
|
-
enumerable: false,
|
345
|
-
writable: false,
|
346
|
-
value: interanState
|
347
|
-
})) throw localUnexpected();
|
348
|
-
|
349
|
-
/*
|
350
|
-
* Eval sanitization
|
351
|
-
*/
|
352
|
-
|
353
|
-
function throwAsync() {
|
354
|
-
return new VMError('Async not available');
|
355
|
-
}
|
356
|
-
|
357
|
-
function makeFunction(inputArgs, isAsync, isGenerator) {
|
358
|
-
const lastArgs = inputArgs.length - 1;
|
359
|
-
let code = lastArgs >= 0 ? `${inputArgs[lastArgs]}` : '';
|
360
|
-
let args = lastArgs > 0 ? `${inputArgs[0]}` : '';
|
361
|
-
for (let i = 1; i < lastArgs; i++) {
|
362
|
-
args += `,${inputArgs[i]}`;
|
363
|
-
}
|
364
|
-
try {
|
365
|
-
code = host.transformAndCheck(args, code, isAsync, isGenerator, allowAsync);
|
366
|
-
} catch (e) {
|
367
|
-
throw bridge.from(e);
|
368
|
-
}
|
369
|
-
return localEval(code);
|
370
|
-
}
|
371
|
-
|
372
|
-
const FunctionHandler = {
|
373
|
-
__proto__: null,
|
374
|
-
apply(target, thiz, args) {
|
375
|
-
return makeFunction(args, this.isAsync, this.isGenerator);
|
376
|
-
},
|
377
|
-
construct(target, args, newTarget) {
|
378
|
-
return makeFunction(args, this.isAsync, this.isGenerator);
|
379
|
-
}
|
380
|
-
};
|
381
|
-
|
382
|
-
const EvalHandler = {
|
383
|
-
__proto__: null,
|
384
|
-
apply(target, thiz, args) {
|
385
|
-
if (args.length === 0) return undefined;
|
386
|
-
let code = `${args[0]}`;
|
387
|
-
try {
|
388
|
-
code = host.transformAndCheck(null, code, false, false, allowAsync);
|
389
|
-
} catch (e) {
|
390
|
-
throw bridge.from(e);
|
391
|
-
}
|
392
|
-
return localEval(code);
|
393
|
-
}
|
394
|
-
};
|
395
|
-
|
396
|
-
const AsyncErrorHandler = {
|
397
|
-
__proto__: null,
|
398
|
-
apply(target, thiz, args) {
|
399
|
-
throw throwAsync();
|
400
|
-
},
|
401
|
-
construct(target, args, newTarget) {
|
402
|
-
throw throwAsync();
|
403
|
-
}
|
404
|
-
};
|
405
|
-
|
406
|
-
function makeCheckFunction(isAsync, isGenerator) {
|
407
|
-
if (isAsync && !allowAsync) return AsyncErrorHandler;
|
408
|
-
return {
|
409
|
-
__proto__: FunctionHandler,
|
410
|
-
isAsync,
|
411
|
-
isGenerator
|
412
|
-
};
|
413
|
-
}
|
414
|
-
|
415
|
-
function overrideWithProxy(obj, prop, value, handler) {
|
416
|
-
const proxy = new LocalProxy(value, handler);
|
417
|
-
if (!localReflectDefineProperty(obj, prop, {__proto__: null, value: proxy})) throw localUnexpected();
|
418
|
-
return proxy;
|
419
|
-
}
|
420
|
-
|
421
|
-
const proxiedFunction = overrideWithProxy(localFunction.prototype, 'constructor', localFunction, makeCheckFunction(false, false));
|
422
|
-
if (GeneratorFunction) {
|
423
|
-
if (!localReflectSetPrototypeOf(GeneratorFunction, proxiedFunction)) throw localUnexpected();
|
424
|
-
overrideWithProxy(GeneratorFunction.prototype, 'constructor', GeneratorFunction, makeCheckFunction(false, true));
|
425
|
-
}
|
426
|
-
if (AsyncFunction) {
|
427
|
-
if (!localReflectSetPrototypeOf(AsyncFunction, proxiedFunction)) throw localUnexpected();
|
428
|
-
overrideWithProxy(AsyncFunction.prototype, 'constructor', AsyncFunction, makeCheckFunction(true, false));
|
429
|
-
}
|
430
|
-
if (AsyncGeneratorFunction) {
|
431
|
-
if (!localReflectSetPrototypeOf(AsyncGeneratorFunction, proxiedFunction)) throw localUnexpected();
|
432
|
-
overrideWithProxy(AsyncGeneratorFunction.prototype, 'constructor', AsyncGeneratorFunction, makeCheckFunction(true, true));
|
433
|
-
}
|
434
|
-
|
435
|
-
global.Function = proxiedFunction;
|
436
|
-
global.eval = new LocalProxy(localEval, EvalHandler);
|
437
|
-
|
438
|
-
/*
|
439
|
-
* Promise sanitization
|
440
|
-
*/
|
441
|
-
|
442
|
-
if (localPromise) {
|
443
|
-
|
444
|
-
const PromisePrototype = localPromise.prototype;
|
445
|
-
|
446
|
-
if (!allowAsync) {
|
447
|
-
|
448
|
-
overrideWithProxy(PromisePrototype, 'then', PromisePrototype.then, AsyncErrorHandler);
|
449
|
-
// This seems not to work, and will produce
|
450
|
-
// UnhandledPromiseRejectionWarning: TypeError: Method Promise.prototype.then called on incompatible receiver [object Object].
|
451
|
-
// This is likely caused since the host.Promise.prototype.then cannot use the VM Proxy object.
|
452
|
-
// Contextify.connect(host.Promise.prototype.then, Promise.prototype.then);
|
453
|
-
|
454
|
-
} else {
|
455
|
-
|
456
|
-
overrideWithProxy(PromisePrototype, 'then', PromisePrototype.then, {
|
457
|
-
__proto__: null,
|
458
|
-
apply(target, thiz, args) {
|
459
|
-
if (args.length > 1) {
|
460
|
-
const onRejected = args[1];
|
461
|
-
if (typeof onRejected === 'function') {
|
462
|
-
args[1] = function wrapper(error) {
|
463
|
-
error = ensureThis(error);
|
464
|
-
return localReflectApply(onRejected, this, [error]);
|
465
|
-
};
|
466
|
-
}
|
467
|
-
}
|
468
|
-
return localReflectApply(target, thiz, args);
|
469
|
-
}
|
470
|
-
});
|
471
|
-
|
472
|
-
}
|
473
|
-
|
474
|
-
}
|
475
|
-
|
476
|
-
function readonly(other, mock) {
|
477
|
-
// Note: other@other(unsafe) mock@other(unsafe) returns@this(unsafe) throws@this(unsafe)
|
478
|
-
if (!mock) return fromWithFactory(readonlyFactory, other);
|
479
|
-
const tmock = from(mock);
|
480
|
-
return fromWithFactory(obj=>new ReadOnlyMockHandler(obj, tmock), other);
|
481
|
-
}
|
482
|
-
|
483
|
-
return {
|
484
|
-
__proto__: null,
|
485
|
-
readonly,
|
486
|
-
global
|
487
|
-
};
|