@enclave-vm/core 2.9.2 → 2.10.1
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/worker-pool-adapter.d.ts +1 -0
- package/enclave.d.ts +1 -0
- package/esm/index.mjs +289 -90
- package/index.js +290 -91
- package/package.json +5 -5
- package/src/adapters/worker-pool/package.json +61 -0
- package/src/adapters/worker-pool/worker-script.js +759 -0
package/esm/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
// libs/
|
|
11
|
+
// libs/core/src/sidecar/reference-config.ts
|
|
12
12
|
function isReferenceId(value) {
|
|
13
13
|
return typeof value === "string" && REF_ID_PATTERN.test(value);
|
|
14
14
|
}
|
|
@@ -20,7 +20,7 @@ function getReferenceConfig(securityLevel, overrides) {
|
|
|
20
20
|
}
|
|
21
21
|
var REFERENCE_CONFIGS, REF_ID_PREFIX, REF_ID_SUFFIX, REF_ID_PATTERN;
|
|
22
22
|
var init_reference_config = __esm({
|
|
23
|
-
"libs/
|
|
23
|
+
"libs/core/src/sidecar/reference-config.ts"() {
|
|
24
24
|
"use strict";
|
|
25
25
|
REFERENCE_CONFIGS = {
|
|
26
26
|
/**
|
|
@@ -122,14 +122,14 @@ var init_reference_config = __esm({
|
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
-
// libs/
|
|
125
|
+
// libs/core/src/sidecar/reference-resolver.ts
|
|
126
126
|
function isCompositeHandle(value) {
|
|
127
127
|
const obj = value;
|
|
128
128
|
return typeof value === "object" && value !== null && obj["__type"] === "composite" && Array.isArray(obj["__parts"]);
|
|
129
129
|
}
|
|
130
130
|
var ResolutionLimitError, ReferenceResolver;
|
|
131
131
|
var init_reference_resolver = __esm({
|
|
132
|
-
"libs/
|
|
132
|
+
"libs/core/src/sidecar/reference-resolver.ts"() {
|
|
133
133
|
"use strict";
|
|
134
134
|
init_reference_config();
|
|
135
135
|
ResolutionLimitError = class _ResolutionLimitError extends Error {
|
|
@@ -337,7 +337,7 @@ var init_reference_resolver = __esm({
|
|
|
337
337
|
}
|
|
338
338
|
});
|
|
339
339
|
|
|
340
|
-
// libs/
|
|
340
|
+
// libs/core/src/value-sanitizer.ts
|
|
341
341
|
function sanitizeValue(value, options = {}, depth = 0, context = { propCount: { count: 0 }, visited: /* @__PURE__ */ new WeakSet() }) {
|
|
342
342
|
const maxDepth = options.maxDepth ?? 20;
|
|
343
343
|
const maxProperties = options.maxProperties ?? 1e4;
|
|
@@ -573,13 +573,13 @@ function checkSerializedSize(value, maxBytes) {
|
|
|
573
573
|
}
|
|
574
574
|
var DANGEROUS_KEYS;
|
|
575
575
|
var init_value_sanitizer = __esm({
|
|
576
|
-
"libs/
|
|
576
|
+
"libs/core/src/value-sanitizer.ts"() {
|
|
577
577
|
"use strict";
|
|
578
578
|
DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor"]);
|
|
579
579
|
}
|
|
580
580
|
});
|
|
581
581
|
|
|
582
|
-
// libs/
|
|
582
|
+
// libs/core/src/safe-error.ts
|
|
583
583
|
function createSafeError(message, name = "Error") {
|
|
584
584
|
const error = new Error(message);
|
|
585
585
|
error.name = name;
|
|
@@ -631,12 +631,12 @@ function createSafeTypeError(message) {
|
|
|
631
631
|
return createSafeError(message, "TypeError");
|
|
632
632
|
}
|
|
633
633
|
var init_safe_error = __esm({
|
|
634
|
-
"libs/
|
|
634
|
+
"libs/core/src/safe-error.ts"() {
|
|
635
635
|
"use strict";
|
|
636
636
|
}
|
|
637
637
|
});
|
|
638
638
|
|
|
639
|
-
// libs/
|
|
639
|
+
// libs/core/src/secure-proxy.ts
|
|
640
640
|
function getBlockedPropertiesForLevel(level) {
|
|
641
641
|
const blocked = /* @__PURE__ */ new Set();
|
|
642
642
|
if (level !== "PERMISSIVE") {
|
|
@@ -958,7 +958,7 @@ function isSecureProxy(obj) {
|
|
|
958
958
|
}
|
|
959
959
|
var BLOCKED_PROPERTY_CATEGORIES, BLOCKED_PROPERTIES, DEFAULT_SECURE_PROXY_CONFIG, FUNCTION_BLOCKED_PROPERTIES, proxyCache, proxySet, NON_PROXYABLE_TYPES, INTERNAL_SLOT_TYPES;
|
|
960
960
|
var init_secure_proxy = __esm({
|
|
961
|
-
"libs/
|
|
961
|
+
"libs/core/src/secure-proxy.ts"() {
|
|
962
962
|
"use strict";
|
|
963
963
|
init_safe_error();
|
|
964
964
|
BLOCKED_PROPERTY_CATEGORIES = {
|
|
@@ -1074,7 +1074,7 @@ var init_secure_proxy = __esm({
|
|
|
1074
1074
|
}
|
|
1075
1075
|
});
|
|
1076
1076
|
|
|
1077
|
-
// libs/
|
|
1077
|
+
// libs/core/src/memory-tracker.ts
|
|
1078
1078
|
function estimateStringSize2(str) {
|
|
1079
1079
|
return str.length * 2 + 40;
|
|
1080
1080
|
}
|
|
@@ -1086,7 +1086,7 @@ function estimateObjectSize(propertyCount) {
|
|
|
1086
1086
|
}
|
|
1087
1087
|
var MemoryLimitError, MemoryTracker;
|
|
1088
1088
|
var init_memory_tracker = __esm({
|
|
1089
|
-
"libs/
|
|
1089
|
+
"libs/core/src/memory-tracker.ts"() {
|
|
1090
1090
|
"use strict";
|
|
1091
1091
|
MemoryLimitError = class _MemoryLimitError extends Error {
|
|
1092
1092
|
constructor(message, usedBytes, limitBytes) {
|
|
@@ -1228,7 +1228,7 @@ var init_memory_tracker = __esm({
|
|
|
1228
1228
|
}
|
|
1229
1229
|
});
|
|
1230
1230
|
|
|
1231
|
-
// libs/
|
|
1231
|
+
// libs/core/src/tool-bridge.ts
|
|
1232
1232
|
function utf8ByteLength(value) {
|
|
1233
1233
|
return Buffer.byteLength(value, "utf8");
|
|
1234
1234
|
}
|
|
@@ -1565,7 +1565,7 @@ function createHostToolBridge(executionContext, options) {
|
|
|
1565
1565
|
}
|
|
1566
1566
|
var TOOL_BRIDGE_PROTOCOL_VERSION;
|
|
1567
1567
|
var init_tool_bridge = __esm({
|
|
1568
|
-
"libs/
|
|
1568
|
+
"libs/core/src/tool-bridge.ts"() {
|
|
1569
1569
|
"use strict";
|
|
1570
1570
|
init_value_sanitizer();
|
|
1571
1571
|
init_reference_resolver();
|
|
@@ -1573,7 +1573,7 @@ var init_tool_bridge = __esm({
|
|
|
1573
1573
|
}
|
|
1574
1574
|
});
|
|
1575
1575
|
|
|
1576
|
-
// libs/
|
|
1576
|
+
// libs/core/src/double-vm/parent-vm-bootstrap.ts
|
|
1577
1577
|
function generateSanitizeContextCode(securityLevel) {
|
|
1578
1578
|
const globalsToRemove = NODEJS_24_DANGEROUS_GLOBALS[securityLevel];
|
|
1579
1579
|
return globalsToRemove.map(
|
|
@@ -2913,8 +2913,110 @@ ${stackTraceHardeningCode}
|
|
|
2913
2913
|
// Remove dangerous globals from inner VM (AFTER memory patching)
|
|
2914
2914
|
${sanitizeContextCode}
|
|
2915
2915
|
|
|
2916
|
-
//
|
|
2917
|
-
//
|
|
2916
|
+
// ============================================================
|
|
2917
|
+
// PHASE 2 HARDENING: CVE-2023-29017 Stack Overflow Escape Defense
|
|
2918
|
+
// ============================================================
|
|
2919
|
+
//
|
|
2920
|
+
// CRITICAL: Hardening MUST run BEFORE prototypes are frozen!
|
|
2921
|
+
// Otherwise Object.defineProperty calls will silently fail on frozen prototypes.
|
|
2922
|
+
//
|
|
2923
|
+
// Defense-in-depth against prototype chain escape via stack overflow errors:
|
|
2924
|
+
// 1. __proto__ shadowing to block prototype chain traversal
|
|
2925
|
+
// 2. Legacy method blocking (__lookupGetter__, etc.)
|
|
2926
|
+
// 3. Error constructor wrapping to secure V8-generated errors
|
|
2927
|
+
// 4. Then freeze all prototypes to lock in hardening
|
|
2928
|
+
|
|
2929
|
+
// HARDENING 1: Shadow __proto__ on PARENT VM error prototypes with null
|
|
2930
|
+
// This prevents e["__proto__"]["__proto__"] traversal attacks by making
|
|
2931
|
+
// __proto__ return null instead of the actual prototype chain.
|
|
2932
|
+
// MUST run before freeze!
|
|
2933
|
+
(function() {
|
|
2934
|
+
var errorProtos = [
|
|
2935
|
+
Error.prototype,
|
|
2936
|
+
TypeError.prototype,
|
|
2937
|
+
RangeError.prototype,
|
|
2938
|
+
SyntaxError.prototype,
|
|
2939
|
+
ReferenceError.prototype,
|
|
2940
|
+
URIError.prototype,
|
|
2941
|
+
EvalError.prototype
|
|
2942
|
+
];
|
|
2943
|
+
for (var i = 0; i < errorProtos.length; i++) {
|
|
2944
|
+
// Shadow __proto__ with a null-returning getter
|
|
2945
|
+
// This blocks: error["__proto__"]["__proto__"]["__proto__"] attacks
|
|
2946
|
+
Object.defineProperty(errorProtos[i], '__proto__', {
|
|
2947
|
+
get: function() { return null; },
|
|
2948
|
+
set: function() { /* silently ignore */ },
|
|
2949
|
+
configurable: false,
|
|
2950
|
+
enumerable: false
|
|
2951
|
+
});
|
|
2952
|
+
}
|
|
2953
|
+
})();
|
|
2954
|
+
|
|
2955
|
+
// HARDENING 2: Shadow __proto__ in INNER VM error prototypes
|
|
2956
|
+
// MUST run before freeze!
|
|
2957
|
+
(function() {
|
|
2958
|
+
var shadowProtoCode =
|
|
2959
|
+
'(function() {' +
|
|
2960
|
+
' var errorProtos = [' +
|
|
2961
|
+
' Error.prototype,' +
|
|
2962
|
+
' TypeError.prototype,' +
|
|
2963
|
+
' RangeError.prototype,' +
|
|
2964
|
+
' SyntaxError.prototype,' +
|
|
2965
|
+
' ReferenceError.prototype,' +
|
|
2966
|
+
' URIError.prototype,' +
|
|
2967
|
+
' EvalError.prototype' +
|
|
2968
|
+
' ];' +
|
|
2969
|
+
' for (var i = 0; i < errorProtos.length; i++) {' +
|
|
2970
|
+
' Object.defineProperty(errorProtos[i], "__proto__", {' +
|
|
2971
|
+
' get: function() { return null; },' +
|
|
2972
|
+
' set: function() {},' +
|
|
2973
|
+
' configurable: false,' +
|
|
2974
|
+
' enumerable: false' +
|
|
2975
|
+
' });' +
|
|
2976
|
+
' }' +
|
|
2977
|
+
'})();';
|
|
2978
|
+
var shadowScript = new vm.Script(shadowProtoCode);
|
|
2979
|
+
shadowScript.runInContext(innerContext);
|
|
2980
|
+
})();
|
|
2981
|
+
|
|
2982
|
+
// HARDENING 3: Block legacy prototype manipulation methods in PARENT VM
|
|
2983
|
+
// These deprecated methods (__lookupGetter__, __lookupSetter__, __defineGetter__, __defineSetter__)
|
|
2984
|
+
// can be used to bypass frozen prototype protections.
|
|
2985
|
+
// MUST run before freeze!
|
|
2986
|
+
(function() {
|
|
2987
|
+
var legacyMethods = ['__lookupGetter__', '__lookupSetter__', '__defineGetter__', '__defineSetter__'];
|
|
2988
|
+
for (var i = 0; i < legacyMethods.length; i++) {
|
|
2989
|
+
Object.defineProperty(Object.prototype, legacyMethods[i], {
|
|
2990
|
+
value: function() { return undefined; },
|
|
2991
|
+
writable: false,
|
|
2992
|
+
configurable: false,
|
|
2993
|
+
enumerable: false
|
|
2994
|
+
});
|
|
2995
|
+
}
|
|
2996
|
+
})();
|
|
2997
|
+
|
|
2998
|
+
// HARDENING 4: Block legacy prototype methods in INNER VM
|
|
2999
|
+
// MUST run before freeze!
|
|
3000
|
+
(function() {
|
|
3001
|
+
var blockLegacyCode =
|
|
3002
|
+
'(function() {' +
|
|
3003
|
+
' var methods = ["__lookupGetter__", "__lookupSetter__", "__defineGetter__", "__defineSetter__"];' +
|
|
3004
|
+
' for (var i = 0; i < methods.length; i++) {' +
|
|
3005
|
+
' Object.defineProperty(Object.prototype, methods[i], {' +
|
|
3006
|
+
' value: function() { return undefined; },' +
|
|
3007
|
+
' writable: false,' +
|
|
3008
|
+
' configurable: false,' +
|
|
3009
|
+
' enumerable: false' +
|
|
3010
|
+
' });' +
|
|
3011
|
+
' }' +
|
|
3012
|
+
'})();';
|
|
3013
|
+
var blockScript = new vm.Script(blockLegacyCode);
|
|
3014
|
+
blockScript.runInContext(innerContext);
|
|
3015
|
+
})();
|
|
3016
|
+
|
|
3017
|
+
// ============================================================
|
|
3018
|
+
// PROTOTYPE FREEZING: Lock in hardening by freezing all prototypes
|
|
3019
|
+
// ============================================================
|
|
2918
3020
|
//
|
|
2919
3021
|
// We freeze prototypes in TWO places:
|
|
2920
3022
|
// 1. PARENT VM prototypes - because SafeObject.prototype = Object.prototype uses parent's prototype
|
|
@@ -2936,6 +3038,8 @@ ${stackTraceHardeningCode}
|
|
|
2936
3038
|
Object.freeze(RangeError.prototype);
|
|
2937
3039
|
Object.freeze(SyntaxError.prototype);
|
|
2938
3040
|
Object.freeze(ReferenceError.prototype);
|
|
3041
|
+
Object.freeze(URIError.prototype);
|
|
3042
|
+
Object.freeze(EvalError.prototype);
|
|
2939
3043
|
Object.freeze(Promise.prototype);
|
|
2940
3044
|
|
|
2941
3045
|
// Freeze INNER VM prototypes (used by literals like '', [], etc.)
|
|
@@ -2953,11 +3057,64 @@ ${stackTraceHardeningCode}
|
|
|
2953
3057
|
'Object.freeze(RangeError.prototype);' +
|
|
2954
3058
|
'Object.freeze(SyntaxError.prototype);' +
|
|
2955
3059
|
'Object.freeze(ReferenceError.prototype);' +
|
|
3060
|
+
'Object.freeze(URIError.prototype);' +
|
|
3061
|
+
'Object.freeze(EvalError.prototype);' +
|
|
2956
3062
|
'Object.freeze(Promise.prototype);';
|
|
2957
3063
|
var freezeScript = new vm.Script(freezeCode);
|
|
2958
3064
|
freezeScript.runInContext(innerContext);
|
|
2959
3065
|
})();
|
|
2960
3066
|
|
|
3067
|
+
// HARDENING 5: Wrap error constructors to freeze instances
|
|
3068
|
+
// V8-generated errors (like stack overflow RangeError) are created internally,
|
|
3069
|
+
// not via the constructor. But wrapping provides defense-in-depth for any
|
|
3070
|
+
// errors that ARE created via constructors.
|
|
3071
|
+
// NOTE: This can run after freeze because it replaces global constructors, not prototype properties
|
|
3072
|
+
(function() {
|
|
3073
|
+
var wrapErrorCode =
|
|
3074
|
+
'(function() {' +
|
|
3075
|
+
' var origError = Error;' +
|
|
3076
|
+
' var origTypeError = TypeError;' +
|
|
3077
|
+
' var origRangeError = RangeError;' +
|
|
3078
|
+
' var origSyntaxError = SyntaxError;' +
|
|
3079
|
+
' var origReferenceError = ReferenceError;' +
|
|
3080
|
+
' var origEvalError = EvalError;' +
|
|
3081
|
+
' var origURIError = URIError;' +
|
|
3082
|
+
' function wrapErrorCtor(OrigCtor, name) {' +
|
|
3083
|
+
' var WrappedCtor = function(msg) {' +
|
|
3084
|
+
' var err;' +
|
|
3085
|
+
' if (new.target) {' +
|
|
3086
|
+
' err = new OrigCtor(msg);' +
|
|
3087
|
+
' } else {' +
|
|
3088
|
+
' err = OrigCtor(msg);' +
|
|
3089
|
+
' }' +
|
|
3090
|
+
' try { Object.freeze(err); } catch (e) {}' +
|
|
3091
|
+
' return err;' +
|
|
3092
|
+
' };' +
|
|
3093
|
+
' WrappedCtor.prototype = OrigCtor.prototype;' +
|
|
3094
|
+
' try { Object.setPrototypeOf(WrappedCtor, OrigCtor); } catch (e) {}' +
|
|
3095
|
+
' try { Object.freeze(WrappedCtor); } catch (e) {}' +
|
|
3096
|
+
' return WrappedCtor;' +
|
|
3097
|
+
' }' +
|
|
3098
|
+
' try { Error = wrapErrorCtor(origError, "Error"); } catch (e) {}' +
|
|
3099
|
+
' try { TypeError = wrapErrorCtor(origTypeError, "TypeError"); } catch (e) {}' +
|
|
3100
|
+
' try { RangeError = wrapErrorCtor(origRangeError, "RangeError"); } catch (e) {}' +
|
|
3101
|
+
' try { SyntaxError = wrapErrorCtor(origSyntaxError, "SyntaxError"); } catch (e) {}' +
|
|
3102
|
+
' try { ReferenceError = wrapErrorCtor(origReferenceError, "ReferenceError"); } catch (e) {}' +
|
|
3103
|
+
' try { EvalError = wrapErrorCtor(origEvalError, "EvalError"); } catch (e) {}' +
|
|
3104
|
+
' try { URIError = wrapErrorCtor(origURIError, "URIError"); } catch (e) {}' +
|
|
3105
|
+
'})();';
|
|
3106
|
+
try {
|
|
3107
|
+
var wrapScript = new vm.Script(wrapErrorCode);
|
|
3108
|
+
wrapScript.runInContext(innerContext);
|
|
3109
|
+
} catch (e) { /* ignore */ }
|
|
3110
|
+
})();
|
|
3111
|
+
|
|
3112
|
+
// NOTE: HARDENING 6 and 7 (Object.getPrototypeOf / Reflect.getPrototypeOf wrappers)
|
|
3113
|
+
// were removed as they break legitimate internal functionality like __safe_template.
|
|
3114
|
+
// The existing defenses (prototype freezing, __proto__ shadowing, error constructor
|
|
3115
|
+
// wrapping, codeGeneration.strings=false) provide sufficient protection against
|
|
3116
|
+
// the CVE-2023-29017 attack pattern.
|
|
3117
|
+
|
|
2961
3118
|
// Inject safe runtime functions (non-writable, non-configurable)
|
|
2962
3119
|
// Wrap with secure proxy to block dangerous property access
|
|
2963
3120
|
var safeRuntime = {
|
|
@@ -3142,6 +3299,47 @@ ${stackTraceHardeningCode}
|
|
|
3142
3299
|
// Execute User Code
|
|
3143
3300
|
// ============================================================
|
|
3144
3301
|
|
|
3302
|
+
// HARDENING 4: Runtime prototype verification before user code execution
|
|
3303
|
+
// Verifies that critical prototypes are still frozen. If any have been
|
|
3304
|
+
// unfrozen (which shouldn't be possible but defense-in-depth), abort.
|
|
3305
|
+
(function() {
|
|
3306
|
+
var criticalPrototypes = [
|
|
3307
|
+
{ name: 'Object.prototype', proto: Object.prototype },
|
|
3308
|
+
{ name: 'Array.prototype', proto: Array.prototype },
|
|
3309
|
+
{ name: 'Function.prototype', proto: Function.prototype },
|
|
3310
|
+
{ name: 'Error.prototype', proto: Error.prototype },
|
|
3311
|
+
{ name: 'RangeError.prototype', proto: RangeError.prototype }
|
|
3312
|
+
];
|
|
3313
|
+
for (var i = 0; i < criticalPrototypes.length; i++) {
|
|
3314
|
+
var item = criticalPrototypes[i];
|
|
3315
|
+
if (!Object.isFrozen(item.proto)) {
|
|
3316
|
+
throw new Error('SECURITY VIOLATION: ' + item.name + ' is not frozen. Aborting execution.');
|
|
3317
|
+
}
|
|
3318
|
+
}
|
|
3319
|
+
})();
|
|
3320
|
+
|
|
3321
|
+
// HARDENING 5: Runtime verification in INNER VM
|
|
3322
|
+
(function() {
|
|
3323
|
+
var verifyCode =
|
|
3324
|
+
'(function() {' +
|
|
3325
|
+
' var protos = [Object.prototype, Array.prototype, Error.prototype, RangeError.prototype];' +
|
|
3326
|
+
' for (var i = 0; i < protos.length; i++) {' +
|
|
3327
|
+
' if (!Object.isFrozen(protos[i])) {' +
|
|
3328
|
+
' throw new Error("SECURITY VIOLATION: Inner VM prototype not frozen");' +
|
|
3329
|
+
' }' +
|
|
3330
|
+
' }' +
|
|
3331
|
+
'})();';
|
|
3332
|
+
try {
|
|
3333
|
+
var verifyScript = new vm.Script(verifyCode);
|
|
3334
|
+
verifyScript.runInContext(innerContext);
|
|
3335
|
+
} catch (e) {
|
|
3336
|
+
if (e.message && e.message.indexOf('SECURITY VIOLATION') >= 0) {
|
|
3337
|
+
throw e;
|
|
3338
|
+
}
|
|
3339
|
+
/* ignore other errors */
|
|
3340
|
+
}
|
|
3341
|
+
})();
|
|
3342
|
+
|
|
3145
3343
|
var userCode = ${JSON.stringify(userCode)};
|
|
3146
3344
|
// IMPORTANT: For stack overflow errors (RangeError: Maximum call stack size exceeded),
|
|
3147
3345
|
// Node/V8 may ignore Error.prepareStackTrace when it was installed by a different Script
|
|
@@ -3176,7 +3374,7 @@ ${stackTraceHardeningCode}
|
|
|
3176
3374
|
}
|
|
3177
3375
|
var NODEJS_24_DANGEROUS_GLOBALS;
|
|
3178
3376
|
var init_parent_vm_bootstrap = __esm({
|
|
3179
|
-
"libs/
|
|
3377
|
+
"libs/core/src/double-vm/parent-vm-bootstrap.ts"() {
|
|
3180
3378
|
"use strict";
|
|
3181
3379
|
NODEJS_24_DANGEROUS_GLOBALS = {
|
|
3182
3380
|
STRICT: [
|
|
@@ -3261,7 +3459,7 @@ var init_parent_vm_bootstrap = __esm({
|
|
|
3261
3459
|
}
|
|
3262
3460
|
});
|
|
3263
3461
|
|
|
3264
|
-
// libs/
|
|
3462
|
+
// libs/core/src/double-vm/suspicious-patterns.ts
|
|
3265
3463
|
function serializePattern(pattern) {
|
|
3266
3464
|
if (typeof pattern.detect !== "function") {
|
|
3267
3465
|
throw new Error(`Pattern "${pattern.id}": detect must be a function`);
|
|
@@ -3305,7 +3503,7 @@ function serializePatterns(patterns) {
|
|
|
3305
3503
|
}
|
|
3306
3504
|
var EXFIL_LIST_SEND, RAPID_ENUMERATION, CREDENTIAL_EXFIL, BULK_OPERATION, DELETE_AFTER_ACCESS, DEFAULT_SUSPICIOUS_PATTERNS;
|
|
3307
3505
|
var init_suspicious_patterns = __esm({
|
|
3308
|
-
"libs/
|
|
3506
|
+
"libs/core/src/double-vm/suspicious-patterns.ts"() {
|
|
3309
3507
|
"use strict";
|
|
3310
3508
|
EXFIL_LIST_SEND = {
|
|
3311
3509
|
id: "EXFIL_LIST_SEND",
|
|
@@ -3387,7 +3585,7 @@ var init_suspicious_patterns = __esm({
|
|
|
3387
3585
|
}
|
|
3388
3586
|
});
|
|
3389
3587
|
|
|
3390
|
-
// libs/
|
|
3588
|
+
// libs/core/src/double-vm/double-vm-wrapper.ts
|
|
3391
3589
|
import * as vm2 from "vm";
|
|
3392
3590
|
function sanitizeStackTrace(stack, sanitize = true) {
|
|
3393
3591
|
if (!stack || !sanitize) return stack;
|
|
@@ -3420,7 +3618,7 @@ function sanitizeStackTrace(stack, sanitize = true) {
|
|
|
3420
3618
|
}
|
|
3421
3619
|
var SENSITIVE_STACK_PATTERNS, DoubleVmWrapper;
|
|
3422
3620
|
var init_double_vm_wrapper = __esm({
|
|
3423
|
-
"libs/
|
|
3621
|
+
"libs/core/src/double-vm/double-vm-wrapper.ts"() {
|
|
3424
3622
|
"use strict";
|
|
3425
3623
|
init_value_sanitizer();
|
|
3426
3624
|
init_secure_proxy();
|
|
@@ -3814,7 +4012,7 @@ var init_double_vm_wrapper = __esm({
|
|
|
3814
4012
|
}
|
|
3815
4013
|
});
|
|
3816
4014
|
|
|
3817
|
-
// libs/
|
|
4015
|
+
// libs/core/src/double-vm/wrap-adapter.ts
|
|
3818
4016
|
function wrapWithDoubleVm(baseAdapter, config, securityLevel) {
|
|
3819
4017
|
if (!config.enabled) {
|
|
3820
4018
|
if (!baseAdapter) {
|
|
@@ -3833,13 +4031,13 @@ function isDoubleVmEnabled(config) {
|
|
|
3833
4031
|
return config?.enabled !== false;
|
|
3834
4032
|
}
|
|
3835
4033
|
var init_wrap_adapter = __esm({
|
|
3836
|
-
"libs/
|
|
4034
|
+
"libs/core/src/double-vm/wrap-adapter.ts"() {
|
|
3837
4035
|
"use strict";
|
|
3838
4036
|
init_double_vm_wrapper();
|
|
3839
4037
|
}
|
|
3840
4038
|
});
|
|
3841
4039
|
|
|
3842
|
-
// libs/
|
|
4040
|
+
// libs/core/src/double-vm/index.ts
|
|
3843
4041
|
var double_vm_exports = {};
|
|
3844
4042
|
__export(double_vm_exports, {
|
|
3845
4043
|
DEFAULT_SUSPICIOUS_PATTERNS: () => DEFAULT_SUSPICIOUS_PATTERNS,
|
|
@@ -3851,7 +4049,7 @@ __export(double_vm_exports, {
|
|
|
3851
4049
|
wrapWithDoubleVm: () => wrapWithDoubleVm
|
|
3852
4050
|
});
|
|
3853
4051
|
var init_double_vm = __esm({
|
|
3854
|
-
"libs/
|
|
4052
|
+
"libs/core/src/double-vm/index.ts"() {
|
|
3855
4053
|
"use strict";
|
|
3856
4054
|
init_double_vm_wrapper();
|
|
3857
4055
|
init_wrap_adapter();
|
|
@@ -3860,7 +4058,7 @@ var init_double_vm = __esm({
|
|
|
3860
4058
|
}
|
|
3861
4059
|
});
|
|
3862
4060
|
|
|
3863
|
-
// libs/
|
|
4061
|
+
// libs/core/src/memory-proxy.ts
|
|
3864
4062
|
function createTrackedString(tracker) {
|
|
3865
4063
|
return new Proxy(String, {
|
|
3866
4064
|
apply(target, thisArg, args) {
|
|
@@ -3953,13 +4151,13 @@ function createTrackedArray(tracker) {
|
|
|
3953
4151
|
return TrackedArray;
|
|
3954
4152
|
}
|
|
3955
4153
|
var init_memory_proxy = __esm({
|
|
3956
|
-
"libs/
|
|
4154
|
+
"libs/core/src/memory-proxy.ts"() {
|
|
3957
4155
|
"use strict";
|
|
3958
4156
|
init_memory_tracker();
|
|
3959
4157
|
}
|
|
3960
4158
|
});
|
|
3961
4159
|
|
|
3962
|
-
// libs/
|
|
4160
|
+
// libs/core/src/safe-runtime.ts
|
|
3963
4161
|
function createSafeRuntime(context, options) {
|
|
3964
4162
|
const { config, stats } = context;
|
|
3965
4163
|
const sidecar = options?.sidecar;
|
|
@@ -4442,7 +4640,7 @@ function serializeSafeRuntime() {
|
|
|
4442
4640
|
`.trim();
|
|
4443
4641
|
}
|
|
4444
4642
|
var init_safe_runtime = __esm({
|
|
4445
|
-
"libs/
|
|
4643
|
+
"libs/core/src/safe-runtime.ts"() {
|
|
4446
4644
|
"use strict";
|
|
4447
4645
|
init_value_sanitizer();
|
|
4448
4646
|
init_safe_error();
|
|
@@ -4453,7 +4651,7 @@ var init_safe_runtime = __esm({
|
|
|
4453
4651
|
}
|
|
4454
4652
|
});
|
|
4455
4653
|
|
|
4456
|
-
// libs/
|
|
4654
|
+
// libs/core/src/adapters/vm-adapter.ts
|
|
4457
4655
|
var vm_adapter_exports = {};
|
|
4458
4656
|
__export(vm_adapter_exports, {
|
|
4459
4657
|
VmAdapter: () => VmAdapter
|
|
@@ -4654,7 +4852,7 @@ function sanitizeVmContext(context, securityLevel) {
|
|
|
4654
4852
|
}
|
|
4655
4853
|
var SENSITIVE_STACK_PATTERNS2, STACK_TRACE_HARDENING_CODE, STACK_TRACE_HARDENING_SCRIPT, CODE_GENERATION_VIOLATION_DETECTOR_CODE, CODE_GENERATION_VIOLATION_DETECTOR_SCRIPT, PROTECTED_PREFIXES, DANGEROUS_OBJECT_STATIC_METHODS, NODEJS_24_DANGEROUS_GLOBALS2, VmAdapter;
|
|
4656
4854
|
var init_vm_adapter = __esm({
|
|
4657
|
-
"libs/
|
|
4855
|
+
"libs/core/src/adapters/vm-adapter.ts"() {
|
|
4658
4856
|
"use strict";
|
|
4659
4857
|
init_safe_runtime();
|
|
4660
4858
|
init_secure_proxy();
|
|
@@ -5351,12 +5549,7 @@ var init_vm_adapter = __esm({
|
|
|
5351
5549
|
}
|
|
5352
5550
|
const _protectedSandbox = createProtectedSandbox(baseSandbox);
|
|
5353
5551
|
this.context = baseSandbox;
|
|
5354
|
-
const wrappedCode =
|
|
5355
|
-
(async () => {
|
|
5356
|
-
${code}
|
|
5357
|
-
return typeof __ag_main === 'function' ? await __ag_main() : undefined;
|
|
5358
|
-
})();
|
|
5359
|
-
`;
|
|
5552
|
+
const wrappedCode = "(async () => {\n" + code + '\nreturn typeof __ag_main === "function" ? await __ag_main() : undefined;\n})();';
|
|
5360
5553
|
const script = new vm3.Script(wrappedCode, {
|
|
5361
5554
|
filename: "agentscript.js"
|
|
5362
5555
|
});
|
|
@@ -5459,7 +5652,7 @@ var init_vm_adapter = __esm({
|
|
|
5459
5652
|
}
|
|
5460
5653
|
});
|
|
5461
5654
|
|
|
5462
|
-
// libs/
|
|
5655
|
+
// libs/core/src/adapters/worker-pool/config.ts
|
|
5463
5656
|
import os from "os";
|
|
5464
5657
|
function buildWorkerPoolConfig(securityLevel, overrides) {
|
|
5465
5658
|
const preset = WORKER_POOL_PRESETS[securityLevel];
|
|
@@ -5471,7 +5664,7 @@ function buildWorkerPoolConfig(securityLevel, overrides) {
|
|
|
5471
5664
|
}
|
|
5472
5665
|
var DEFAULT_WORKER_POOL_CONFIG, WORKER_POOL_PRESETS;
|
|
5473
5666
|
var init_config = __esm({
|
|
5474
|
-
"libs/
|
|
5667
|
+
"libs/core/src/adapters/worker-pool/config.ts"() {
|
|
5475
5668
|
"use strict";
|
|
5476
5669
|
DEFAULT_WORKER_POOL_CONFIG = {
|
|
5477
5670
|
minWorkers: 2,
|
|
@@ -5584,7 +5777,7 @@ var init_config = __esm({
|
|
|
5584
5777
|
}
|
|
5585
5778
|
});
|
|
5586
5779
|
|
|
5587
|
-
// libs/
|
|
5780
|
+
// libs/core/src/adapters/worker-pool/protocol.ts
|
|
5588
5781
|
import { z } from "zod";
|
|
5589
5782
|
function isToolCallMessage(msg) {
|
|
5590
5783
|
return msg.type === "tool-call";
|
|
@@ -5597,7 +5790,7 @@ function isConsoleMessage(msg) {
|
|
|
5597
5790
|
}
|
|
5598
5791
|
var TOOL_NAME_PATTERN, ID_PATTERN, toolCallMessageSchema, executionResultMessageSchema, memoryReportResultMessageSchema, consoleMessageSchema, workerReadyMessageSchema, workerToMainMessageSchema;
|
|
5599
5792
|
var init_protocol = __esm({
|
|
5600
|
-
"libs/
|
|
5793
|
+
"libs/core/src/adapters/worker-pool/protocol.ts"() {
|
|
5601
5794
|
"use strict";
|
|
5602
5795
|
TOOL_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9:_-]*$/;
|
|
5603
5796
|
ID_PATTERN = /^[a-zA-Z0-9-]+$/;
|
|
@@ -5656,10 +5849,10 @@ var init_protocol = __esm({
|
|
|
5656
5849
|
}
|
|
5657
5850
|
});
|
|
5658
5851
|
|
|
5659
|
-
// libs/
|
|
5852
|
+
// libs/core/src/adapters/worker-pool/errors.ts
|
|
5660
5853
|
var WorkerPoolError, WorkerTimeoutError, WorkerMemoryError, WorkerCrashedError, WorkerPoolDisposedError, QueueFullError, QueueTimeoutError, ExecutionAbortedError, MessageFloodError, MessageValidationError, MessageSizeError, WorkerStartupError, TooManyPendingCallsError;
|
|
5661
5854
|
var init_errors = __esm({
|
|
5662
|
-
"libs/
|
|
5855
|
+
"libs/core/src/adapters/worker-pool/errors.ts"() {
|
|
5663
5856
|
"use strict";
|
|
5664
5857
|
WorkerPoolError = class extends Error {
|
|
5665
5858
|
constructor(message) {
|
|
@@ -5785,7 +5978,7 @@ var init_errors = __esm({
|
|
|
5785
5978
|
}
|
|
5786
5979
|
});
|
|
5787
5980
|
|
|
5788
|
-
// libs/
|
|
5981
|
+
// libs/core/src/adapters/worker-pool/safe-deserialize.ts
|
|
5789
5982
|
function safeDeserialize(raw, maxSizeBytes) {
|
|
5790
5983
|
if (maxSizeBytes !== void 0) {
|
|
5791
5984
|
const byteLength = Buffer.byteLength(raw, "utf-8");
|
|
@@ -5855,7 +6048,7 @@ function sanitizeObject(value, depth = 0) {
|
|
|
5855
6048
|
}
|
|
5856
6049
|
var DANGEROUS_KEYS2, MAX_DEPTH;
|
|
5857
6050
|
var init_safe_deserialize = __esm({
|
|
5858
|
-
"libs/
|
|
6051
|
+
"libs/core/src/adapters/worker-pool/safe-deserialize.ts"() {
|
|
5859
6052
|
"use strict";
|
|
5860
6053
|
init_errors();
|
|
5861
6054
|
DANGEROUS_KEYS2 = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
@@ -5863,13 +6056,13 @@ var init_safe_deserialize = __esm({
|
|
|
5863
6056
|
}
|
|
5864
6057
|
});
|
|
5865
6058
|
|
|
5866
|
-
// libs/
|
|
6059
|
+
// libs/core/src/adapters/worker-pool/worker-slot.ts
|
|
5867
6060
|
import { Worker } from "worker_threads";
|
|
5868
6061
|
import path from "path";
|
|
5869
6062
|
import { EventEmitter } from "events";
|
|
5870
6063
|
var WorkerSlot;
|
|
5871
6064
|
var init_worker_slot = __esm({
|
|
5872
|
-
"libs/
|
|
6065
|
+
"libs/core/src/adapters/worker-pool/worker-slot.ts"() {
|
|
5873
6066
|
"use strict";
|
|
5874
6067
|
init_safe_deserialize();
|
|
5875
6068
|
init_errors();
|
|
@@ -6135,10 +6328,10 @@ var init_worker_slot = __esm({
|
|
|
6135
6328
|
}
|
|
6136
6329
|
});
|
|
6137
6330
|
|
|
6138
|
-
// libs/
|
|
6331
|
+
// libs/core/src/adapters/worker-pool/execution-queue.ts
|
|
6139
6332
|
var ExecutionQueue;
|
|
6140
6333
|
var init_execution_queue = __esm({
|
|
6141
|
-
"libs/
|
|
6334
|
+
"libs/core/src/adapters/worker-pool/execution-queue.ts"() {
|
|
6142
6335
|
"use strict";
|
|
6143
6336
|
init_errors();
|
|
6144
6337
|
ExecutionQueue = class {
|
|
@@ -6298,11 +6491,11 @@ var init_execution_queue = __esm({
|
|
|
6298
6491
|
}
|
|
6299
6492
|
});
|
|
6300
6493
|
|
|
6301
|
-
// libs/
|
|
6494
|
+
// libs/core/src/adapters/worker-pool/memory-monitor.ts
|
|
6302
6495
|
import { EventEmitter as EventEmitter2 } from "events";
|
|
6303
6496
|
var MemoryMonitor;
|
|
6304
6497
|
var init_memory_monitor = __esm({
|
|
6305
|
-
"libs/
|
|
6498
|
+
"libs/core/src/adapters/worker-pool/memory-monitor.ts"() {
|
|
6306
6499
|
"use strict";
|
|
6307
6500
|
MemoryMonitor = class extends EventEmitter2 {
|
|
6308
6501
|
config;
|
|
@@ -6468,7 +6661,7 @@ var init_memory_monitor = __esm({
|
|
|
6468
6661
|
}
|
|
6469
6662
|
});
|
|
6470
6663
|
|
|
6471
|
-
// libs/
|
|
6664
|
+
// libs/core/src/adapters/worker-pool/rate-limiter.ts
|
|
6472
6665
|
function createRateLimiter(maxMessagesPerSecond) {
|
|
6473
6666
|
return new RateLimiter({
|
|
6474
6667
|
maxMessagesPerWindow: maxMessagesPerSecond,
|
|
@@ -6477,7 +6670,7 @@ function createRateLimiter(maxMessagesPerSecond) {
|
|
|
6477
6670
|
}
|
|
6478
6671
|
var RateLimiter;
|
|
6479
6672
|
var init_rate_limiter = __esm({
|
|
6480
|
-
"libs/
|
|
6673
|
+
"libs/core/src/adapters/worker-pool/rate-limiter.ts"() {
|
|
6481
6674
|
"use strict";
|
|
6482
6675
|
init_errors();
|
|
6483
6676
|
RateLimiter = class {
|
|
@@ -6553,11 +6746,11 @@ var init_rate_limiter = __esm({
|
|
|
6553
6746
|
}
|
|
6554
6747
|
});
|
|
6555
6748
|
|
|
6556
|
-
// libs/
|
|
6749
|
+
// libs/core/src/adapters/worker-pool/worker-pool-adapter.ts
|
|
6557
6750
|
import crypto from "crypto";
|
|
6558
6751
|
var WorkerPoolAdapter;
|
|
6559
6752
|
var init_worker_pool_adapter = __esm({
|
|
6560
|
-
"libs/
|
|
6753
|
+
"libs/core/src/adapters/worker-pool/worker-pool-adapter.ts"() {
|
|
6561
6754
|
"use strict";
|
|
6562
6755
|
init_config();
|
|
6563
6756
|
init_protocol();
|
|
@@ -6576,6 +6769,8 @@ var init_worker_pool_adapter = __esm({
|
|
|
6576
6769
|
rateLimiter;
|
|
6577
6770
|
disposed = false;
|
|
6578
6771
|
initialized = false;
|
|
6772
|
+
// Bound event handler for proper cleanup
|
|
6773
|
+
boundMemoryExceededHandler = this.handleMemoryExceeded.bind(this);
|
|
6579
6774
|
// Metrics
|
|
6580
6775
|
_totalExecutions = 0;
|
|
6581
6776
|
_successfulExecutions = 0;
|
|
@@ -6598,7 +6793,7 @@ var init_worker_pool_adapter = __esm({
|
|
|
6598
6793
|
this.slots
|
|
6599
6794
|
);
|
|
6600
6795
|
this.rateLimiter = createRateLimiter(this.config.maxMessagesPerSecond);
|
|
6601
|
-
this.memoryMonitor.on("memoryExceeded", this.
|
|
6796
|
+
this.memoryMonitor.on("memoryExceeded", this.boundMemoryExceededHandler);
|
|
6602
6797
|
}
|
|
6603
6798
|
/**
|
|
6604
6799
|
* Initialize the worker pool
|
|
@@ -6663,6 +6858,7 @@ var init_worker_pool_adapter = __esm({
|
|
|
6663
6858
|
return;
|
|
6664
6859
|
}
|
|
6665
6860
|
this.disposed = true;
|
|
6861
|
+
this.memoryMonitor.off("memoryExceeded", this.boundMemoryExceededHandler);
|
|
6666
6862
|
this.memoryMonitor.stop();
|
|
6667
6863
|
this.executionQueue.clear();
|
|
6668
6864
|
const terminatePromises = [];
|
|
@@ -6989,7 +7185,7 @@ var init_worker_pool_adapter = __esm({
|
|
|
6989
7185
|
}
|
|
6990
7186
|
});
|
|
6991
7187
|
|
|
6992
|
-
// libs/
|
|
7188
|
+
// libs/core/src/adapters/worker-pool/index.ts
|
|
6993
7189
|
var worker_pool_exports = {};
|
|
6994
7190
|
__export(worker_pool_exports, {
|
|
6995
7191
|
DEFAULT_WORKER_POOL_CONFIG: () => DEFAULT_WORKER_POOL_CONFIG,
|
|
@@ -7019,7 +7215,7 @@ __export(worker_pool_exports, {
|
|
|
7019
7215
|
sanitizeObject: () => sanitizeObject
|
|
7020
7216
|
});
|
|
7021
7217
|
var init_worker_pool = __esm({
|
|
7022
|
-
"libs/
|
|
7218
|
+
"libs/core/src/adapters/worker-pool/index.ts"() {
|
|
7023
7219
|
"use strict";
|
|
7024
7220
|
init_worker_pool_adapter();
|
|
7025
7221
|
init_config();
|
|
@@ -7032,7 +7228,7 @@ var init_worker_pool = __esm({
|
|
|
7032
7228
|
}
|
|
7033
7229
|
});
|
|
7034
7230
|
|
|
7035
|
-
// libs/
|
|
7231
|
+
// libs/core/src/enclave.ts
|
|
7036
7232
|
import {
|
|
7037
7233
|
JSAstValidator,
|
|
7038
7234
|
createAgentScriptPreset,
|
|
@@ -7045,7 +7241,7 @@ import {
|
|
|
7045
7241
|
getAgentScriptGlobals
|
|
7046
7242
|
} from "@enclave-vm/ast";
|
|
7047
7243
|
|
|
7048
|
-
// libs/
|
|
7244
|
+
// libs/core/src/babel/babel-wrapper.ts
|
|
7049
7245
|
import * as vm from "vm";
|
|
7050
7246
|
import * as BabelStandalone from "@babel/standalone";
|
|
7051
7247
|
import { rewriteImports } from "@enclave-vm/ast";
|
|
@@ -7323,7 +7519,7 @@ function getAvailableBabelPresets() {
|
|
|
7323
7519
|
return ["env", "react", "typescript", "flow"];
|
|
7324
7520
|
}
|
|
7325
7521
|
|
|
7326
|
-
// libs/
|
|
7522
|
+
// libs/core/src/babel/multi-file-transform.ts
|
|
7327
7523
|
import { rewriteImports as rewriteImports2 } from "@enclave-vm/ast";
|
|
7328
7524
|
var VALID_FILENAME_REGEX = /^[a-zA-Z0-9_\-./]+\.(ts|tsx|js|jsx|mjs|cjs|mts|cts)$/;
|
|
7329
7525
|
var EXTENSION_MAP = {
|
|
@@ -7545,13 +7741,13 @@ function transformMultiple(files, options, limits, singleFileTransform) {
|
|
|
7545
7741
|
};
|
|
7546
7742
|
}
|
|
7547
7743
|
|
|
7548
|
-
// libs/
|
|
7744
|
+
// libs/core/src/enclave.ts
|
|
7549
7745
|
import { transformAgentScript, isWrappedInMain } from "@enclave-vm/ast";
|
|
7550
7746
|
import { extractLargeStrings, transformConcatenation, transformTemplateLiterals } from "@enclave-vm/ast";
|
|
7551
7747
|
import * as acorn2 from "acorn";
|
|
7552
7748
|
import { generate } from "astring";
|
|
7553
7749
|
|
|
7554
|
-
// libs/
|
|
7750
|
+
// libs/core/src/types.ts
|
|
7555
7751
|
var SECURITY_LEVEL_CONFIGS = {
|
|
7556
7752
|
/**
|
|
7557
7753
|
* STRICT: Maximum security for untrusted code
|
|
@@ -7728,7 +7924,7 @@ var DEFAULT_DOUBLE_VM_CONFIG = {
|
|
|
7728
7924
|
}
|
|
7729
7925
|
};
|
|
7730
7926
|
|
|
7731
|
-
// libs/
|
|
7927
|
+
// libs/core/src/globals-validator.ts
|
|
7732
7928
|
var DANGEROUS_FUNCTION_PATTERNS = [
|
|
7733
7929
|
/\beval\b/,
|
|
7734
7930
|
// eval() calls
|
|
@@ -7846,10 +8042,10 @@ function validateGlobals(globals, options = {}) {
|
|
|
7846
8042
|
}
|
|
7847
8043
|
}
|
|
7848
8044
|
|
|
7849
|
-
// libs/
|
|
8045
|
+
// libs/core/src/sidecar/index.ts
|
|
7850
8046
|
init_reference_config();
|
|
7851
8047
|
|
|
7852
|
-
// libs/
|
|
8048
|
+
// libs/core/src/sidecar/reference-sidecar.ts
|
|
7853
8049
|
init_reference_config();
|
|
7854
8050
|
import { randomUUID } from "crypto";
|
|
7855
8051
|
var SidecarLimitError = class _SidecarLimitError extends Error {
|
|
@@ -8037,15 +8233,15 @@ var ReferenceSidecar = class {
|
|
|
8037
8233
|
}
|
|
8038
8234
|
};
|
|
8039
8235
|
|
|
8040
|
-
// libs/
|
|
8236
|
+
// libs/core/src/sidecar/index.ts
|
|
8041
8237
|
init_reference_resolver();
|
|
8042
8238
|
|
|
8043
|
-
// libs/
|
|
8239
|
+
// libs/core/src/scoring/feature-extractor.ts
|
|
8044
8240
|
import * as acorn from "acorn";
|
|
8045
8241
|
import * as walk from "acorn-walk";
|
|
8046
8242
|
import { createHash } from "crypto";
|
|
8047
8243
|
|
|
8048
|
-
// libs/
|
|
8244
|
+
// libs/core/src/scoring/types.ts
|
|
8049
8245
|
var DEFAULT_PROGRESSIVE_CONFIG = {
|
|
8050
8246
|
escalationThreshold: 30,
|
|
8051
8247
|
combination: "max"
|
|
@@ -8119,7 +8315,7 @@ var RULE_THRESHOLDS = {
|
|
|
8119
8315
|
HIGH_FAN_OUT: 3
|
|
8120
8316
|
};
|
|
8121
8317
|
|
|
8122
|
-
// libs/
|
|
8318
|
+
// libs/core/src/scoring/feature-extractor.ts
|
|
8123
8319
|
var SENSITIVE_PATTERNS = {
|
|
8124
8320
|
authentication: /password|token|secret|api.?key|auth|credential|bearer/i,
|
|
8125
8321
|
pii: /email|ssn|phone|address|credit.?card|birth.?date|social.?security/i,
|
|
@@ -8421,7 +8617,7 @@ var FeatureExtractor = class {
|
|
|
8421
8617
|
}
|
|
8422
8618
|
};
|
|
8423
8619
|
|
|
8424
|
-
// libs/
|
|
8620
|
+
// libs/core/src/scoring/cache.ts
|
|
8425
8621
|
var ScoringCache = class {
|
|
8426
8622
|
cache;
|
|
8427
8623
|
config;
|
|
@@ -8558,7 +8754,7 @@ var ScoringCache = class {
|
|
|
8558
8754
|
}
|
|
8559
8755
|
};
|
|
8560
8756
|
|
|
8561
|
-
// libs/
|
|
8757
|
+
// libs/core/src/scoring/scorer.interface.ts
|
|
8562
8758
|
var BaseScorer = class {
|
|
8563
8759
|
ready = false;
|
|
8564
8760
|
async initialize() {
|
|
@@ -8588,7 +8784,7 @@ var BaseScorer = class {
|
|
|
8588
8784
|
}
|
|
8589
8785
|
};
|
|
8590
8786
|
|
|
8591
|
-
// libs/
|
|
8787
|
+
// libs/core/src/scoring/scorers/disabled.scorer.ts
|
|
8592
8788
|
var DisabledScorer = class extends BaseScorer {
|
|
8593
8789
|
type = "disabled";
|
|
8594
8790
|
name = "DisabledScorer";
|
|
@@ -8607,7 +8803,7 @@ var DisabledScorer = class extends BaseScorer {
|
|
|
8607
8803
|
}
|
|
8608
8804
|
};
|
|
8609
8805
|
|
|
8610
|
-
// libs/
|
|
8806
|
+
// libs/core/src/scoring/scorers/rule-based.scorer.ts
|
|
8611
8807
|
var RULE_SCORES = {
|
|
8612
8808
|
SENSITIVE_FIELD: 35,
|
|
8613
8809
|
// Base score for sensitive field access
|
|
@@ -8869,7 +9065,7 @@ var RuleBasedScorer = class extends BaseScorer {
|
|
|
8869
9065
|
}
|
|
8870
9066
|
};
|
|
8871
9067
|
|
|
8872
|
-
// libs/
|
|
9068
|
+
// libs/core/src/scoring/scorers/external-api.scorer.ts
|
|
8873
9069
|
var VALID_RISK_LEVELS = ["none", "low", "medium", "high", "critical"];
|
|
8874
9070
|
var ExternalApiScorer = class extends BaseScorer {
|
|
8875
9071
|
type = "external-api";
|
|
@@ -8982,7 +9178,7 @@ var ExternalApiScorerError = class extends Error {
|
|
|
8982
9178
|
}
|
|
8983
9179
|
};
|
|
8984
9180
|
|
|
8985
|
-
// libs/
|
|
9181
|
+
// libs/core/src/scoring/scorers/local-llm.scorer.ts
|
|
8986
9182
|
import { homedir } from "node:os";
|
|
8987
9183
|
import { join } from "node:path";
|
|
8988
9184
|
var LEGACY_DEFAULT_CACHE_DIR = "./.cache/transformers";
|
|
@@ -9370,7 +9566,7 @@ var LocalLlmScorerError = class extends Error {
|
|
|
9370
9566
|
}
|
|
9371
9567
|
};
|
|
9372
9568
|
|
|
9373
|
-
// libs/
|
|
9569
|
+
// libs/core/src/scoring/scorers/progressive.scorer.ts
|
|
9374
9570
|
var ProgressiveScorer = class extends BaseScorer {
|
|
9375
9571
|
type = "progressive";
|
|
9376
9572
|
name = "ProgressiveScorer";
|
|
@@ -9519,7 +9715,7 @@ var ProgressiveScorer = class extends BaseScorer {
|
|
|
9519
9715
|
}
|
|
9520
9716
|
};
|
|
9521
9717
|
|
|
9522
|
-
// libs/
|
|
9718
|
+
// libs/core/src/scoring/scoring-gate.ts
|
|
9523
9719
|
var ScoringGate = class {
|
|
9524
9720
|
extractor;
|
|
9525
9721
|
config;
|
|
@@ -9724,7 +9920,7 @@ function createScoringGate(config) {
|
|
|
9724
9920
|
return new ScoringGate(config);
|
|
9725
9921
|
}
|
|
9726
9922
|
|
|
9727
|
-
// libs/
|
|
9923
|
+
// libs/core/src/enclave.ts
|
|
9728
9924
|
var DEFAULT_SECURITY_LEVEL = "STANDARD";
|
|
9729
9925
|
var DEFAULT_TOOL_BRIDGE_MAX_PAYLOAD_BYTES = 5 * 1024 * 1024;
|
|
9730
9926
|
function getConfigFromSecurityLevel(securityLevel, options) {
|
|
@@ -9778,6 +9974,7 @@ var Enclave = class {
|
|
|
9778
9974
|
referenceConfig;
|
|
9779
9975
|
scoringGate;
|
|
9780
9976
|
doubleVmConfig;
|
|
9977
|
+
customGlobalNames;
|
|
9781
9978
|
adapter;
|
|
9782
9979
|
constructor(options = {}) {
|
|
9783
9980
|
this.securityLevel = options.securityLevel ?? DEFAULT_SECURITY_LEVEL;
|
|
@@ -9849,8 +10046,8 @@ var Enclave = class {
|
|
|
9849
10046
|
secureProxyConfig: securityConfig.secureProxyConfig,
|
|
9850
10047
|
globals: initialGlobals
|
|
9851
10048
|
};
|
|
9852
|
-
|
|
9853
|
-
const customAllowedGlobals = customGlobalNames.flatMap((name) => [name, `__safe_${name}`]);
|
|
10049
|
+
this.customGlobalNames = Object.keys(initialGlobals);
|
|
10050
|
+
const customAllowedGlobals = this.customGlobalNames.flatMap((name) => [name, `__safe_${name}`]);
|
|
9854
10051
|
this.validator = this.createValidator(presetName, customAllowedGlobals);
|
|
9855
10052
|
this.validateCode = options.validate !== false;
|
|
9856
10053
|
this.transformCode = options.transform !== false;
|
|
@@ -9914,7 +10111,9 @@ var Enclave = class {
|
|
|
9914
10111
|
transformedCode = transformAgentScript(code, {
|
|
9915
10112
|
wrapInMain: needsWrapping,
|
|
9916
10113
|
transformCallTool: true,
|
|
9917
|
-
transformLoops: true
|
|
10114
|
+
transformLoops: true,
|
|
10115
|
+
// Pass custom global names so they aren't transformed to __safe_ prefix
|
|
10116
|
+
additionalIdentifiers: this.customGlobalNames
|
|
9918
10117
|
});
|
|
9919
10118
|
}
|
|
9920
10119
|
if (this.validateCode) {
|
|
@@ -10240,16 +10439,16 @@ async function runAgentScript(code, options = {}) {
|
|
|
10240
10439
|
}
|
|
10241
10440
|
}
|
|
10242
10441
|
|
|
10243
|
-
// libs/
|
|
10442
|
+
// libs/core/src/index.ts
|
|
10244
10443
|
init_safe_runtime();
|
|
10245
10444
|
init_secure_proxy();
|
|
10246
10445
|
init_memory_tracker();
|
|
10247
10446
|
init_worker_pool();
|
|
10248
10447
|
|
|
10249
|
-
// libs/
|
|
10448
|
+
// libs/core/src/session/session.ts
|
|
10250
10449
|
import { generateCallId, generateSessionId, DEFAULT_SESSION_LIMITS } from "@enclave-vm/types";
|
|
10251
10450
|
|
|
10252
|
-
// libs/
|
|
10451
|
+
// libs/core/src/session/session-emitter.ts
|
|
10253
10452
|
import { PROTOCOL_VERSION, EventType } from "@enclave-vm/types";
|
|
10254
10453
|
var SessionEmitter = class {
|
|
10255
10454
|
sessionId;
|
|
@@ -10480,7 +10679,7 @@ function createSessionEmitter(sessionId, options = {}) {
|
|
|
10480
10679
|
});
|
|
10481
10680
|
}
|
|
10482
10681
|
|
|
10483
|
-
// libs/
|
|
10682
|
+
// libs/core/src/session/session-state-machine.ts
|
|
10484
10683
|
var VALID_TRANSITIONS = {
|
|
10485
10684
|
starting: ["running", "failed", "cancelled"],
|
|
10486
10685
|
running: ["waiting_for_tool", "completed", "failed", "cancelled"],
|
|
@@ -10639,7 +10838,7 @@ function createSessionStateMachine(initialState) {
|
|
|
10639
10838
|
return new SessionStateMachine(initialState);
|
|
10640
10839
|
}
|
|
10641
10840
|
|
|
10642
|
-
// libs/
|
|
10841
|
+
// libs/core/src/session/session.ts
|
|
10643
10842
|
var Session = class {
|
|
10644
10843
|
sessionId;
|
|
10645
10844
|
createdAt;
|
|
@@ -10978,7 +11177,7 @@ function createSession(options) {
|
|
|
10978
11177
|
return new Session(options);
|
|
10979
11178
|
}
|
|
10980
11179
|
|
|
10981
|
-
// libs/
|
|
11180
|
+
// libs/core/src/session/channels/embedded-channel.ts
|
|
10982
11181
|
var EmbeddedChannel = class {
|
|
10983
11182
|
_isOpen = true;
|
|
10984
11183
|
eventHandlers;
|
|
@@ -11081,7 +11280,7 @@ function createEmbeddedChannelPair() {
|
|
|
11081
11280
|
};
|
|
11082
11281
|
}
|
|
11083
11282
|
|
|
11084
|
-
// libs/
|
|
11283
|
+
// libs/core/src/session-types.ts
|
|
11085
11284
|
function isSession(obj) {
|
|
11086
11285
|
return typeof obj === "object" && obj !== null && "sessionId" in obj && "state" in obj && "submitToolResult" in obj && typeof obj.submitToolResult === "function";
|
|
11087
11286
|
}
|