@enclave-vm/core 2.15.3 → 2.17.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/adapters/worker-pool/protocol.d.ts +26 -1
- package/adapters/worker-pool/result-encoding.d.ts +33 -0
- package/adapters/worker-pool/worker-pool-adapter.d.ts +3 -4
- package/enclave.d.ts +3 -1
- package/esm/index.mjs +195 -41
- package/index.js +197 -43
- package/node-vm.d.ts +13 -0
- package/package.json +3 -3
- package/secure-proxy.d.ts +7 -0
- package/src/adapters/worker-pool/package.json +3 -3
- package/src/adapters/worker-pool/worker-script.js +222 -1
- package/types.d.ts +25 -2
- package/value-sanitizer.d.ts +6 -0
package/index.js
CHANGED
|
@@ -492,6 +492,15 @@ function isSecureProxy(obj) {
|
|
|
492
492
|
}
|
|
493
493
|
return proxySet.has(obj);
|
|
494
494
|
}
|
|
495
|
+
function unwrapSecureProxy(value) {
|
|
496
|
+
let current = value;
|
|
497
|
+
while (current !== null && (typeof current === "object" || typeof current === "function")) {
|
|
498
|
+
const target = proxyToTarget.get(current);
|
|
499
|
+
if (target === void 0) break;
|
|
500
|
+
current = target;
|
|
501
|
+
}
|
|
502
|
+
return current;
|
|
503
|
+
}
|
|
495
504
|
var ObjectGetOwnPropertyDescriptor, ObjectToString, FunctionBind, ReflectGet, ReflectSet, ReflectDefineProperty, ReflectGetOwnPropertyDescriptor2, ReflectOwnKeys2, ReflectApply2, ReflectConstruct, ReflectObject, PINNED_REFLECT_VALUES, FunctionCtor, AsyncFunctionCtor, GeneratorFunctionCtor, AsyncGeneratorFunctionCtor, MIN_MEMBRANE_RECURSION_DEPTH, BLOCKED_PROPERTY_CATEGORIES, BLOCKED_PROPERTIES, DEFAULT_SECURE_PROXY_CONFIG, FUNCTION_BLOCKED_PROPERTIES, gatedProxyCaches, proxyCache, proxySet, proxyToTarget, NON_PROXYABLE_TYPES, INTERNAL_SLOT_TYPES;
|
|
496
505
|
var init_secure_proxy = __esm({
|
|
497
506
|
"libs/core/src/secure-proxy.ts"() {
|
|
@@ -1035,6 +1044,26 @@ var init_reference_resolver = __esm({
|
|
|
1035
1044
|
});
|
|
1036
1045
|
|
|
1037
1046
|
// libs/core/src/value-sanitizer.ts
|
|
1047
|
+
function hasBrand(builtin, value) {
|
|
1048
|
+
if (!builtin) return false;
|
|
1049
|
+
try {
|
|
1050
|
+
ReflectApply3(builtin, value, []);
|
|
1051
|
+
return true;
|
|
1052
|
+
} catch {
|
|
1053
|
+
return false;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
function regExpToString(value) {
|
|
1057
|
+
let flags = "";
|
|
1058
|
+
for (const [flag, getter] of RegExpFlagGetters) {
|
|
1059
|
+
if (getter && ReflectApply3(getter, value, [])) flags += flag;
|
|
1060
|
+
}
|
|
1061
|
+
return `/${ReflectApply3(RegExpProtoSourceGetter, value, [])}/${flags}`;
|
|
1062
|
+
}
|
|
1063
|
+
function isPlainObject(value) {
|
|
1064
|
+
const prototype = ObjectGetPrototypeOf2(value);
|
|
1065
|
+
return prototype === null || ObjectGetPrototypeOf2(prototype) === null;
|
|
1066
|
+
}
|
|
1038
1067
|
function sanitizeValue(value, options = {}, depth = 0, context = { propCount: { count: 0 }, visited: /* @__PURE__ */ new WeakSet() }) {
|
|
1039
1068
|
const maxDepth = options.maxDepth ?? 20;
|
|
1040
1069
|
const maxProperties = options.maxProperties ?? 1e4;
|
|
@@ -1095,12 +1124,14 @@ function sanitizeValue(value, options = {}, depth = 0, context = { propCount: {
|
|
|
1095
1124
|
}
|
|
1096
1125
|
return result;
|
|
1097
1126
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1127
|
+
const inspected = options.unwrap ? options.unwrap(value) : value;
|
|
1128
|
+
const isPlain = isPlainObject(inspected);
|
|
1129
|
+
if (!isPlain && hasBrand(DateProtoGetTime, inspected)) {
|
|
1130
|
+
const time = ReflectApply3(DateProtoGetTime, inspected, []);
|
|
1100
1131
|
if (allowDates) {
|
|
1101
1132
|
return new Date(time);
|
|
1102
1133
|
}
|
|
1103
|
-
return ReflectApply3(DateProtoToISOString,
|
|
1134
|
+
return ReflectApply3(DateProtoToISOString, inspected, []);
|
|
1104
1135
|
}
|
|
1105
1136
|
if (value instanceof Error) {
|
|
1106
1137
|
const rawName = ReflectGet3(value, "name");
|
|
@@ -1116,12 +1147,12 @@ function sanitizeValue(value, options = {}, depth = 0, context = { propCount: {
|
|
|
1116
1147
|
}
|
|
1117
1148
|
return { error: message };
|
|
1118
1149
|
}
|
|
1119
|
-
if (
|
|
1120
|
-
return
|
|
1150
|
+
if (!isPlain && hasBrand(RegExpProtoSourceGetter, inspected)) {
|
|
1151
|
+
return regExpToString(inspected);
|
|
1121
1152
|
}
|
|
1122
|
-
if (
|
|
1153
|
+
if (!isPlain && hasBrand(MapProtoSizeGetter, inspected)) {
|
|
1123
1154
|
const sanitizedMap = ObjectCreate(null);
|
|
1124
|
-
const entries = ReflectApply3(MapProtoEntries,
|
|
1155
|
+
const entries = ReflectApply3(MapProtoEntries, inspected, []);
|
|
1125
1156
|
for (const [key, val] of entries) {
|
|
1126
1157
|
if (typeof key !== "string") continue;
|
|
1127
1158
|
if (DANGEROUS_KEYS.has(key)) continue;
|
|
@@ -1130,8 +1161,8 @@ function sanitizeValue(value, options = {}, depth = 0, context = { propCount: {
|
|
|
1130
1161
|
}
|
|
1131
1162
|
return sanitizedMap;
|
|
1132
1163
|
}
|
|
1133
|
-
if (
|
|
1134
|
-
const iter = ReflectApply3(SetProtoValues,
|
|
1164
|
+
if (!isPlain && hasBrand(SetProtoSizeGetter, inspected)) {
|
|
1165
|
+
const iter = ReflectApply3(SetProtoValues, inspected, []);
|
|
1135
1166
|
const result = [];
|
|
1136
1167
|
for (const item of iter) {
|
|
1137
1168
|
context.propCount.count++;
|
|
@@ -1290,7 +1321,7 @@ function checkSerializedSize(value, maxBytes) {
|
|
|
1290
1321
|
return { ok: false, error: err instanceof Error ? err.message : "Unknown error" };
|
|
1291
1322
|
}
|
|
1292
1323
|
}
|
|
1293
|
-
var DANGEROUS_KEYS, ReflectApply3, ReflectGet3, ArrayIsArray, ObjectKeys, ObjectCreate, NumberIsFinite2, MathFloor2, MapProtoEntries, SetProtoValues, DateProtoGetTime, DateProtoToISOString,
|
|
1324
|
+
var DANGEROUS_KEYS, ReflectApply3, ReflectGet3, ArrayIsArray, ObjectKeys, ObjectCreate, ObjectGetPrototypeOf2, NumberIsFinite2, MathFloor2, MapProtoEntries, SetProtoValues, DateProtoGetTime, DateProtoToISOString, RegExpProtoSourceGetter, RegExpFlagGetters, MapProtoSizeGetter, SetProtoSizeGetter;
|
|
1294
1325
|
var init_value_sanitizer = __esm({
|
|
1295
1326
|
"libs/core/src/value-sanitizer.ts"() {
|
|
1296
1327
|
"use strict";
|
|
@@ -1300,13 +1331,26 @@ var init_value_sanitizer = __esm({
|
|
|
1300
1331
|
ArrayIsArray = Array.isArray;
|
|
1301
1332
|
ObjectKeys = Object.keys;
|
|
1302
1333
|
ObjectCreate = Object.create;
|
|
1334
|
+
ObjectGetPrototypeOf2 = Object.getPrototypeOf;
|
|
1303
1335
|
NumberIsFinite2 = Number.isFinite;
|
|
1304
1336
|
MathFloor2 = Math.floor;
|
|
1305
1337
|
MapProtoEntries = Map.prototype.entries;
|
|
1306
1338
|
SetProtoValues = Set.prototype.values;
|
|
1307
1339
|
DateProtoGetTime = Date.prototype.getTime;
|
|
1308
1340
|
DateProtoToISOString = Date.prototype.toISOString;
|
|
1309
|
-
|
|
1341
|
+
RegExpProtoSourceGetter = Object.getOwnPropertyDescriptor(RegExp.prototype, "source")?.get;
|
|
1342
|
+
RegExpFlagGetters = [
|
|
1343
|
+
["d", "hasIndices"],
|
|
1344
|
+
["g", "global"],
|
|
1345
|
+
["i", "ignoreCase"],
|
|
1346
|
+
["m", "multiline"],
|
|
1347
|
+
["s", "dotAll"],
|
|
1348
|
+
["u", "unicode"],
|
|
1349
|
+
["v", "unicodeSets"],
|
|
1350
|
+
["y", "sticky"]
|
|
1351
|
+
].map(([flag, property]) => [flag, Object.getOwnPropertyDescriptor(RegExp.prototype, property)?.get]);
|
|
1352
|
+
MapProtoSizeGetter = Object.getOwnPropertyDescriptor(Map.prototype, "size")?.get;
|
|
1353
|
+
SetProtoSizeGetter = Object.getOwnPropertyDescriptor(Set.prototype, "size")?.get;
|
|
1310
1354
|
}
|
|
1311
1355
|
});
|
|
1312
1356
|
|
|
@@ -1455,7 +1499,7 @@ function createGlobalFunctionGate(context, realm) {
|
|
|
1455
1499
|
}
|
|
1456
1500
|
};
|
|
1457
1501
|
}
|
|
1458
|
-
var ReflectApply4, ReflectOwnKeys3, ObjectGetOwnPropertyDescriptor2,
|
|
1502
|
+
var ReflectApply4, ReflectOwnKeys3, ObjectGetOwnPropertyDescriptor2, ObjectGetPrototypeOf3, ArrayIsArray2, JsonStringify, BUILTIN_METHODS, DEFAULT_GLOBAL_FUNCTION_CALLS_PER_TOOL_CALL, DEFAULT_MAX_PAYLOAD_BYTES, MAX_ERROR_MESSAGE_LENGTH, MAX_ERROR_NAME_LENGTH, UNSAFE_RESULT_MESSAGE;
|
|
1459
1503
|
var init_global_function_gate = __esm({
|
|
1460
1504
|
"libs/core/src/global-function-gate.ts"() {
|
|
1461
1505
|
"use strict";
|
|
@@ -1464,7 +1508,7 @@ var init_global_function_gate = __esm({
|
|
|
1464
1508
|
ReflectApply4 = Reflect.apply;
|
|
1465
1509
|
ReflectOwnKeys3 = Reflect.ownKeys;
|
|
1466
1510
|
ObjectGetOwnPropertyDescriptor2 = Object.getOwnPropertyDescriptor;
|
|
1467
|
-
|
|
1511
|
+
ObjectGetPrototypeOf3 = Object.getPrototypeOf;
|
|
1468
1512
|
ArrayIsArray2 = Array.isArray;
|
|
1469
1513
|
JsonStringify = JSON.stringify;
|
|
1470
1514
|
BUILTIN_METHODS = (() => {
|
|
@@ -1482,7 +1526,7 @@ var init_global_function_gate = __esm({
|
|
|
1482
1526
|
BigInt64Array,
|
|
1483
1527
|
BigUint64Array
|
|
1484
1528
|
];
|
|
1485
|
-
const arrayIteratorPrototype =
|
|
1529
|
+
const arrayIteratorPrototype = ObjectGetPrototypeOf3([][Symbol.iterator]());
|
|
1486
1530
|
const prototypes = [
|
|
1487
1531
|
Object.prototype,
|
|
1488
1532
|
Array.prototype,
|
|
@@ -1507,15 +1551,15 @@ var init_global_function_gate = __esm({
|
|
|
1507
1551
|
Promise.prototype,
|
|
1508
1552
|
ArrayBuffer.prototype,
|
|
1509
1553
|
DataView.prototype,
|
|
1510
|
-
|
|
1554
|
+
ObjectGetPrototypeOf3(Uint8Array.prototype),
|
|
1511
1555
|
// %TypedArray%.prototype
|
|
1512
1556
|
...typedArrays.map((TypedArray) => TypedArray.prototype),
|
|
1513
1557
|
arrayIteratorPrototype,
|
|
1514
|
-
|
|
1558
|
+
ObjectGetPrototypeOf3(arrayIteratorPrototype),
|
|
1515
1559
|
// %IteratorPrototype%
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1560
|
+
ObjectGetPrototypeOf3((/* @__PURE__ */ new Map())[Symbol.iterator]()),
|
|
1561
|
+
ObjectGetPrototypeOf3((/* @__PURE__ */ new Set())[Symbol.iterator]()),
|
|
1562
|
+
ObjectGetPrototypeOf3(""[Symbol.iterator]())
|
|
1519
1563
|
];
|
|
1520
1564
|
for (const prototype of prototypes) {
|
|
1521
1565
|
if (prototype === null || typeof prototype !== "object") continue;
|
|
@@ -4659,11 +4703,11 @@ var init_suspicious_patterns = __esm({
|
|
|
4659
4703
|
});
|
|
4660
4704
|
|
|
4661
4705
|
// libs/core/src/double-vm/double-vm-wrapper.ts
|
|
4662
|
-
var
|
|
4706
|
+
var vm3, DoubleVmWrapper;
|
|
4663
4707
|
var init_double_vm_wrapper = __esm({
|
|
4664
4708
|
"libs/core/src/double-vm/double-vm-wrapper.ts"() {
|
|
4665
4709
|
"use strict";
|
|
4666
|
-
|
|
4710
|
+
vm3 = __toESM(require("vm"));
|
|
4667
4711
|
init_value_sanitizer();
|
|
4668
4712
|
init_secure_proxy();
|
|
4669
4713
|
init_safe_error();
|
|
@@ -4701,7 +4745,7 @@ var init_double_vm_wrapper = __esm({
|
|
|
4701
4745
|
});
|
|
4702
4746
|
this.parentContext = parentContext;
|
|
4703
4747
|
const parentScript = this.buildParentScript(code, executionContext);
|
|
4704
|
-
const script = new
|
|
4748
|
+
const script = new vm3.Script(parentScript, {
|
|
4705
4749
|
filename: "parent-vm.js"
|
|
4706
4750
|
});
|
|
4707
4751
|
const parentTimeout = config.timeout + this.config.parentTimeoutBuffer;
|
|
@@ -4813,15 +4857,15 @@ var init_double_vm_wrapper = __esm({
|
|
|
4813
4857
|
*/
|
|
4814
4858
|
createParentContext(executionContext, memoryTracker, reportViolation) {
|
|
4815
4859
|
const { stats, config } = executionContext;
|
|
4816
|
-
const parentContext =
|
|
4860
|
+
const parentContext = vm3.createContext(
|
|
4817
4861
|
{},
|
|
4818
4862
|
{
|
|
4819
4863
|
codeGeneration: { strings: false, wasm: false }
|
|
4820
4864
|
}
|
|
4821
4865
|
);
|
|
4822
4866
|
const safeVm = {
|
|
4823
|
-
createContext:
|
|
4824
|
-
Script:
|
|
4867
|
+
createContext: vm3.createContext.bind(vm3),
|
|
4868
|
+
Script: vm3.Script
|
|
4825
4869
|
};
|
|
4826
4870
|
Object.defineProperty(parentContext, "__host_vm_module__", {
|
|
4827
4871
|
value: safeVm,
|
|
@@ -5906,11 +5950,11 @@ function sanitizeVmContext(context, securityLevel) {
|
|
|
5906
5950
|
enumerable: true
|
|
5907
5951
|
});
|
|
5908
5952
|
}
|
|
5909
|
-
var
|
|
5953
|
+
var vm4, STACK_TRACE_HARDENING_CODE, STACK_TRACE_HARDENING_SCRIPT, CODE_GENERATION_VIOLATION_DETECTOR_CODE, CODE_GENERATION_VIOLATION_DETECTOR_SCRIPT, INTRINSIC_OBJECT_NEUTRALIZATION_CODE, INTRINSIC_OBJECT_NEUTRALIZATION_SCRIPT, SANDBOX_REALM_BRIDGE_SCRIPT, TOOL_NAMESPACE_FACTORY_SCRIPT, PROTECTED_PREFIXES, DANGEROUS_OBJECT_STATIC_METHODS, NODEJS_24_DANGEROUS_GLOBALS2, VmAdapter;
|
|
5910
5954
|
var init_vm_adapter = __esm({
|
|
5911
5955
|
"libs/core/src/adapters/vm-adapter.ts"() {
|
|
5912
5956
|
"use strict";
|
|
5913
|
-
|
|
5957
|
+
vm4 = __toESM(require("vm"));
|
|
5914
5958
|
init_safe_runtime();
|
|
5915
5959
|
init_secure_proxy();
|
|
5916
5960
|
init_safe_error();
|
|
@@ -6019,7 +6063,7 @@ var init_vm_adapter = __esm({
|
|
|
6019
6063
|
} catch (e) {}
|
|
6020
6064
|
})();
|
|
6021
6065
|
`.trim();
|
|
6022
|
-
STACK_TRACE_HARDENING_SCRIPT = new
|
|
6066
|
+
STACK_TRACE_HARDENING_SCRIPT = new vm4.Script(STACK_TRACE_HARDENING_CODE);
|
|
6023
6067
|
CODE_GENERATION_VIOLATION_DETECTOR_CODE = `
|
|
6024
6068
|
(function() {
|
|
6025
6069
|
var __ag_report = (typeof __ag_reportViolation__ === 'function') ? __ag_reportViolation__ : null;
|
|
@@ -6068,7 +6112,7 @@ var init_vm_adapter = __esm({
|
|
|
6068
6112
|
try { __ag_wrapCtor((async function*(){}).constructor, 'CODE_GENERATION'); } catch (e) {}
|
|
6069
6113
|
})();
|
|
6070
6114
|
`.trim();
|
|
6071
|
-
CODE_GENERATION_VIOLATION_DETECTOR_SCRIPT = new
|
|
6115
|
+
CODE_GENERATION_VIOLATION_DETECTOR_SCRIPT = new vm4.Script(CODE_GENERATION_VIOLATION_DETECTOR_CODE);
|
|
6072
6116
|
INTRINSIC_OBJECT_NEUTRALIZATION_CODE = `
|
|
6073
6117
|
(function() {
|
|
6074
6118
|
var RealObject = Object.getPrototypeOf({}).constructor;
|
|
@@ -6084,8 +6128,8 @@ var init_vm_adapter = __esm({
|
|
|
6084
6128
|
}
|
|
6085
6129
|
})();
|
|
6086
6130
|
`;
|
|
6087
|
-
INTRINSIC_OBJECT_NEUTRALIZATION_SCRIPT = new
|
|
6088
|
-
SANDBOX_REALM_BRIDGE_SCRIPT = new
|
|
6131
|
+
INTRINSIC_OBJECT_NEUTRALIZATION_SCRIPT = new vm4.Script(INTRINSIC_OBJECT_NEUTRALIZATION_CODE);
|
|
6132
|
+
SANDBOX_REALM_BRIDGE_SCRIPT = new vm4.Script(`
|
|
6089
6133
|
(function () {
|
|
6090
6134
|
'use strict';
|
|
6091
6135
|
var parse = JSON.parse;
|
|
@@ -6098,7 +6142,7 @@ var init_vm_adapter = __esm({
|
|
|
6098
6142
|
});
|
|
6099
6143
|
})()
|
|
6100
6144
|
`);
|
|
6101
|
-
TOOL_NAMESPACE_FACTORY_SCRIPT = new
|
|
6145
|
+
TOOL_NAMESPACE_FACTORY_SCRIPT = new vm4.Script(TOOL_NAMESPACE_FACTORY_SOURCE, { filename: "tool-namespaces.js" });
|
|
6102
6146
|
PROTECTED_PREFIXES = ["__safe_", "__ag_"];
|
|
6103
6147
|
DANGEROUS_OBJECT_STATIC_METHODS = [
|
|
6104
6148
|
"defineProperty",
|
|
@@ -6214,7 +6258,7 @@ var init_vm_adapter = __esm({
|
|
|
6214
6258
|
}) : void 0;
|
|
6215
6259
|
memoryTracker?.start();
|
|
6216
6260
|
try {
|
|
6217
|
-
const baseSandbox =
|
|
6261
|
+
const baseSandbox = vm4.createContext(
|
|
6218
6262
|
{},
|
|
6219
6263
|
{
|
|
6220
6264
|
codeGeneration: { strings: false, wasm: false }
|
|
@@ -6240,7 +6284,7 @@ var init_vm_adapter = __esm({
|
|
|
6240
6284
|
configurable: true,
|
|
6241
6285
|
enumerable: false
|
|
6242
6286
|
});
|
|
6243
|
-
const patchScript = new
|
|
6287
|
+
const patchScript = new vm4.Script(`
|
|
6244
6288
|
(function() {
|
|
6245
6289
|
var memoryLimit = ${config.memoryLimit};
|
|
6246
6290
|
var trackMemory = __host_memory_track__;
|
|
@@ -6383,7 +6427,7 @@ var init_vm_adapter = __esm({
|
|
|
6383
6427
|
// allow deletion after capture
|
|
6384
6428
|
enumerable: false
|
|
6385
6429
|
});
|
|
6386
|
-
const bridgeInitScript = new
|
|
6430
|
+
const bridgeInitScript = new vm4.Script(`
|
|
6387
6431
|
(function() {
|
|
6388
6432
|
var bridge = __host_callToolBridge__;
|
|
6389
6433
|
var stringify = JSON.stringify;
|
|
@@ -6595,7 +6639,7 @@ var init_vm_adapter = __esm({
|
|
|
6595
6639
|
const _protectedSandbox = createProtectedSandbox(baseSandbox);
|
|
6596
6640
|
this.context = baseSandbox;
|
|
6597
6641
|
const wrappedCode = "(async () => {\n" + code + '\nreturn typeof __ag_main === "function" ? await __ag_main() : undefined;\n})();';
|
|
6598
|
-
const script = new
|
|
6642
|
+
const script = new vm4.Script(wrappedCode, {
|
|
6599
6643
|
filename: "agentscript.js"
|
|
6600
6644
|
});
|
|
6601
6645
|
const resultPromise = script.runInContext(this.context, {
|
|
@@ -6644,7 +6688,9 @@ var init_vm_adapter = __esm({
|
|
|
6644
6688
|
maxDepth: clampedDepth,
|
|
6645
6689
|
maxProperties: clampedProperties,
|
|
6646
6690
|
allowDates: true,
|
|
6647
|
-
allowErrors: true
|
|
6691
|
+
allowErrors: true,
|
|
6692
|
+
// The membrane wraps the script's Dates; read them through their targets.
|
|
6693
|
+
unwrap: unwrapSecureProxy
|
|
6648
6694
|
});
|
|
6649
6695
|
return {
|
|
6650
6696
|
success: true,
|
|
@@ -6852,6 +6898,13 @@ var init_protocol = __esm({
|
|
|
6852
6898
|
requestId: import_zod.z.string().min(1).max(100).regex(ID_PATTERN),
|
|
6853
6899
|
success: import_zod.z.boolean(),
|
|
6854
6900
|
value: import_zod.z.unknown().optional(),
|
|
6901
|
+
specialValues: import_zod.z.array(
|
|
6902
|
+
import_zod.z.object({
|
|
6903
|
+
path: import_zod.z.array(import_zod.z.union([import_zod.z.string(), import_zod.z.number().int().nonnegative()])).max(64),
|
|
6904
|
+
kind: import_zod.z.enum(["date", "nan", "infinity", "-infinity", "undefined"]),
|
|
6905
|
+
time: import_zod.z.number().nullable().optional()
|
|
6906
|
+
}).strict()
|
|
6907
|
+
).optional(),
|
|
6855
6908
|
error: import_zod.z.object({
|
|
6856
6909
|
name: import_zod.z.string().max(100),
|
|
6857
6910
|
message: import_zod.z.string().max(1e4),
|
|
@@ -7089,6 +7142,9 @@ function safeSerialize(value) {
|
|
|
7089
7142
|
return val;
|
|
7090
7143
|
});
|
|
7091
7144
|
}
|
|
7145
|
+
function isDangerousKey(key) {
|
|
7146
|
+
return DANGEROUS_KEYS2.has(key);
|
|
7147
|
+
}
|
|
7092
7148
|
function sanitizeObject(value, depth = 0) {
|
|
7093
7149
|
if (depth > MAX_DEPTH) {
|
|
7094
7150
|
return void 0;
|
|
@@ -7815,6 +7871,75 @@ var init_rate_limiter = __esm({
|
|
|
7815
7871
|
}
|
|
7816
7872
|
});
|
|
7817
7873
|
|
|
7874
|
+
// libs/core/src/adapters/worker-pool/result-encoding.ts
|
|
7875
|
+
function decodeResult(value, specialValues) {
|
|
7876
|
+
if (specialValues === void 0) {
|
|
7877
|
+
return value;
|
|
7878
|
+
}
|
|
7879
|
+
if (!Array.isArray(specialValues)) {
|
|
7880
|
+
throw new MessageValidationError("Worker result special values must be an array");
|
|
7881
|
+
}
|
|
7882
|
+
let decoded = value;
|
|
7883
|
+
for (const special of specialValues) {
|
|
7884
|
+
assertSpecialValue(special);
|
|
7885
|
+
const restored = restoreSpecialValue(special);
|
|
7886
|
+
if (special.path.length === 0) {
|
|
7887
|
+
decoded = restored;
|
|
7888
|
+
continue;
|
|
7889
|
+
}
|
|
7890
|
+
const container = resolveContainer(decoded, special.path.slice(0, -1));
|
|
7891
|
+
const key = special.path[special.path.length - 1];
|
|
7892
|
+
if (!container || !Object.hasOwn(container, key) || container[key] !== null) {
|
|
7893
|
+
throw new MessageValidationError("Worker result refers to a value it does not contain");
|
|
7894
|
+
}
|
|
7895
|
+
container[key] = restored;
|
|
7896
|
+
}
|
|
7897
|
+
return decoded;
|
|
7898
|
+
}
|
|
7899
|
+
function assertSpecialValue(special) {
|
|
7900
|
+
const candidate = special;
|
|
7901
|
+
const validPath = Array.isArray(candidate?.path) && candidate.path.every((key) => typeof key === "string" || Number.isInteger(key) && key >= 0);
|
|
7902
|
+
if (!validPath || !SPECIAL_KINDS.has(candidate?.kind)) {
|
|
7903
|
+
throw new MessageValidationError("Worker result has an invalid special value");
|
|
7904
|
+
}
|
|
7905
|
+
}
|
|
7906
|
+
function resolveContainer(root, path2) {
|
|
7907
|
+
let current = root;
|
|
7908
|
+
for (const key of path2) {
|
|
7909
|
+
if (!isDataContainer(current) || isDangerousKey(String(key)) || !Object.hasOwn(current, key)) {
|
|
7910
|
+
return void 0;
|
|
7911
|
+
}
|
|
7912
|
+
current = current[key];
|
|
7913
|
+
}
|
|
7914
|
+
return isDataContainer(current) ? current : void 0;
|
|
7915
|
+
}
|
|
7916
|
+
function isDataContainer(value) {
|
|
7917
|
+
return Array.isArray(value) || typeof value === "object" && value !== null && Object.getPrototypeOf(value) === null;
|
|
7918
|
+
}
|
|
7919
|
+
function restoreSpecialValue(special) {
|
|
7920
|
+
switch (special.kind) {
|
|
7921
|
+
case "date":
|
|
7922
|
+
return new Date(typeof special.time === "number" ? special.time : NaN);
|
|
7923
|
+
case "nan":
|
|
7924
|
+
return NaN;
|
|
7925
|
+
case "infinity":
|
|
7926
|
+
return Infinity;
|
|
7927
|
+
case "-infinity":
|
|
7928
|
+
return -Infinity;
|
|
7929
|
+
case "undefined":
|
|
7930
|
+
return void 0;
|
|
7931
|
+
}
|
|
7932
|
+
}
|
|
7933
|
+
var SPECIAL_KINDS;
|
|
7934
|
+
var init_result_encoding = __esm({
|
|
7935
|
+
"libs/core/src/adapters/worker-pool/result-encoding.ts"() {
|
|
7936
|
+
"use strict";
|
|
7937
|
+
init_errors();
|
|
7938
|
+
init_safe_deserialize();
|
|
7939
|
+
SPECIAL_KINDS = /* @__PURE__ */ new Set(["date", "nan", "infinity", "-infinity", "undefined"]);
|
|
7940
|
+
}
|
|
7941
|
+
});
|
|
7942
|
+
|
|
7818
7943
|
// libs/core/src/adapters/worker-pool/worker-pool-adapter.ts
|
|
7819
7944
|
var import_crypto3, WorkerPoolAdapter;
|
|
7820
7945
|
var init_worker_pool_adapter = __esm({
|
|
@@ -7828,6 +7953,7 @@ var init_worker_pool_adapter = __esm({
|
|
|
7828
7953
|
init_memory_monitor();
|
|
7829
7954
|
init_rate_limiter();
|
|
7830
7955
|
init_safe_deserialize();
|
|
7956
|
+
init_result_encoding();
|
|
7831
7957
|
init_errors();
|
|
7832
7958
|
init_stack_trace();
|
|
7833
7959
|
WorkerPoolAdapter = class {
|
|
@@ -8173,16 +8299,15 @@ var init_worker_pool_adapter = __esm({
|
|
|
8173
8299
|
/**
|
|
8174
8300
|
* Build result from worker message.
|
|
8175
8301
|
*
|
|
8176
|
-
* Note: The `
|
|
8177
|
-
*
|
|
8178
|
-
*
|
|
8179
|
-
* definitions which are not available at this layer.
|
|
8302
|
+
* Note: The `as T` assertion is inherent to cross-thread serialization boundaries. The
|
|
8303
|
+
* worker sanitizes the result with sanitizeValue() and sends the values JSON cannot carry
|
|
8304
|
+
* (Dates, NaN, ...) separately; decodeResult() puts them back and refuses a malformed list.
|
|
8180
8305
|
*/
|
|
8181
8306
|
buildResult(msg, duration, sanitizeStacks) {
|
|
8182
8307
|
if (msg.success) {
|
|
8183
8308
|
return {
|
|
8184
8309
|
success: true,
|
|
8185
|
-
value: msg.value,
|
|
8310
|
+
value: decodeResult(msg.value, msg.specialValues),
|
|
8186
8311
|
stats: {
|
|
8187
8312
|
duration,
|
|
8188
8313
|
toolCallCount: msg.stats.toolCallCount,
|
|
@@ -11195,6 +11320,19 @@ function createScoringGate(config) {
|
|
|
11195
11320
|
// libs/core/src/enclave.ts
|
|
11196
11321
|
init_global_function_gate();
|
|
11197
11322
|
init_stack_trace();
|
|
11323
|
+
|
|
11324
|
+
// libs/core/src/node-vm.ts
|
|
11325
|
+
var vm2 = __toESM(require("vm"));
|
|
11326
|
+
function assertNodeVmAvailable() {
|
|
11327
|
+
if (typeof vm2.createContext === "function" && typeof vm2.Script === "function") {
|
|
11328
|
+
return;
|
|
11329
|
+
}
|
|
11330
|
+
throw new Error(
|
|
11331
|
+
"@enclave-vm/core needs node:vm, which this runtime does not provide. In a browser, use @enclave-vm/browser; elsewhere, pass a sandboxAdapter (for example new InterpreterAdapter())."
|
|
11332
|
+
);
|
|
11333
|
+
}
|
|
11334
|
+
|
|
11335
|
+
// libs/core/src/enclave.ts
|
|
11198
11336
|
var DEFAULT_SECURITY_LEVEL = "STANDARD";
|
|
11199
11337
|
var DEFAULT_TOOL_BRIDGE_MAX_PAYLOAD_BYTES = 5 * 1024 * 1024;
|
|
11200
11338
|
function getConfigFromSecurityLevel(securityLevel, options) {
|
|
@@ -11250,6 +11388,7 @@ var Enclave = class {
|
|
|
11250
11388
|
doubleVmConfig;
|
|
11251
11389
|
customGlobalNames;
|
|
11252
11390
|
toolNamespaces;
|
|
11391
|
+
sandboxAdapter;
|
|
11253
11392
|
adapter;
|
|
11254
11393
|
constructor(options = {}) {
|
|
11255
11394
|
this.securityLevel = options.securityLevel ?? DEFAULT_SECURITY_LEVEL;
|
|
@@ -11341,6 +11480,10 @@ var Enclave = class {
|
|
|
11341
11480
|
this.scoringGate = new ScoringGate(options.scoringGate);
|
|
11342
11481
|
}
|
|
11343
11482
|
this.doubleVmConfig = this.buildDoubleVmConfig(options.doubleVm);
|
|
11483
|
+
if (options.sandboxAdapter !== void 0 && !isSandboxAdapter(options.sandboxAdapter)) {
|
|
11484
|
+
throw new TypeError("sandboxAdapter must have execute(code, context) and dispose() methods");
|
|
11485
|
+
}
|
|
11486
|
+
this.sandboxAdapter = options.sandboxAdapter;
|
|
11344
11487
|
}
|
|
11345
11488
|
/**
|
|
11346
11489
|
* Build double VM configuration from user options
|
|
@@ -11601,7 +11744,8 @@ ${errorMessages}`,
|
|
|
11601
11744
|
/**
|
|
11602
11745
|
* Get or create the sandbox adapter
|
|
11603
11746
|
*
|
|
11604
|
-
*
|
|
11747
|
+
* A host-supplied `sandboxAdapter` is used as is. Otherwise, when double VM is enabled
|
|
11748
|
+
* (default), the base adapter is wrapped
|
|
11605
11749
|
* with a double VM layer that provides:
|
|
11606
11750
|
* - Nested VM isolation (Parent VM + Inner VM)
|
|
11607
11751
|
* - Enhanced tool call validation
|
|
@@ -11609,9 +11753,15 @@ ${errorMessages}`,
|
|
|
11609
11753
|
* - Defense-in-depth against VM escape attacks
|
|
11610
11754
|
*/
|
|
11611
11755
|
async getAdapter() {
|
|
11756
|
+
if (this.sandboxAdapter) {
|
|
11757
|
+
return this.sandboxAdapter;
|
|
11758
|
+
}
|
|
11612
11759
|
if (this.adapter) {
|
|
11613
11760
|
return this.adapter;
|
|
11614
11761
|
}
|
|
11762
|
+
if (this.doubleVmConfig.enabled || this.config.adapter === "vm") {
|
|
11763
|
+
assertNodeVmAvailable();
|
|
11764
|
+
}
|
|
11615
11765
|
if (this.doubleVmConfig.enabled) {
|
|
11616
11766
|
const { wrapWithDoubleVm: wrapWithDoubleVm3 } = await Promise.resolve().then(() => (init_double_vm(), double_vm_exports));
|
|
11617
11767
|
this.adapter = wrapWithDoubleVm3(void 0, this.doubleVmConfig, this.securityLevel);
|
|
@@ -11754,6 +11904,10 @@ ${errorMessages}`,
|
|
|
11754
11904
|
return uniqueErrors.join("\n");
|
|
11755
11905
|
}
|
|
11756
11906
|
};
|
|
11907
|
+
function isSandboxAdapter(value) {
|
|
11908
|
+
const candidate = value;
|
|
11909
|
+
return typeof candidate === "object" && candidate !== null && typeof candidate.execute === "function" && typeof candidate.dispose === "function";
|
|
11910
|
+
}
|
|
11757
11911
|
async function runAgentScript(code, options = {}) {
|
|
11758
11912
|
const enclave = new Enclave(options);
|
|
11759
11913
|
try {
|
package/node-vm.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js `vm` availability check
|
|
3
|
+
*
|
|
4
|
+
* The built-in adapters need `node:vm`. Bundled for a browser or an edge runtime, `vm` is often
|
|
5
|
+
* mapped to an empty module, and the first call into it fails with an opaque
|
|
6
|
+
* `TypeError: (void 0) is not a function`; this check names the problem and the way out.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Throw a descriptive error when this runtime does not provide `node:vm`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertNodeVmAvailable(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enclave-vm/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.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,8 @@
|
|
|
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.17.0",
|
|
48
|
+
"@enclave-vm/types": "2.17.0",
|
|
49
49
|
"@types/estree": "1.0.8",
|
|
50
50
|
"acorn": "8.15.0",
|
|
51
51
|
"acorn-walk": "8.3.4",
|
package/secure-proxy.d.ts
CHANGED
|
@@ -185,6 +185,13 @@ export declare function createSecureStandardLibrary(options?: SecureProxyOptions
|
|
|
185
185
|
* @returns true if the object is wrapped in a secure proxy
|
|
186
186
|
*/
|
|
187
187
|
export declare function isSecureProxy(obj: unknown): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* The object a secure proxy wraps, or `value` itself when it is not one.
|
|
190
|
+
*
|
|
191
|
+
* For host code that must read a sandbox value's internal slots, which a proxy does not carry
|
|
192
|
+
* (a proxied Date fails `Date.prototype.getTime`). Never hand the result back to the sandbox.
|
|
193
|
+
*/
|
|
194
|
+
export declare function unwrapSecureProxy<T>(value: T): T;
|
|
188
195
|
/**
|
|
189
196
|
* Clear the proxy cache
|
|
190
197
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enclave-vm/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.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,8 @@
|
|
|
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.17.0",
|
|
50
|
+
"@enclave-vm/types": "2.17.0",
|
|
51
51
|
"@types/estree": "1.0.8",
|
|
52
52
|
"acorn": "8.15.0",
|
|
53
53
|
"acorn-walk": "8.3.4",
|