@enclave-vm/core 2.14.0 → 2.15.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/esm/index.mjs +194 -42
- package/esm/worker.mjs +682 -0
- package/index.js +194 -42
- package/package.json +4 -3
- package/src/adapters/worker-pool/package.json +4 -3
- package/src/adapters/worker-pool/worker-script.js +27 -4
- package/worker.d.ts +1 -1
- package/worker.js +722 -0
package/index.js
CHANGED
|
@@ -145,15 +145,42 @@ var init_reference_config = __esm({
|
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
// libs/core/src/sidecar/reference-resolver.ts
|
|
148
|
+
function untrustedLength(value) {
|
|
149
|
+
const rawLen = ReflectGet(value, "length");
|
|
150
|
+
if (typeof rawLen !== "number" || !NumberIsFinite(rawLen) || rawLen < 0) {
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
const len = MathFloor(rawLen);
|
|
154
|
+
if (len > MAX_TRAVERSAL_LENGTH) {
|
|
155
|
+
throw new ResolutionLimitError(
|
|
156
|
+
`Array length ${len} exceeds maximum traversal limit (${MAX_TRAVERSAL_LENGTH})`,
|
|
157
|
+
"MAX_TRAVERSAL_LENGTH",
|
|
158
|
+
MAX_TRAVERSAL_LENGTH,
|
|
159
|
+
len
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
return len;
|
|
163
|
+
}
|
|
164
|
+
function untrustedAt(value, index) {
|
|
165
|
+
try {
|
|
166
|
+
return ReflectGet(value, index);
|
|
167
|
+
} catch {
|
|
168
|
+
return void 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
148
171
|
function isCompositeHandle(value) {
|
|
149
172
|
const obj = value;
|
|
150
173
|
return typeof value === "object" && value !== null && obj["__type"] === "composite" && Array.isArray(obj["__parts"]);
|
|
151
174
|
}
|
|
152
|
-
var ResolutionLimitError, ReferenceResolver;
|
|
175
|
+
var ReflectGet, NumberIsFinite, MathFloor, MAX_TRAVERSAL_LENGTH, ResolutionLimitError, ReferenceResolver;
|
|
153
176
|
var init_reference_resolver = __esm({
|
|
154
177
|
"libs/core/src/sidecar/reference-resolver.ts"() {
|
|
155
178
|
"use strict";
|
|
156
179
|
init_reference_config();
|
|
180
|
+
ReflectGet = Reflect.get;
|
|
181
|
+
NumberIsFinite = Number.isFinite;
|
|
182
|
+
MathFloor = Math.floor;
|
|
183
|
+
MAX_TRAVERSAL_LENGTH = 1e6;
|
|
157
184
|
ResolutionLimitError = class _ResolutionLimitError extends Error {
|
|
158
185
|
constructor(message, code, limit, actual) {
|
|
159
186
|
super(message);
|
|
@@ -197,17 +224,24 @@ var init_reference_resolver = __esm({
|
|
|
197
224
|
return size;
|
|
198
225
|
}
|
|
199
226
|
if (isCompositeHandle(value)) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
227
|
+
const parts = value.__parts;
|
|
228
|
+
const len = untrustedLength(parts);
|
|
229
|
+
let sum = 0;
|
|
230
|
+
for (let i = 0; i < len; i++) {
|
|
231
|
+
sum += this.predictExpandedSize(untrustedAt(parts, i), depth + 1);
|
|
232
|
+
}
|
|
233
|
+
return sum;
|
|
203
234
|
}
|
|
204
235
|
if (typeof value === "string") {
|
|
205
236
|
return Buffer.byteLength(value, "utf-8");
|
|
206
237
|
}
|
|
207
238
|
if (Array.isArray(value)) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
239
|
+
const len = untrustedLength(value);
|
|
240
|
+
let sum = 0;
|
|
241
|
+
for (let i = 0; i < len; i++) {
|
|
242
|
+
sum += this.predictExpandedSize(untrustedAt(value, i), depth + 1);
|
|
243
|
+
}
|
|
244
|
+
return sum;
|
|
211
245
|
}
|
|
212
246
|
if (value !== null && typeof value === "object") {
|
|
213
247
|
return Object.values(value).reduce((sum, val) => {
|
|
@@ -268,7 +302,12 @@ var init_reference_resolver = __esm({
|
|
|
268
302
|
return value;
|
|
269
303
|
}
|
|
270
304
|
if (Array.isArray(value)) {
|
|
271
|
-
|
|
305
|
+
const len = untrustedLength(value);
|
|
306
|
+
const out = [];
|
|
307
|
+
for (let i = 0; i < len; i++) {
|
|
308
|
+
out[i] = this.resolve(untrustedAt(value, i), depth + 1);
|
|
309
|
+
}
|
|
310
|
+
return out;
|
|
272
311
|
}
|
|
273
312
|
if (value !== null && typeof value === "object") {
|
|
274
313
|
const resolved = /* @__PURE__ */ Object.create(null);
|
|
@@ -283,15 +322,17 @@ var init_reference_resolver = __esm({
|
|
|
283
322
|
* Resolve a composite handle by concatenating its parts
|
|
284
323
|
*/
|
|
285
324
|
resolveComposite(handle, depth) {
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
325
|
+
const out = [];
|
|
326
|
+
const source = handle.__parts;
|
|
327
|
+
const len = untrustedLength(source);
|
|
328
|
+
for (let i = 0; i < len; i++) {
|
|
329
|
+
const resolved = this.resolve(untrustedAt(source, i), depth + 1);
|
|
289
330
|
if (typeof resolved !== "string") {
|
|
290
331
|
throw new Error(`Composite part resolved to non-string: ${typeof resolved}`);
|
|
291
332
|
}
|
|
292
|
-
|
|
333
|
+
out.push(resolved);
|
|
293
334
|
}
|
|
294
|
-
return
|
|
335
|
+
return out.join("");
|
|
295
336
|
}
|
|
296
337
|
/**
|
|
297
338
|
* Check if a value contains any reference IDs
|
|
@@ -308,7 +349,13 @@ var init_reference_resolver = __esm({
|
|
|
308
349
|
return true;
|
|
309
350
|
}
|
|
310
351
|
if (Array.isArray(value)) {
|
|
311
|
-
|
|
352
|
+
const len = untrustedLength(value);
|
|
353
|
+
for (let i = 0; i < len; i++) {
|
|
354
|
+
if (this.containsReferences(untrustedAt(value, i), depth + 1)) {
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return false;
|
|
312
359
|
}
|
|
313
360
|
if (value !== null && typeof value === "object") {
|
|
314
361
|
return Object.values(value).some((val) => this.containsReferences(val, depth + 1));
|
|
@@ -401,35 +448,53 @@ function sanitizeValue(value, options = {}, depth = 0, context = { propCount: {
|
|
|
401
448
|
}
|
|
402
449
|
context.visited.add(value);
|
|
403
450
|
}
|
|
404
|
-
if (
|
|
405
|
-
|
|
451
|
+
if (ArrayIsArray(value)) {
|
|
452
|
+
const rawLen = ReflectGet2(value, "length");
|
|
453
|
+
const len = typeof rawLen === "number" && NumberIsFinite2(rawLen) && rawLen >= 0 ? MathFloor2(rawLen) : 0;
|
|
454
|
+
context.propCount.count += len;
|
|
406
455
|
if (context.propCount.count > maxProperties) {
|
|
407
456
|
throw new Error(`Tool handler return value exceeds maximum properties (${maxProperties}).`);
|
|
408
457
|
}
|
|
409
|
-
|
|
458
|
+
const result = [];
|
|
459
|
+
for (let i = 0; i < len; i++) {
|
|
460
|
+
let item;
|
|
461
|
+
try {
|
|
462
|
+
item = ReflectGet2(value, i);
|
|
463
|
+
} catch {
|
|
464
|
+
item = void 0;
|
|
465
|
+
}
|
|
466
|
+
result[i] = sanitizeValue(item, options, depth + 1, context);
|
|
467
|
+
}
|
|
468
|
+
return result;
|
|
410
469
|
}
|
|
411
470
|
if (value instanceof Date) {
|
|
471
|
+
const time = ReflectApply(DateProtoGetTime, value, []);
|
|
412
472
|
if (allowDates) {
|
|
413
|
-
return new Date(
|
|
473
|
+
return new Date(time);
|
|
414
474
|
}
|
|
415
|
-
return value
|
|
475
|
+
return ReflectApply(DateProtoToISOString, value, []);
|
|
416
476
|
}
|
|
417
477
|
if (value instanceof Error) {
|
|
478
|
+
const rawName = ReflectGet2(value, "name");
|
|
479
|
+
const rawMessage = ReflectGet2(value, "message");
|
|
480
|
+
const name = typeof rawName === "string" ? rawName : "Error";
|
|
481
|
+
const message = typeof rawMessage === "string" ? rawMessage : "";
|
|
418
482
|
if (allowErrors) {
|
|
419
483
|
return {
|
|
420
|
-
name
|
|
421
|
-
message
|
|
484
|
+
name,
|
|
485
|
+
message
|
|
422
486
|
// Do NOT include stack trace - could leak host information
|
|
423
487
|
};
|
|
424
488
|
}
|
|
425
|
-
return { error:
|
|
489
|
+
return { error: message };
|
|
426
490
|
}
|
|
427
491
|
if (value instanceof RegExp) {
|
|
428
|
-
return value
|
|
492
|
+
return ReflectApply(RegExpProtoToString, value, []);
|
|
429
493
|
}
|
|
430
494
|
if (value instanceof Map) {
|
|
431
|
-
const sanitizedMap =
|
|
432
|
-
|
|
495
|
+
const sanitizedMap = ObjectCreate(null);
|
|
496
|
+
const entries = ReflectApply(MapProtoEntries, value, []);
|
|
497
|
+
for (const [key, val] of entries) {
|
|
433
498
|
if (typeof key !== "string") continue;
|
|
434
499
|
if (DANGEROUS_KEYS.has(key)) continue;
|
|
435
500
|
context.propCount.count++;
|
|
@@ -438,13 +503,17 @@ function sanitizeValue(value, options = {}, depth = 0, context = { propCount: {
|
|
|
438
503
|
return sanitizedMap;
|
|
439
504
|
}
|
|
440
505
|
if (value instanceof Set) {
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
506
|
+
const iter = ReflectApply(SetProtoValues, value, []);
|
|
507
|
+
const result = [];
|
|
508
|
+
for (const item of iter) {
|
|
509
|
+
context.propCount.count++;
|
|
510
|
+
result.push(sanitizeValue(item, options, depth + 1, context));
|
|
511
|
+
}
|
|
512
|
+
return result;
|
|
444
513
|
}
|
|
445
514
|
if (type === "object") {
|
|
446
|
-
const sanitized =
|
|
447
|
-
const keys =
|
|
515
|
+
const sanitized = ObjectCreate(null);
|
|
516
|
+
const keys = ObjectKeys(value);
|
|
448
517
|
context.propCount.count += keys.length;
|
|
449
518
|
if (context.propCount.count > maxProperties) {
|
|
450
519
|
throw new Error(`Tool handler return value exceeds maximum properties (${maxProperties}).`);
|
|
@@ -455,7 +524,7 @@ function sanitizeValue(value, options = {}, depth = 0, context = { propCount: {
|
|
|
455
524
|
}
|
|
456
525
|
let propValue;
|
|
457
526
|
try {
|
|
458
|
-
propValue = value
|
|
527
|
+
propValue = ReflectGet2(value, key);
|
|
459
528
|
} catch {
|
|
460
529
|
continue;
|
|
461
530
|
}
|
|
@@ -593,11 +662,23 @@ function checkSerializedSize(value, maxBytes) {
|
|
|
593
662
|
return { ok: false, error: err instanceof Error ? err.message : "Unknown error" };
|
|
594
663
|
}
|
|
595
664
|
}
|
|
596
|
-
var DANGEROUS_KEYS;
|
|
665
|
+
var DANGEROUS_KEYS, ReflectApply, ReflectGet2, ArrayIsArray, ObjectKeys, ObjectCreate, NumberIsFinite2, MathFloor2, MapProtoEntries, SetProtoValues, DateProtoGetTime, DateProtoToISOString, RegExpProtoToString;
|
|
597
666
|
var init_value_sanitizer = __esm({
|
|
598
667
|
"libs/core/src/value-sanitizer.ts"() {
|
|
599
668
|
"use strict";
|
|
600
669
|
DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor"]);
|
|
670
|
+
ReflectApply = Reflect.apply;
|
|
671
|
+
ReflectGet2 = Reflect.get;
|
|
672
|
+
ArrayIsArray = Array.isArray;
|
|
673
|
+
ObjectKeys = Object.keys;
|
|
674
|
+
ObjectCreate = Object.create;
|
|
675
|
+
NumberIsFinite2 = Number.isFinite;
|
|
676
|
+
MathFloor2 = Math.floor;
|
|
677
|
+
MapProtoEntries = Map.prototype.entries;
|
|
678
|
+
SetProtoValues = Set.prototype.values;
|
|
679
|
+
DateProtoGetTime = Date.prototype.getTime;
|
|
680
|
+
DateProtoToISOString = Date.prototype.toISOString;
|
|
681
|
+
RegExpProtoToString = RegExp.prototype.toString;
|
|
601
682
|
}
|
|
602
683
|
});
|
|
603
684
|
|
|
@@ -925,11 +1006,23 @@ function createSecureProxy(target, options = {}) {
|
|
|
925
1006
|
// Intercept function calls to proxy return values
|
|
926
1007
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Proxy handler signature requires any for compatibility
|
|
927
1008
|
apply(target2, thisArg, argArray) {
|
|
928
|
-
const
|
|
1009
|
+
const unwrappedThis = thisArg !== null && (typeof thisArg === "object" || typeof thisArg === "function") && proxyToTarget.has(thisArg) ? proxyToTarget.get(thisArg) : thisArg;
|
|
1010
|
+
const result = Reflect.apply(target2, unwrappedThis, argArray);
|
|
929
1011
|
if (isProxyable(result)) {
|
|
930
1012
|
return proxyWithDepth(result, depth + 1);
|
|
931
1013
|
}
|
|
932
1014
|
return result;
|
|
1015
|
+
},
|
|
1016
|
+
// Intercept constructor calls to proxy the created instance. Without this, code such as
|
|
1017
|
+
// `new (wrappedCtor)()` would return a RAW object whose prototype chain reaches the
|
|
1018
|
+
// host Function constructor — the same escape class the apply trap closes for calls.
|
|
1019
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Proxy handler signature requires any for compatibility
|
|
1020
|
+
construct(target2, argArray, newTarget) {
|
|
1021
|
+
const instance = Reflect.construct(target2, argArray, newTarget === proxy ? target2 : newTarget);
|
|
1022
|
+
if (isProxyable(instance)) {
|
|
1023
|
+
return proxyWithDepth(instance, depth + 1);
|
|
1024
|
+
}
|
|
1025
|
+
return instance;
|
|
933
1026
|
}
|
|
934
1027
|
});
|
|
935
1028
|
let objCacheMap = proxyCache.get(obj);
|
|
@@ -939,6 +1032,7 @@ function createSecureProxy(target, options = {}) {
|
|
|
939
1032
|
}
|
|
940
1033
|
objCacheMap.set(cacheKey, proxy);
|
|
941
1034
|
proxySet.add(proxy);
|
|
1035
|
+
proxyToTarget.set(proxy, obj);
|
|
942
1036
|
return proxy;
|
|
943
1037
|
}
|
|
944
1038
|
return proxyWithDepth(target, 0);
|
|
@@ -978,7 +1072,7 @@ function isSecureProxy(obj) {
|
|
|
978
1072
|
}
|
|
979
1073
|
return proxySet.has(obj);
|
|
980
1074
|
}
|
|
981
|
-
var BLOCKED_PROPERTY_CATEGORIES, BLOCKED_PROPERTIES, DEFAULT_SECURE_PROXY_CONFIG, FUNCTION_BLOCKED_PROPERTIES, proxyCache, proxySet, NON_PROXYABLE_TYPES, INTERNAL_SLOT_TYPES;
|
|
1075
|
+
var BLOCKED_PROPERTY_CATEGORIES, BLOCKED_PROPERTIES, DEFAULT_SECURE_PROXY_CONFIG, FUNCTION_BLOCKED_PROPERTIES, proxyCache, proxySet, proxyToTarget, NON_PROXYABLE_TYPES, INTERNAL_SLOT_TYPES;
|
|
982
1076
|
var init_secure_proxy = __esm({
|
|
983
1077
|
"libs/core/src/secure-proxy.ts"() {
|
|
984
1078
|
"use strict";
|
|
@@ -1060,6 +1154,7 @@ var init_secure_proxy = __esm({
|
|
|
1060
1154
|
]);
|
|
1061
1155
|
proxyCache = /* @__PURE__ */ new WeakMap();
|
|
1062
1156
|
proxySet = /* @__PURE__ */ new WeakSet();
|
|
1157
|
+
proxyToTarget = /* @__PURE__ */ new WeakMap();
|
|
1063
1158
|
NON_PROXYABLE_TYPES = /* @__PURE__ */ new Set([
|
|
1064
1159
|
// Map/Set have internal slots but we may need to proxy them in the future
|
|
1065
1160
|
"[object Map]",
|
|
@@ -2373,10 +2468,34 @@ ${stackTraceHardeningCode}
|
|
|
2373
2468
|
getPrototypeOf: function(target) {
|
|
2374
2469
|
// Return null to hide prototype chain
|
|
2375
2470
|
return null;
|
|
2376
|
-
}
|
|
2471
|
+
},
|
|
2472
|
+
// SECURITY (GHSA-grmc-r8vw-226r): the get trap re-wraps values obtained via property
|
|
2473
|
+
// ACCESS, but function-call results cross the same trust boundary and must be wrapped
|
|
2474
|
+
// too. Without an apply trap, calling a wrapped function (for example the then method
|
|
2475
|
+
// of the secure Promise returned by callTool) falls through to the default call and
|
|
2476
|
+
// returns a RAW host object; the sandbox can then walk its prototype chain
|
|
2477
|
+
// (Promise.prototype up to Function) to reach the host Function constructor for RCE.
|
|
2478
|
+
// Results are re-wrapped at a FRESH depth (0) so a chain of calls such as
|
|
2479
|
+
// then().then() cannot inflate depth past the recursion cap and leak an unwrapped value.
|
|
2480
|
+
apply: function(target, thisArg, args) {
|
|
2481
|
+
return createSecureProxy(Reflect.apply(target, thisArg, args), 0);
|
|
2482
|
+
}
|
|
2483
|
+
// NOTE: intentionally NO construct trap here (unlike the standalone secure-proxy used
|
|
2484
|
+
// for single-VM mode). Every constructor reachable from sandbox code resolves to an
|
|
2485
|
+
// inner-VM or parent-VM intrinsic, and BOTH of those realms run with code generation
|
|
2486
|
+
// from strings disabled, so a 'new X()' result cannot reach a usable Function
|
|
2487
|
+
// constructor. The only code-generation-enabled realm (the host) is reached solely via
|
|
2488
|
+
// host return values (callTool), which is an apply-path and is covered above. Wrapping
|
|
2489
|
+
// construct results would additionally break the proxy invariant for the frozen (non-
|
|
2490
|
+
// extensible) Error objects the harness throws (getPrototypeOf must not report null for
|
|
2491
|
+
// a non-extensible target), masking legitimate errors.
|
|
2377
2492
|
});
|
|
2378
2493
|
|
|
2379
2494
|
proxyCache.set(obj, proxy);
|
|
2495
|
+
// Idempotency: re-wrapping an already-secure proxy must return it unchanged, so an apply
|
|
2496
|
+
// result that is itself already a secure proxy is not double-wrapped (which would nest
|
|
2497
|
+
// proxies and inflate depth toward the recursion cap).
|
|
2498
|
+
proxyCache.set(proxy, proxy);
|
|
2380
2499
|
return proxy;
|
|
2381
2500
|
}
|
|
2382
2501
|
|
|
@@ -2754,10 +2873,20 @@ ${stackTraceHardeningCode}
|
|
|
2754
2873
|
if (typeof fn !== 'function') {
|
|
2755
2874
|
throw createSafeError('parallel() requires a callback function as second argument', 'TypeError');
|
|
2756
2875
|
}
|
|
2757
|
-
|
|
2876
|
+
// SECURITY: items may be an attacker Proxy that only passes Array.isArray. Read the length
|
|
2877
|
+
// ONCE and build the promise list by index rather than items.map(fn), so a .map trap can
|
|
2878
|
+
// neither be handed our callback nor use a stateful length to slip past the 100-item cap.
|
|
2879
|
+
var len = items.length;
|
|
2880
|
+
if (typeof len !== 'number' || !isFinite(len) || len < 0) len = 0;
|
|
2881
|
+
len = Math.floor(len);
|
|
2882
|
+
if (len > 100) {
|
|
2758
2883
|
throw createSafeError('parallel() is limited to 100 items');
|
|
2759
2884
|
}
|
|
2760
|
-
|
|
2885
|
+
var promises = [];
|
|
2886
|
+
for (var i = 0; i < len; i++) {
|
|
2887
|
+
promises[i] = fn(items[i], i, items);
|
|
2888
|
+
}
|
|
2889
|
+
return await Promise.all(promises);
|
|
2761
2890
|
}
|
|
2762
2891
|
|
|
2763
2892
|
/**
|
|
@@ -6044,6 +6173,24 @@ var init_errors = __esm({
|
|
|
6044
6173
|
});
|
|
6045
6174
|
|
|
6046
6175
|
// libs/core/src/adapters/worker-pool/safe-deserialize.ts
|
|
6176
|
+
function mapArraySafely(value, sanitizeItem) {
|
|
6177
|
+
const rawLen = ReflectGet3(value, "length");
|
|
6178
|
+
const len = typeof rawLen === "number" && NumberIsFinite3(rawLen) && rawLen >= 0 ? MathFloor3(rawLen) : 0;
|
|
6179
|
+
if (len > MAX_ARRAY_LENGTH) {
|
|
6180
|
+
throw new MessageValidationError(`Array exceeds maximum length of ${MAX_ARRAY_LENGTH}`);
|
|
6181
|
+
}
|
|
6182
|
+
const out = [];
|
|
6183
|
+
for (let i = 0; i < len; i++) {
|
|
6184
|
+
let item;
|
|
6185
|
+
try {
|
|
6186
|
+
item = ReflectGet3(value, i);
|
|
6187
|
+
} catch {
|
|
6188
|
+
item = void 0;
|
|
6189
|
+
}
|
|
6190
|
+
out[i] = sanitizeItem(item);
|
|
6191
|
+
}
|
|
6192
|
+
return out;
|
|
6193
|
+
}
|
|
6047
6194
|
function safeDeserialize(raw, maxSizeBytes) {
|
|
6048
6195
|
if (maxSizeBytes !== void 0) {
|
|
6049
6196
|
const byteLength = Buffer.byteLength(raw, "utf-8");
|
|
@@ -6071,8 +6218,8 @@ function sanitizeObjectWithDepthCheck(value, depth) {
|
|
|
6071
6218
|
if (typeof value !== "object") {
|
|
6072
6219
|
return value;
|
|
6073
6220
|
}
|
|
6074
|
-
if (
|
|
6075
|
-
return value
|
|
6221
|
+
if (ArrayIsArray2(value)) {
|
|
6222
|
+
return mapArraySafely(value, (item) => sanitizeObjectWithDepthCheck(item, depth + 1));
|
|
6076
6223
|
}
|
|
6077
6224
|
const result = /* @__PURE__ */ Object.create(null);
|
|
6078
6225
|
for (const key of Object.keys(value)) {
|
|
@@ -6100,8 +6247,8 @@ function sanitizeObject(value, depth = 0) {
|
|
|
6100
6247
|
if (typeof value !== "object") {
|
|
6101
6248
|
return value;
|
|
6102
6249
|
}
|
|
6103
|
-
if (
|
|
6104
|
-
return value
|
|
6250
|
+
if (ArrayIsArray2(value)) {
|
|
6251
|
+
return mapArraySafely(value, (item) => sanitizeObject(item, depth + 1));
|
|
6105
6252
|
}
|
|
6106
6253
|
const result = /* @__PURE__ */ Object.create(null);
|
|
6107
6254
|
for (const key of Object.keys(value)) {
|
|
@@ -6111,11 +6258,16 @@ function sanitizeObject(value, depth = 0) {
|
|
|
6111
6258
|
}
|
|
6112
6259
|
return result;
|
|
6113
6260
|
}
|
|
6114
|
-
var DANGEROUS_KEYS2, MAX_DEPTH;
|
|
6261
|
+
var ReflectGet3, ArrayIsArray2, NumberIsFinite3, MathFloor3, MAX_ARRAY_LENGTH, DANGEROUS_KEYS2, MAX_DEPTH;
|
|
6115
6262
|
var init_safe_deserialize = __esm({
|
|
6116
6263
|
"libs/core/src/adapters/worker-pool/safe-deserialize.ts"() {
|
|
6117
6264
|
"use strict";
|
|
6118
6265
|
init_errors();
|
|
6266
|
+
ReflectGet3 = Reflect.get;
|
|
6267
|
+
ArrayIsArray2 = Array.isArray;
|
|
6268
|
+
NumberIsFinite3 = Number.isFinite;
|
|
6269
|
+
MathFloor3 = Math.floor;
|
|
6270
|
+
MAX_ARRAY_LENGTH = 1e6;
|
|
6119
6271
|
DANGEROUS_KEYS2 = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
6120
6272
|
MAX_DEPTH = 50;
|
|
6121
6273
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enclave-vm/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"description": "Sandbox runtime for secure JavaScript code execution",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"homepage": "https://github.com/agentfront/enclave",
|
|
@@ -44,8 +44,9 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/standalone": "^7.29.0",
|
|
47
|
-
"@enclave-vm/ast": "2.
|
|
48
|
-
"@enclave-vm/types": "2.
|
|
47
|
+
"@enclave-vm/ast": "2.15.0",
|
|
48
|
+
"@enclave-vm/types": "2.15.0",
|
|
49
|
+
"@types/estree": "1.0.8",
|
|
49
50
|
"acorn": "8.15.0",
|
|
50
51
|
"acorn-walk": "8.3.4",
|
|
51
52
|
"astring": "1.9.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enclave-vm/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"description": "Sandbox runtime for secure JavaScript code execution",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"homepage": "https://github.com/agentfront/enclave",
|
|
@@ -46,8 +46,9 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@babel/standalone": "^7.29.0",
|
|
49
|
-
"@enclave-vm/ast": "2.
|
|
50
|
-
"@enclave-vm/types": "2.
|
|
49
|
+
"@enclave-vm/ast": "2.15.0",
|
|
50
|
+
"@enclave-vm/types": "2.15.0",
|
|
51
|
+
"@types/estree": "1.0.8",
|
|
51
52
|
"acorn": "8.15.0",
|
|
52
53
|
"acorn-walk": "8.3.4",
|
|
53
54
|
"astring": "1.9.0",
|
|
@@ -57,6 +57,29 @@ var MessageSizeError = class extends WorkerPoolError {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
// libs/core/src/adapters/worker-pool/safe-deserialize.ts
|
|
60
|
+
var ReflectGet = Reflect.get;
|
|
61
|
+
var ArrayIsArray = Array.isArray;
|
|
62
|
+
var NumberIsFinite = Number.isFinite;
|
|
63
|
+
var MathFloor = Math.floor;
|
|
64
|
+
var MAX_ARRAY_LENGTH = 1e6;
|
|
65
|
+
function mapArraySafely(value, sanitizeItem) {
|
|
66
|
+
const rawLen = ReflectGet(value, "length");
|
|
67
|
+
const len = typeof rawLen === "number" && NumberIsFinite(rawLen) && rawLen >= 0 ? MathFloor(rawLen) : 0;
|
|
68
|
+
if (len > MAX_ARRAY_LENGTH) {
|
|
69
|
+
throw new MessageValidationError(`Array exceeds maximum length of ${MAX_ARRAY_LENGTH}`);
|
|
70
|
+
}
|
|
71
|
+
const out = [];
|
|
72
|
+
for (let i = 0; i < len; i++) {
|
|
73
|
+
let item;
|
|
74
|
+
try {
|
|
75
|
+
item = ReflectGet(value, i);
|
|
76
|
+
} catch {
|
|
77
|
+
item = void 0;
|
|
78
|
+
}
|
|
79
|
+
out[i] = sanitizeItem(item);
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
60
83
|
var DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
61
84
|
var MAX_DEPTH = 50;
|
|
62
85
|
function safeDeserialize(raw, maxSizeBytes) {
|
|
@@ -86,8 +109,8 @@ function sanitizeObjectWithDepthCheck(value, depth) {
|
|
|
86
109
|
if (typeof value !== "object") {
|
|
87
110
|
return value;
|
|
88
111
|
}
|
|
89
|
-
if (
|
|
90
|
-
return value
|
|
112
|
+
if (ArrayIsArray(value)) {
|
|
113
|
+
return mapArraySafely(value, (item) => sanitizeObjectWithDepthCheck(item, depth + 1));
|
|
91
114
|
}
|
|
92
115
|
const result = /* @__PURE__ */ Object.create(null);
|
|
93
116
|
for (const key of Object.keys(value)) {
|
|
@@ -115,8 +138,8 @@ function sanitizeObject(value, depth = 0) {
|
|
|
115
138
|
if (typeof value !== "object") {
|
|
116
139
|
return value;
|
|
117
140
|
}
|
|
118
|
-
if (
|
|
119
|
-
return value
|
|
141
|
+
if (ArrayIsArray(value)) {
|
|
142
|
+
return mapArraySafely(value, (item) => sanitizeObject(item, depth + 1));
|
|
120
143
|
}
|
|
121
144
|
const result = /* @__PURE__ */ Object.create(null);
|
|
122
145
|
for (const key of Object.keys(value)) {
|
package/worker.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { InterpreterAdapter } from './adapters/interpreter-adapter';
|
|
|
2
2
|
export type { InterpreterAdapterOptions } from './adapters/interpreter-adapter';
|
|
3
3
|
export { Interpreter, InterpreterError, StepLimitError } from './interpreter/interpreter';
|
|
4
4
|
export type { InterpreterOptions } from './interpreter/interpreter';
|
|
5
|
-
export type { ExecutionContext, ExecutionResult, ExecutionError, ExecutionStats, ToolHandler
|
|
5
|
+
export type { ExecutionContext, ExecutionResult, ExecutionError, ExecutionStats, ToolHandler } from './types';
|