@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/index.js
CHANGED
|
@@ -30,7 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
-
// libs/
|
|
33
|
+
// libs/core/src/sidecar/reference-config.ts
|
|
34
34
|
function isReferenceId(value) {
|
|
35
35
|
return typeof value === "string" && REF_ID_PATTERN.test(value);
|
|
36
36
|
}
|
|
@@ -42,7 +42,7 @@ function getReferenceConfig(securityLevel, overrides) {
|
|
|
42
42
|
}
|
|
43
43
|
var REFERENCE_CONFIGS, REF_ID_PREFIX, REF_ID_SUFFIX, REF_ID_PATTERN;
|
|
44
44
|
var init_reference_config = __esm({
|
|
45
|
-
"libs/
|
|
45
|
+
"libs/core/src/sidecar/reference-config.ts"() {
|
|
46
46
|
"use strict";
|
|
47
47
|
REFERENCE_CONFIGS = {
|
|
48
48
|
/**
|
|
@@ -144,14 +144,14 @@ var init_reference_config = __esm({
|
|
|
144
144
|
}
|
|
145
145
|
});
|
|
146
146
|
|
|
147
|
-
// libs/
|
|
147
|
+
// libs/core/src/sidecar/reference-resolver.ts
|
|
148
148
|
function isCompositeHandle(value) {
|
|
149
149
|
const obj = value;
|
|
150
150
|
return typeof value === "object" && value !== null && obj["__type"] === "composite" && Array.isArray(obj["__parts"]);
|
|
151
151
|
}
|
|
152
152
|
var ResolutionLimitError, ReferenceResolver;
|
|
153
153
|
var init_reference_resolver = __esm({
|
|
154
|
-
"libs/
|
|
154
|
+
"libs/core/src/sidecar/reference-resolver.ts"() {
|
|
155
155
|
"use strict";
|
|
156
156
|
init_reference_config();
|
|
157
157
|
ResolutionLimitError = class _ResolutionLimitError extends Error {
|
|
@@ -359,7 +359,7 @@ var init_reference_resolver = __esm({
|
|
|
359
359
|
}
|
|
360
360
|
});
|
|
361
361
|
|
|
362
|
-
// libs/
|
|
362
|
+
// libs/core/src/value-sanitizer.ts
|
|
363
363
|
function sanitizeValue(value, options = {}, depth = 0, context = { propCount: { count: 0 }, visited: /* @__PURE__ */ new WeakSet() }) {
|
|
364
364
|
const maxDepth = options.maxDepth ?? 20;
|
|
365
365
|
const maxProperties = options.maxProperties ?? 1e4;
|
|
@@ -595,13 +595,13 @@ function checkSerializedSize(value, maxBytes) {
|
|
|
595
595
|
}
|
|
596
596
|
var DANGEROUS_KEYS;
|
|
597
597
|
var init_value_sanitizer = __esm({
|
|
598
|
-
"libs/
|
|
598
|
+
"libs/core/src/value-sanitizer.ts"() {
|
|
599
599
|
"use strict";
|
|
600
600
|
DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor"]);
|
|
601
601
|
}
|
|
602
602
|
});
|
|
603
603
|
|
|
604
|
-
// libs/
|
|
604
|
+
// libs/core/src/safe-error.ts
|
|
605
605
|
function createSafeError(message, name = "Error") {
|
|
606
606
|
const error = new Error(message);
|
|
607
607
|
error.name = name;
|
|
@@ -653,12 +653,12 @@ function createSafeTypeError(message) {
|
|
|
653
653
|
return createSafeError(message, "TypeError");
|
|
654
654
|
}
|
|
655
655
|
var init_safe_error = __esm({
|
|
656
|
-
"libs/
|
|
656
|
+
"libs/core/src/safe-error.ts"() {
|
|
657
657
|
"use strict";
|
|
658
658
|
}
|
|
659
659
|
});
|
|
660
660
|
|
|
661
|
-
// libs/
|
|
661
|
+
// libs/core/src/secure-proxy.ts
|
|
662
662
|
function getBlockedPropertiesForLevel(level) {
|
|
663
663
|
const blocked = /* @__PURE__ */ new Set();
|
|
664
664
|
if (level !== "PERMISSIVE") {
|
|
@@ -980,7 +980,7 @@ function isSecureProxy(obj) {
|
|
|
980
980
|
}
|
|
981
981
|
var BLOCKED_PROPERTY_CATEGORIES, BLOCKED_PROPERTIES, DEFAULT_SECURE_PROXY_CONFIG, FUNCTION_BLOCKED_PROPERTIES, proxyCache, proxySet, NON_PROXYABLE_TYPES, INTERNAL_SLOT_TYPES;
|
|
982
982
|
var init_secure_proxy = __esm({
|
|
983
|
-
"libs/
|
|
983
|
+
"libs/core/src/secure-proxy.ts"() {
|
|
984
984
|
"use strict";
|
|
985
985
|
init_safe_error();
|
|
986
986
|
BLOCKED_PROPERTY_CATEGORIES = {
|
|
@@ -1096,7 +1096,7 @@ var init_secure_proxy = __esm({
|
|
|
1096
1096
|
}
|
|
1097
1097
|
});
|
|
1098
1098
|
|
|
1099
|
-
// libs/
|
|
1099
|
+
// libs/core/src/memory-tracker.ts
|
|
1100
1100
|
function estimateStringSize2(str) {
|
|
1101
1101
|
return str.length * 2 + 40;
|
|
1102
1102
|
}
|
|
@@ -1108,7 +1108,7 @@ function estimateObjectSize(propertyCount) {
|
|
|
1108
1108
|
}
|
|
1109
1109
|
var MemoryLimitError, MemoryTracker;
|
|
1110
1110
|
var init_memory_tracker = __esm({
|
|
1111
|
-
"libs/
|
|
1111
|
+
"libs/core/src/memory-tracker.ts"() {
|
|
1112
1112
|
"use strict";
|
|
1113
1113
|
MemoryLimitError = class _MemoryLimitError extends Error {
|
|
1114
1114
|
constructor(message, usedBytes, limitBytes) {
|
|
@@ -1250,7 +1250,7 @@ var init_memory_tracker = __esm({
|
|
|
1250
1250
|
}
|
|
1251
1251
|
});
|
|
1252
1252
|
|
|
1253
|
-
// libs/
|
|
1253
|
+
// libs/core/src/tool-bridge.ts
|
|
1254
1254
|
function utf8ByteLength(value) {
|
|
1255
1255
|
return Buffer.byteLength(value, "utf8");
|
|
1256
1256
|
}
|
|
@@ -1587,7 +1587,7 @@ function createHostToolBridge(executionContext, options) {
|
|
|
1587
1587
|
}
|
|
1588
1588
|
var TOOL_BRIDGE_PROTOCOL_VERSION;
|
|
1589
1589
|
var init_tool_bridge = __esm({
|
|
1590
|
-
"libs/
|
|
1590
|
+
"libs/core/src/tool-bridge.ts"() {
|
|
1591
1591
|
"use strict";
|
|
1592
1592
|
init_value_sanitizer();
|
|
1593
1593
|
init_reference_resolver();
|
|
@@ -1595,7 +1595,7 @@ var init_tool_bridge = __esm({
|
|
|
1595
1595
|
}
|
|
1596
1596
|
});
|
|
1597
1597
|
|
|
1598
|
-
// libs/
|
|
1598
|
+
// libs/core/src/double-vm/parent-vm-bootstrap.ts
|
|
1599
1599
|
function generateSanitizeContextCode(securityLevel) {
|
|
1600
1600
|
const globalsToRemove = NODEJS_24_DANGEROUS_GLOBALS[securityLevel];
|
|
1601
1601
|
return globalsToRemove.map(
|
|
@@ -2935,8 +2935,110 @@ ${stackTraceHardeningCode}
|
|
|
2935
2935
|
// Remove dangerous globals from inner VM (AFTER memory patching)
|
|
2936
2936
|
${sanitizeContextCode}
|
|
2937
2937
|
|
|
2938
|
-
//
|
|
2939
|
-
//
|
|
2938
|
+
// ============================================================
|
|
2939
|
+
// PHASE 2 HARDENING: CVE-2023-29017 Stack Overflow Escape Defense
|
|
2940
|
+
// ============================================================
|
|
2941
|
+
//
|
|
2942
|
+
// CRITICAL: Hardening MUST run BEFORE prototypes are frozen!
|
|
2943
|
+
// Otherwise Object.defineProperty calls will silently fail on frozen prototypes.
|
|
2944
|
+
//
|
|
2945
|
+
// Defense-in-depth against prototype chain escape via stack overflow errors:
|
|
2946
|
+
// 1. __proto__ shadowing to block prototype chain traversal
|
|
2947
|
+
// 2. Legacy method blocking (__lookupGetter__, etc.)
|
|
2948
|
+
// 3. Error constructor wrapping to secure V8-generated errors
|
|
2949
|
+
// 4. Then freeze all prototypes to lock in hardening
|
|
2950
|
+
|
|
2951
|
+
// HARDENING 1: Shadow __proto__ on PARENT VM error prototypes with null
|
|
2952
|
+
// This prevents e["__proto__"]["__proto__"] traversal attacks by making
|
|
2953
|
+
// __proto__ return null instead of the actual prototype chain.
|
|
2954
|
+
// MUST run before freeze!
|
|
2955
|
+
(function() {
|
|
2956
|
+
var errorProtos = [
|
|
2957
|
+
Error.prototype,
|
|
2958
|
+
TypeError.prototype,
|
|
2959
|
+
RangeError.prototype,
|
|
2960
|
+
SyntaxError.prototype,
|
|
2961
|
+
ReferenceError.prototype,
|
|
2962
|
+
URIError.prototype,
|
|
2963
|
+
EvalError.prototype
|
|
2964
|
+
];
|
|
2965
|
+
for (var i = 0; i < errorProtos.length; i++) {
|
|
2966
|
+
// Shadow __proto__ with a null-returning getter
|
|
2967
|
+
// This blocks: error["__proto__"]["__proto__"]["__proto__"] attacks
|
|
2968
|
+
Object.defineProperty(errorProtos[i], '__proto__', {
|
|
2969
|
+
get: function() { return null; },
|
|
2970
|
+
set: function() { /* silently ignore */ },
|
|
2971
|
+
configurable: false,
|
|
2972
|
+
enumerable: false
|
|
2973
|
+
});
|
|
2974
|
+
}
|
|
2975
|
+
})();
|
|
2976
|
+
|
|
2977
|
+
// HARDENING 2: Shadow __proto__ in INNER VM error prototypes
|
|
2978
|
+
// MUST run before freeze!
|
|
2979
|
+
(function() {
|
|
2980
|
+
var shadowProtoCode =
|
|
2981
|
+
'(function() {' +
|
|
2982
|
+
' var errorProtos = [' +
|
|
2983
|
+
' Error.prototype,' +
|
|
2984
|
+
' TypeError.prototype,' +
|
|
2985
|
+
' RangeError.prototype,' +
|
|
2986
|
+
' SyntaxError.prototype,' +
|
|
2987
|
+
' ReferenceError.prototype,' +
|
|
2988
|
+
' URIError.prototype,' +
|
|
2989
|
+
' EvalError.prototype' +
|
|
2990
|
+
' ];' +
|
|
2991
|
+
' for (var i = 0; i < errorProtos.length; i++) {' +
|
|
2992
|
+
' Object.defineProperty(errorProtos[i], "__proto__", {' +
|
|
2993
|
+
' get: function() { return null; },' +
|
|
2994
|
+
' set: function() {},' +
|
|
2995
|
+
' configurable: false,' +
|
|
2996
|
+
' enumerable: false' +
|
|
2997
|
+
' });' +
|
|
2998
|
+
' }' +
|
|
2999
|
+
'})();';
|
|
3000
|
+
var shadowScript = new vm.Script(shadowProtoCode);
|
|
3001
|
+
shadowScript.runInContext(innerContext);
|
|
3002
|
+
})();
|
|
3003
|
+
|
|
3004
|
+
// HARDENING 3: Block legacy prototype manipulation methods in PARENT VM
|
|
3005
|
+
// These deprecated methods (__lookupGetter__, __lookupSetter__, __defineGetter__, __defineSetter__)
|
|
3006
|
+
// can be used to bypass frozen prototype protections.
|
|
3007
|
+
// MUST run before freeze!
|
|
3008
|
+
(function() {
|
|
3009
|
+
var legacyMethods = ['__lookupGetter__', '__lookupSetter__', '__defineGetter__', '__defineSetter__'];
|
|
3010
|
+
for (var i = 0; i < legacyMethods.length; i++) {
|
|
3011
|
+
Object.defineProperty(Object.prototype, legacyMethods[i], {
|
|
3012
|
+
value: function() { return undefined; },
|
|
3013
|
+
writable: false,
|
|
3014
|
+
configurable: false,
|
|
3015
|
+
enumerable: false
|
|
3016
|
+
});
|
|
3017
|
+
}
|
|
3018
|
+
})();
|
|
3019
|
+
|
|
3020
|
+
// HARDENING 4: Block legacy prototype methods in INNER VM
|
|
3021
|
+
// MUST run before freeze!
|
|
3022
|
+
(function() {
|
|
3023
|
+
var blockLegacyCode =
|
|
3024
|
+
'(function() {' +
|
|
3025
|
+
' var methods = ["__lookupGetter__", "__lookupSetter__", "__defineGetter__", "__defineSetter__"];' +
|
|
3026
|
+
' for (var i = 0; i < methods.length; i++) {' +
|
|
3027
|
+
' Object.defineProperty(Object.prototype, methods[i], {' +
|
|
3028
|
+
' value: function() { return undefined; },' +
|
|
3029
|
+
' writable: false,' +
|
|
3030
|
+
' configurable: false,' +
|
|
3031
|
+
' enumerable: false' +
|
|
3032
|
+
' });' +
|
|
3033
|
+
' }' +
|
|
3034
|
+
'})();';
|
|
3035
|
+
var blockScript = new vm.Script(blockLegacyCode);
|
|
3036
|
+
blockScript.runInContext(innerContext);
|
|
3037
|
+
})();
|
|
3038
|
+
|
|
3039
|
+
// ============================================================
|
|
3040
|
+
// PROTOTYPE FREEZING: Lock in hardening by freezing all prototypes
|
|
3041
|
+
// ============================================================
|
|
2940
3042
|
//
|
|
2941
3043
|
// We freeze prototypes in TWO places:
|
|
2942
3044
|
// 1. PARENT VM prototypes - because SafeObject.prototype = Object.prototype uses parent's prototype
|
|
@@ -2958,6 +3060,8 @@ ${stackTraceHardeningCode}
|
|
|
2958
3060
|
Object.freeze(RangeError.prototype);
|
|
2959
3061
|
Object.freeze(SyntaxError.prototype);
|
|
2960
3062
|
Object.freeze(ReferenceError.prototype);
|
|
3063
|
+
Object.freeze(URIError.prototype);
|
|
3064
|
+
Object.freeze(EvalError.prototype);
|
|
2961
3065
|
Object.freeze(Promise.prototype);
|
|
2962
3066
|
|
|
2963
3067
|
// Freeze INNER VM prototypes (used by literals like '', [], etc.)
|
|
@@ -2975,11 +3079,64 @@ ${stackTraceHardeningCode}
|
|
|
2975
3079
|
'Object.freeze(RangeError.prototype);' +
|
|
2976
3080
|
'Object.freeze(SyntaxError.prototype);' +
|
|
2977
3081
|
'Object.freeze(ReferenceError.prototype);' +
|
|
3082
|
+
'Object.freeze(URIError.prototype);' +
|
|
3083
|
+
'Object.freeze(EvalError.prototype);' +
|
|
2978
3084
|
'Object.freeze(Promise.prototype);';
|
|
2979
3085
|
var freezeScript = new vm.Script(freezeCode);
|
|
2980
3086
|
freezeScript.runInContext(innerContext);
|
|
2981
3087
|
})();
|
|
2982
3088
|
|
|
3089
|
+
// HARDENING 5: Wrap error constructors to freeze instances
|
|
3090
|
+
// V8-generated errors (like stack overflow RangeError) are created internally,
|
|
3091
|
+
// not via the constructor. But wrapping provides defense-in-depth for any
|
|
3092
|
+
// errors that ARE created via constructors.
|
|
3093
|
+
// NOTE: This can run after freeze because it replaces global constructors, not prototype properties
|
|
3094
|
+
(function() {
|
|
3095
|
+
var wrapErrorCode =
|
|
3096
|
+
'(function() {' +
|
|
3097
|
+
' var origError = Error;' +
|
|
3098
|
+
' var origTypeError = TypeError;' +
|
|
3099
|
+
' var origRangeError = RangeError;' +
|
|
3100
|
+
' var origSyntaxError = SyntaxError;' +
|
|
3101
|
+
' var origReferenceError = ReferenceError;' +
|
|
3102
|
+
' var origEvalError = EvalError;' +
|
|
3103
|
+
' var origURIError = URIError;' +
|
|
3104
|
+
' function wrapErrorCtor(OrigCtor, name) {' +
|
|
3105
|
+
' var WrappedCtor = function(msg) {' +
|
|
3106
|
+
' var err;' +
|
|
3107
|
+
' if (new.target) {' +
|
|
3108
|
+
' err = new OrigCtor(msg);' +
|
|
3109
|
+
' } else {' +
|
|
3110
|
+
' err = OrigCtor(msg);' +
|
|
3111
|
+
' }' +
|
|
3112
|
+
' try { Object.freeze(err); } catch (e) {}' +
|
|
3113
|
+
' return err;' +
|
|
3114
|
+
' };' +
|
|
3115
|
+
' WrappedCtor.prototype = OrigCtor.prototype;' +
|
|
3116
|
+
' try { Object.setPrototypeOf(WrappedCtor, OrigCtor); } catch (e) {}' +
|
|
3117
|
+
' try { Object.freeze(WrappedCtor); } catch (e) {}' +
|
|
3118
|
+
' return WrappedCtor;' +
|
|
3119
|
+
' }' +
|
|
3120
|
+
' try { Error = wrapErrorCtor(origError, "Error"); } catch (e) {}' +
|
|
3121
|
+
' try { TypeError = wrapErrorCtor(origTypeError, "TypeError"); } catch (e) {}' +
|
|
3122
|
+
' try { RangeError = wrapErrorCtor(origRangeError, "RangeError"); } catch (e) {}' +
|
|
3123
|
+
' try { SyntaxError = wrapErrorCtor(origSyntaxError, "SyntaxError"); } catch (e) {}' +
|
|
3124
|
+
' try { ReferenceError = wrapErrorCtor(origReferenceError, "ReferenceError"); } catch (e) {}' +
|
|
3125
|
+
' try { EvalError = wrapErrorCtor(origEvalError, "EvalError"); } catch (e) {}' +
|
|
3126
|
+
' try { URIError = wrapErrorCtor(origURIError, "URIError"); } catch (e) {}' +
|
|
3127
|
+
'})();';
|
|
3128
|
+
try {
|
|
3129
|
+
var wrapScript = new vm.Script(wrapErrorCode);
|
|
3130
|
+
wrapScript.runInContext(innerContext);
|
|
3131
|
+
} catch (e) { /* ignore */ }
|
|
3132
|
+
})();
|
|
3133
|
+
|
|
3134
|
+
// NOTE: HARDENING 6 and 7 (Object.getPrototypeOf / Reflect.getPrototypeOf wrappers)
|
|
3135
|
+
// were removed as they break legitimate internal functionality like __safe_template.
|
|
3136
|
+
// The existing defenses (prototype freezing, __proto__ shadowing, error constructor
|
|
3137
|
+
// wrapping, codeGeneration.strings=false) provide sufficient protection against
|
|
3138
|
+
// the CVE-2023-29017 attack pattern.
|
|
3139
|
+
|
|
2983
3140
|
// Inject safe runtime functions (non-writable, non-configurable)
|
|
2984
3141
|
// Wrap with secure proxy to block dangerous property access
|
|
2985
3142
|
var safeRuntime = {
|
|
@@ -3164,6 +3321,47 @@ ${stackTraceHardeningCode}
|
|
|
3164
3321
|
// Execute User Code
|
|
3165
3322
|
// ============================================================
|
|
3166
3323
|
|
|
3324
|
+
// HARDENING 4: Runtime prototype verification before user code execution
|
|
3325
|
+
// Verifies that critical prototypes are still frozen. If any have been
|
|
3326
|
+
// unfrozen (which shouldn't be possible but defense-in-depth), abort.
|
|
3327
|
+
(function() {
|
|
3328
|
+
var criticalPrototypes = [
|
|
3329
|
+
{ name: 'Object.prototype', proto: Object.prototype },
|
|
3330
|
+
{ name: 'Array.prototype', proto: Array.prototype },
|
|
3331
|
+
{ name: 'Function.prototype', proto: Function.prototype },
|
|
3332
|
+
{ name: 'Error.prototype', proto: Error.prototype },
|
|
3333
|
+
{ name: 'RangeError.prototype', proto: RangeError.prototype }
|
|
3334
|
+
];
|
|
3335
|
+
for (var i = 0; i < criticalPrototypes.length; i++) {
|
|
3336
|
+
var item = criticalPrototypes[i];
|
|
3337
|
+
if (!Object.isFrozen(item.proto)) {
|
|
3338
|
+
throw new Error('SECURITY VIOLATION: ' + item.name + ' is not frozen. Aborting execution.');
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
})();
|
|
3342
|
+
|
|
3343
|
+
// HARDENING 5: Runtime verification in INNER VM
|
|
3344
|
+
(function() {
|
|
3345
|
+
var verifyCode =
|
|
3346
|
+
'(function() {' +
|
|
3347
|
+
' var protos = [Object.prototype, Array.prototype, Error.prototype, RangeError.prototype];' +
|
|
3348
|
+
' for (var i = 0; i < protos.length; i++) {' +
|
|
3349
|
+
' if (!Object.isFrozen(protos[i])) {' +
|
|
3350
|
+
' throw new Error("SECURITY VIOLATION: Inner VM prototype not frozen");' +
|
|
3351
|
+
' }' +
|
|
3352
|
+
' }' +
|
|
3353
|
+
'})();';
|
|
3354
|
+
try {
|
|
3355
|
+
var verifyScript = new vm.Script(verifyCode);
|
|
3356
|
+
verifyScript.runInContext(innerContext);
|
|
3357
|
+
} catch (e) {
|
|
3358
|
+
if (e.message && e.message.indexOf('SECURITY VIOLATION') >= 0) {
|
|
3359
|
+
throw e;
|
|
3360
|
+
}
|
|
3361
|
+
/* ignore other errors */
|
|
3362
|
+
}
|
|
3363
|
+
})();
|
|
3364
|
+
|
|
3167
3365
|
var userCode = ${JSON.stringify(userCode)};
|
|
3168
3366
|
// IMPORTANT: For stack overflow errors (RangeError: Maximum call stack size exceeded),
|
|
3169
3367
|
// Node/V8 may ignore Error.prepareStackTrace when it was installed by a different Script
|
|
@@ -3198,7 +3396,7 @@ ${stackTraceHardeningCode}
|
|
|
3198
3396
|
}
|
|
3199
3397
|
var NODEJS_24_DANGEROUS_GLOBALS;
|
|
3200
3398
|
var init_parent_vm_bootstrap = __esm({
|
|
3201
|
-
"libs/
|
|
3399
|
+
"libs/core/src/double-vm/parent-vm-bootstrap.ts"() {
|
|
3202
3400
|
"use strict";
|
|
3203
3401
|
NODEJS_24_DANGEROUS_GLOBALS = {
|
|
3204
3402
|
STRICT: [
|
|
@@ -3283,7 +3481,7 @@ var init_parent_vm_bootstrap = __esm({
|
|
|
3283
3481
|
}
|
|
3284
3482
|
});
|
|
3285
3483
|
|
|
3286
|
-
// libs/
|
|
3484
|
+
// libs/core/src/double-vm/suspicious-patterns.ts
|
|
3287
3485
|
function serializePattern(pattern) {
|
|
3288
3486
|
if (typeof pattern.detect !== "function") {
|
|
3289
3487
|
throw new Error(`Pattern "${pattern.id}": detect must be a function`);
|
|
@@ -3327,7 +3525,7 @@ function serializePatterns(patterns) {
|
|
|
3327
3525
|
}
|
|
3328
3526
|
var EXFIL_LIST_SEND, RAPID_ENUMERATION, CREDENTIAL_EXFIL, BULK_OPERATION, DELETE_AFTER_ACCESS, DEFAULT_SUSPICIOUS_PATTERNS;
|
|
3329
3527
|
var init_suspicious_patterns = __esm({
|
|
3330
|
-
"libs/
|
|
3528
|
+
"libs/core/src/double-vm/suspicious-patterns.ts"() {
|
|
3331
3529
|
"use strict";
|
|
3332
3530
|
EXFIL_LIST_SEND = {
|
|
3333
3531
|
id: "EXFIL_LIST_SEND",
|
|
@@ -3409,7 +3607,7 @@ var init_suspicious_patterns = __esm({
|
|
|
3409
3607
|
}
|
|
3410
3608
|
});
|
|
3411
3609
|
|
|
3412
|
-
// libs/
|
|
3610
|
+
// libs/core/src/double-vm/double-vm-wrapper.ts
|
|
3413
3611
|
function sanitizeStackTrace(stack, sanitize = true) {
|
|
3414
3612
|
if (!stack || !sanitize) return stack;
|
|
3415
3613
|
let sanitized = stack;
|
|
@@ -3441,7 +3639,7 @@ function sanitizeStackTrace(stack, sanitize = true) {
|
|
|
3441
3639
|
}
|
|
3442
3640
|
var vm2, SENSITIVE_STACK_PATTERNS, DoubleVmWrapper;
|
|
3443
3641
|
var init_double_vm_wrapper = __esm({
|
|
3444
|
-
"libs/
|
|
3642
|
+
"libs/core/src/double-vm/double-vm-wrapper.ts"() {
|
|
3445
3643
|
"use strict";
|
|
3446
3644
|
vm2 = __toESM(require("vm"));
|
|
3447
3645
|
init_value_sanitizer();
|
|
@@ -3836,7 +4034,7 @@ var init_double_vm_wrapper = __esm({
|
|
|
3836
4034
|
}
|
|
3837
4035
|
});
|
|
3838
4036
|
|
|
3839
|
-
// libs/
|
|
4037
|
+
// libs/core/src/double-vm/wrap-adapter.ts
|
|
3840
4038
|
function wrapWithDoubleVm(baseAdapter, config, securityLevel) {
|
|
3841
4039
|
if (!config.enabled) {
|
|
3842
4040
|
if (!baseAdapter) {
|
|
@@ -3855,13 +4053,13 @@ function isDoubleVmEnabled(config) {
|
|
|
3855
4053
|
return config?.enabled !== false;
|
|
3856
4054
|
}
|
|
3857
4055
|
var init_wrap_adapter = __esm({
|
|
3858
|
-
"libs/
|
|
4056
|
+
"libs/core/src/double-vm/wrap-adapter.ts"() {
|
|
3859
4057
|
"use strict";
|
|
3860
4058
|
init_double_vm_wrapper();
|
|
3861
4059
|
}
|
|
3862
4060
|
});
|
|
3863
4061
|
|
|
3864
|
-
// libs/
|
|
4062
|
+
// libs/core/src/double-vm/index.ts
|
|
3865
4063
|
var double_vm_exports = {};
|
|
3866
4064
|
__export(double_vm_exports, {
|
|
3867
4065
|
DEFAULT_SUSPICIOUS_PATTERNS: () => DEFAULT_SUSPICIOUS_PATTERNS,
|
|
@@ -3873,7 +4071,7 @@ __export(double_vm_exports, {
|
|
|
3873
4071
|
wrapWithDoubleVm: () => wrapWithDoubleVm
|
|
3874
4072
|
});
|
|
3875
4073
|
var init_double_vm = __esm({
|
|
3876
|
-
"libs/
|
|
4074
|
+
"libs/core/src/double-vm/index.ts"() {
|
|
3877
4075
|
"use strict";
|
|
3878
4076
|
init_double_vm_wrapper();
|
|
3879
4077
|
init_wrap_adapter();
|
|
@@ -3882,7 +4080,7 @@ var init_double_vm = __esm({
|
|
|
3882
4080
|
}
|
|
3883
4081
|
});
|
|
3884
4082
|
|
|
3885
|
-
// libs/
|
|
4083
|
+
// libs/core/src/memory-proxy.ts
|
|
3886
4084
|
function createTrackedString(tracker) {
|
|
3887
4085
|
return new Proxy(String, {
|
|
3888
4086
|
apply(target, thisArg, args) {
|
|
@@ -3975,13 +4173,13 @@ function createTrackedArray(tracker) {
|
|
|
3975
4173
|
return TrackedArray;
|
|
3976
4174
|
}
|
|
3977
4175
|
var init_memory_proxy = __esm({
|
|
3978
|
-
"libs/
|
|
4176
|
+
"libs/core/src/memory-proxy.ts"() {
|
|
3979
4177
|
"use strict";
|
|
3980
4178
|
init_memory_tracker();
|
|
3981
4179
|
}
|
|
3982
4180
|
});
|
|
3983
4181
|
|
|
3984
|
-
// libs/
|
|
4182
|
+
// libs/core/src/safe-runtime.ts
|
|
3985
4183
|
function createSafeRuntime(context, options) {
|
|
3986
4184
|
const { config, stats } = context;
|
|
3987
4185
|
const sidecar = options?.sidecar;
|
|
@@ -4464,7 +4662,7 @@ function serializeSafeRuntime() {
|
|
|
4464
4662
|
`.trim();
|
|
4465
4663
|
}
|
|
4466
4664
|
var init_safe_runtime = __esm({
|
|
4467
|
-
"libs/
|
|
4665
|
+
"libs/core/src/safe-runtime.ts"() {
|
|
4468
4666
|
"use strict";
|
|
4469
4667
|
init_value_sanitizer();
|
|
4470
4668
|
init_safe_error();
|
|
@@ -4475,7 +4673,7 @@ var init_safe_runtime = __esm({
|
|
|
4475
4673
|
}
|
|
4476
4674
|
});
|
|
4477
4675
|
|
|
4478
|
-
// libs/
|
|
4676
|
+
// libs/core/src/adapters/vm-adapter.ts
|
|
4479
4677
|
var vm_adapter_exports = {};
|
|
4480
4678
|
__export(vm_adapter_exports, {
|
|
4481
4679
|
VmAdapter: () => VmAdapter
|
|
@@ -4675,7 +4873,7 @@ function sanitizeVmContext(context, securityLevel) {
|
|
|
4675
4873
|
}
|
|
4676
4874
|
var vm3, 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;
|
|
4677
4875
|
var init_vm_adapter = __esm({
|
|
4678
|
-
"libs/
|
|
4876
|
+
"libs/core/src/adapters/vm-adapter.ts"() {
|
|
4679
4877
|
"use strict";
|
|
4680
4878
|
vm3 = __toESM(require("vm"));
|
|
4681
4879
|
init_safe_runtime();
|
|
@@ -5373,12 +5571,7 @@ var init_vm_adapter = __esm({
|
|
|
5373
5571
|
}
|
|
5374
5572
|
const _protectedSandbox = createProtectedSandbox(baseSandbox);
|
|
5375
5573
|
this.context = baseSandbox;
|
|
5376
|
-
const wrappedCode =
|
|
5377
|
-
(async () => {
|
|
5378
|
-
${code}
|
|
5379
|
-
return typeof __ag_main === 'function' ? await __ag_main() : undefined;
|
|
5380
|
-
})();
|
|
5381
|
-
`;
|
|
5574
|
+
const wrappedCode = "(async () => {\n" + code + '\nreturn typeof __ag_main === "function" ? await __ag_main() : undefined;\n})();';
|
|
5382
5575
|
const script = new vm3.Script(wrappedCode, {
|
|
5383
5576
|
filename: "agentscript.js"
|
|
5384
5577
|
});
|
|
@@ -5481,7 +5674,7 @@ var init_vm_adapter = __esm({
|
|
|
5481
5674
|
}
|
|
5482
5675
|
});
|
|
5483
5676
|
|
|
5484
|
-
// libs/
|
|
5677
|
+
// libs/core/src/adapters/worker-pool/config.ts
|
|
5485
5678
|
function buildWorkerPoolConfig(securityLevel, overrides) {
|
|
5486
5679
|
const preset = WORKER_POOL_PRESETS[securityLevel];
|
|
5487
5680
|
return {
|
|
@@ -5492,7 +5685,7 @@ function buildWorkerPoolConfig(securityLevel, overrides) {
|
|
|
5492
5685
|
}
|
|
5493
5686
|
var import_os, DEFAULT_WORKER_POOL_CONFIG, WORKER_POOL_PRESETS;
|
|
5494
5687
|
var init_config = __esm({
|
|
5495
|
-
"libs/
|
|
5688
|
+
"libs/core/src/adapters/worker-pool/config.ts"() {
|
|
5496
5689
|
"use strict";
|
|
5497
5690
|
import_os = __toESM(require("os"));
|
|
5498
5691
|
DEFAULT_WORKER_POOL_CONFIG = {
|
|
@@ -5606,7 +5799,7 @@ var init_config = __esm({
|
|
|
5606
5799
|
}
|
|
5607
5800
|
});
|
|
5608
5801
|
|
|
5609
|
-
// libs/
|
|
5802
|
+
// libs/core/src/adapters/worker-pool/protocol.ts
|
|
5610
5803
|
function isToolCallMessage(msg) {
|
|
5611
5804
|
return msg.type === "tool-call";
|
|
5612
5805
|
}
|
|
@@ -5618,7 +5811,7 @@ function isConsoleMessage(msg) {
|
|
|
5618
5811
|
}
|
|
5619
5812
|
var import_zod, TOOL_NAME_PATTERN, ID_PATTERN, toolCallMessageSchema, executionResultMessageSchema, memoryReportResultMessageSchema, consoleMessageSchema, workerReadyMessageSchema, workerToMainMessageSchema;
|
|
5620
5813
|
var init_protocol = __esm({
|
|
5621
|
-
"libs/
|
|
5814
|
+
"libs/core/src/adapters/worker-pool/protocol.ts"() {
|
|
5622
5815
|
"use strict";
|
|
5623
5816
|
import_zod = require("zod");
|
|
5624
5817
|
TOOL_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9:_-]*$/;
|
|
@@ -5678,10 +5871,10 @@ var init_protocol = __esm({
|
|
|
5678
5871
|
}
|
|
5679
5872
|
});
|
|
5680
5873
|
|
|
5681
|
-
// libs/
|
|
5874
|
+
// libs/core/src/adapters/worker-pool/errors.ts
|
|
5682
5875
|
var WorkerPoolError, WorkerTimeoutError, WorkerMemoryError, WorkerCrashedError, WorkerPoolDisposedError, QueueFullError, QueueTimeoutError, ExecutionAbortedError, MessageFloodError, MessageValidationError, MessageSizeError, WorkerStartupError, TooManyPendingCallsError;
|
|
5683
5876
|
var init_errors = __esm({
|
|
5684
|
-
"libs/
|
|
5877
|
+
"libs/core/src/adapters/worker-pool/errors.ts"() {
|
|
5685
5878
|
"use strict";
|
|
5686
5879
|
WorkerPoolError = class extends Error {
|
|
5687
5880
|
constructor(message) {
|
|
@@ -5807,7 +6000,7 @@ var init_errors = __esm({
|
|
|
5807
6000
|
}
|
|
5808
6001
|
});
|
|
5809
6002
|
|
|
5810
|
-
// libs/
|
|
6003
|
+
// libs/core/src/adapters/worker-pool/safe-deserialize.ts
|
|
5811
6004
|
function safeDeserialize(raw, maxSizeBytes) {
|
|
5812
6005
|
if (maxSizeBytes !== void 0) {
|
|
5813
6006
|
const byteLength = Buffer.byteLength(raw, "utf-8");
|
|
@@ -5877,7 +6070,7 @@ function sanitizeObject(value, depth = 0) {
|
|
|
5877
6070
|
}
|
|
5878
6071
|
var DANGEROUS_KEYS2, MAX_DEPTH;
|
|
5879
6072
|
var init_safe_deserialize = __esm({
|
|
5880
|
-
"libs/
|
|
6073
|
+
"libs/core/src/adapters/worker-pool/safe-deserialize.ts"() {
|
|
5881
6074
|
"use strict";
|
|
5882
6075
|
init_errors();
|
|
5883
6076
|
DANGEROUS_KEYS2 = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
@@ -5885,10 +6078,10 @@ var init_safe_deserialize = __esm({
|
|
|
5885
6078
|
}
|
|
5886
6079
|
});
|
|
5887
6080
|
|
|
5888
|
-
// libs/
|
|
6081
|
+
// libs/core/src/adapters/worker-pool/worker-slot.ts
|
|
5889
6082
|
var import_worker_threads, import_path, import_events, WorkerSlot;
|
|
5890
6083
|
var init_worker_slot = __esm({
|
|
5891
|
-
"libs/
|
|
6084
|
+
"libs/core/src/adapters/worker-pool/worker-slot.ts"() {
|
|
5892
6085
|
"use strict";
|
|
5893
6086
|
import_worker_threads = require("worker_threads");
|
|
5894
6087
|
import_path = __toESM(require("path"));
|
|
@@ -6157,10 +6350,10 @@ var init_worker_slot = __esm({
|
|
|
6157
6350
|
}
|
|
6158
6351
|
});
|
|
6159
6352
|
|
|
6160
|
-
// libs/
|
|
6353
|
+
// libs/core/src/adapters/worker-pool/execution-queue.ts
|
|
6161
6354
|
var ExecutionQueue;
|
|
6162
6355
|
var init_execution_queue = __esm({
|
|
6163
|
-
"libs/
|
|
6356
|
+
"libs/core/src/adapters/worker-pool/execution-queue.ts"() {
|
|
6164
6357
|
"use strict";
|
|
6165
6358
|
init_errors();
|
|
6166
6359
|
ExecutionQueue = class {
|
|
@@ -6320,10 +6513,10 @@ var init_execution_queue = __esm({
|
|
|
6320
6513
|
}
|
|
6321
6514
|
});
|
|
6322
6515
|
|
|
6323
|
-
// libs/
|
|
6516
|
+
// libs/core/src/adapters/worker-pool/memory-monitor.ts
|
|
6324
6517
|
var import_events2, MemoryMonitor;
|
|
6325
6518
|
var init_memory_monitor = __esm({
|
|
6326
|
-
"libs/
|
|
6519
|
+
"libs/core/src/adapters/worker-pool/memory-monitor.ts"() {
|
|
6327
6520
|
"use strict";
|
|
6328
6521
|
import_events2 = require("events");
|
|
6329
6522
|
MemoryMonitor = class extends import_events2.EventEmitter {
|
|
@@ -6490,7 +6683,7 @@ var init_memory_monitor = __esm({
|
|
|
6490
6683
|
}
|
|
6491
6684
|
});
|
|
6492
6685
|
|
|
6493
|
-
// libs/
|
|
6686
|
+
// libs/core/src/adapters/worker-pool/rate-limiter.ts
|
|
6494
6687
|
function createRateLimiter(maxMessagesPerSecond) {
|
|
6495
6688
|
return new RateLimiter({
|
|
6496
6689
|
maxMessagesPerWindow: maxMessagesPerSecond,
|
|
@@ -6499,7 +6692,7 @@ function createRateLimiter(maxMessagesPerSecond) {
|
|
|
6499
6692
|
}
|
|
6500
6693
|
var RateLimiter;
|
|
6501
6694
|
var init_rate_limiter = __esm({
|
|
6502
|
-
"libs/
|
|
6695
|
+
"libs/core/src/adapters/worker-pool/rate-limiter.ts"() {
|
|
6503
6696
|
"use strict";
|
|
6504
6697
|
init_errors();
|
|
6505
6698
|
RateLimiter = class {
|
|
@@ -6575,10 +6768,10 @@ var init_rate_limiter = __esm({
|
|
|
6575
6768
|
}
|
|
6576
6769
|
});
|
|
6577
6770
|
|
|
6578
|
-
// libs/
|
|
6771
|
+
// libs/core/src/adapters/worker-pool/worker-pool-adapter.ts
|
|
6579
6772
|
var import_crypto3, WorkerPoolAdapter;
|
|
6580
6773
|
var init_worker_pool_adapter = __esm({
|
|
6581
|
-
"libs/
|
|
6774
|
+
"libs/core/src/adapters/worker-pool/worker-pool-adapter.ts"() {
|
|
6582
6775
|
"use strict";
|
|
6583
6776
|
import_crypto3 = __toESM(require("crypto"));
|
|
6584
6777
|
init_config();
|
|
@@ -6598,6 +6791,8 @@ var init_worker_pool_adapter = __esm({
|
|
|
6598
6791
|
rateLimiter;
|
|
6599
6792
|
disposed = false;
|
|
6600
6793
|
initialized = false;
|
|
6794
|
+
// Bound event handler for proper cleanup
|
|
6795
|
+
boundMemoryExceededHandler = this.handleMemoryExceeded.bind(this);
|
|
6601
6796
|
// Metrics
|
|
6602
6797
|
_totalExecutions = 0;
|
|
6603
6798
|
_successfulExecutions = 0;
|
|
@@ -6620,7 +6815,7 @@ var init_worker_pool_adapter = __esm({
|
|
|
6620
6815
|
this.slots
|
|
6621
6816
|
);
|
|
6622
6817
|
this.rateLimiter = createRateLimiter(this.config.maxMessagesPerSecond);
|
|
6623
|
-
this.memoryMonitor.on("memoryExceeded", this.
|
|
6818
|
+
this.memoryMonitor.on("memoryExceeded", this.boundMemoryExceededHandler);
|
|
6624
6819
|
}
|
|
6625
6820
|
/**
|
|
6626
6821
|
* Initialize the worker pool
|
|
@@ -6685,6 +6880,7 @@ var init_worker_pool_adapter = __esm({
|
|
|
6685
6880
|
return;
|
|
6686
6881
|
}
|
|
6687
6882
|
this.disposed = true;
|
|
6883
|
+
this.memoryMonitor.off("memoryExceeded", this.boundMemoryExceededHandler);
|
|
6688
6884
|
this.memoryMonitor.stop();
|
|
6689
6885
|
this.executionQueue.clear();
|
|
6690
6886
|
const terminatePromises = [];
|
|
@@ -7011,7 +7207,7 @@ var init_worker_pool_adapter = __esm({
|
|
|
7011
7207
|
}
|
|
7012
7208
|
});
|
|
7013
7209
|
|
|
7014
|
-
// libs/
|
|
7210
|
+
// libs/core/src/adapters/worker-pool/index.ts
|
|
7015
7211
|
var worker_pool_exports = {};
|
|
7016
7212
|
__export(worker_pool_exports, {
|
|
7017
7213
|
DEFAULT_WORKER_POOL_CONFIG: () => DEFAULT_WORKER_POOL_CONFIG,
|
|
@@ -7041,7 +7237,7 @@ __export(worker_pool_exports, {
|
|
|
7041
7237
|
sanitizeObject: () => sanitizeObject
|
|
7042
7238
|
});
|
|
7043
7239
|
var init_worker_pool = __esm({
|
|
7044
|
-
"libs/
|
|
7240
|
+
"libs/core/src/adapters/worker-pool/index.ts"() {
|
|
7045
7241
|
"use strict";
|
|
7046
7242
|
init_worker_pool_adapter();
|
|
7047
7243
|
init_config();
|
|
@@ -7054,7 +7250,7 @@ var init_worker_pool = __esm({
|
|
|
7054
7250
|
}
|
|
7055
7251
|
});
|
|
7056
7252
|
|
|
7057
|
-
// libs/
|
|
7253
|
+
// libs/core/src/index.ts
|
|
7058
7254
|
var index_exports = {};
|
|
7059
7255
|
__export(index_exports, {
|
|
7060
7256
|
BLOCKED_PROPERTY_CATEGORIES: () => BLOCKED_PROPERTY_CATEGORIES,
|
|
@@ -7137,10 +7333,10 @@ __export(index_exports, {
|
|
|
7137
7333
|
});
|
|
7138
7334
|
module.exports = __toCommonJS(index_exports);
|
|
7139
7335
|
|
|
7140
|
-
// libs/
|
|
7336
|
+
// libs/core/src/enclave.ts
|
|
7141
7337
|
var import_ast3 = require("@enclave-vm/ast");
|
|
7142
7338
|
|
|
7143
|
-
// libs/
|
|
7339
|
+
// libs/core/src/babel/babel-wrapper.ts
|
|
7144
7340
|
var vm = __toESM(require("vm"));
|
|
7145
7341
|
var BabelStandalone = __toESM(require("@babel/standalone"));
|
|
7146
7342
|
var import_ast = require("@enclave-vm/ast");
|
|
@@ -7418,7 +7614,7 @@ function getAvailableBabelPresets() {
|
|
|
7418
7614
|
return ["env", "react", "typescript", "flow"];
|
|
7419
7615
|
}
|
|
7420
7616
|
|
|
7421
|
-
// libs/
|
|
7617
|
+
// libs/core/src/babel/multi-file-transform.ts
|
|
7422
7618
|
var import_ast2 = require("@enclave-vm/ast");
|
|
7423
7619
|
var VALID_FILENAME_REGEX = /^[a-zA-Z0-9_\-./]+\.(ts|tsx|js|jsx|mjs|cjs|mts|cts)$/;
|
|
7424
7620
|
var EXTENSION_MAP = {
|
|
@@ -7640,13 +7836,13 @@ function transformMultiple(files, options, limits, singleFileTransform) {
|
|
|
7640
7836
|
};
|
|
7641
7837
|
}
|
|
7642
7838
|
|
|
7643
|
-
// libs/
|
|
7839
|
+
// libs/core/src/enclave.ts
|
|
7644
7840
|
var import_ast4 = require("@enclave-vm/ast");
|
|
7645
7841
|
var import_ast5 = require("@enclave-vm/ast");
|
|
7646
7842
|
var acorn2 = __toESM(require("acorn"));
|
|
7647
7843
|
var import_astring = require("astring");
|
|
7648
7844
|
|
|
7649
|
-
// libs/
|
|
7845
|
+
// libs/core/src/types.ts
|
|
7650
7846
|
var SECURITY_LEVEL_CONFIGS = {
|
|
7651
7847
|
/**
|
|
7652
7848
|
* STRICT: Maximum security for untrusted code
|
|
@@ -7823,7 +8019,7 @@ var DEFAULT_DOUBLE_VM_CONFIG = {
|
|
|
7823
8019
|
}
|
|
7824
8020
|
};
|
|
7825
8021
|
|
|
7826
|
-
// libs/
|
|
8022
|
+
// libs/core/src/globals-validator.ts
|
|
7827
8023
|
var DANGEROUS_FUNCTION_PATTERNS = [
|
|
7828
8024
|
/\beval\b/,
|
|
7829
8025
|
// eval() calls
|
|
@@ -7941,10 +8137,10 @@ function validateGlobals(globals, options = {}) {
|
|
|
7941
8137
|
}
|
|
7942
8138
|
}
|
|
7943
8139
|
|
|
7944
|
-
// libs/
|
|
8140
|
+
// libs/core/src/sidecar/index.ts
|
|
7945
8141
|
init_reference_config();
|
|
7946
8142
|
|
|
7947
|
-
// libs/
|
|
8143
|
+
// libs/core/src/sidecar/reference-sidecar.ts
|
|
7948
8144
|
var import_crypto = require("crypto");
|
|
7949
8145
|
init_reference_config();
|
|
7950
8146
|
var SidecarLimitError = class _SidecarLimitError extends Error {
|
|
@@ -8132,15 +8328,15 @@ var ReferenceSidecar = class {
|
|
|
8132
8328
|
}
|
|
8133
8329
|
};
|
|
8134
8330
|
|
|
8135
|
-
// libs/
|
|
8331
|
+
// libs/core/src/sidecar/index.ts
|
|
8136
8332
|
init_reference_resolver();
|
|
8137
8333
|
|
|
8138
|
-
// libs/
|
|
8334
|
+
// libs/core/src/scoring/feature-extractor.ts
|
|
8139
8335
|
var acorn = __toESM(require("acorn"));
|
|
8140
8336
|
var walk = __toESM(require("acorn-walk"));
|
|
8141
8337
|
var import_crypto2 = require("crypto");
|
|
8142
8338
|
|
|
8143
|
-
// libs/
|
|
8339
|
+
// libs/core/src/scoring/types.ts
|
|
8144
8340
|
var DEFAULT_PROGRESSIVE_CONFIG = {
|
|
8145
8341
|
escalationThreshold: 30,
|
|
8146
8342
|
combination: "max"
|
|
@@ -8214,7 +8410,7 @@ var RULE_THRESHOLDS = {
|
|
|
8214
8410
|
HIGH_FAN_OUT: 3
|
|
8215
8411
|
};
|
|
8216
8412
|
|
|
8217
|
-
// libs/
|
|
8413
|
+
// libs/core/src/scoring/feature-extractor.ts
|
|
8218
8414
|
var SENSITIVE_PATTERNS = {
|
|
8219
8415
|
authentication: /password|token|secret|api.?key|auth|credential|bearer/i,
|
|
8220
8416
|
pii: /email|ssn|phone|address|credit.?card|birth.?date|social.?security/i,
|
|
@@ -8516,7 +8712,7 @@ var FeatureExtractor = class {
|
|
|
8516
8712
|
}
|
|
8517
8713
|
};
|
|
8518
8714
|
|
|
8519
|
-
// libs/
|
|
8715
|
+
// libs/core/src/scoring/cache.ts
|
|
8520
8716
|
var ScoringCache = class {
|
|
8521
8717
|
cache;
|
|
8522
8718
|
config;
|
|
@@ -8653,7 +8849,7 @@ var ScoringCache = class {
|
|
|
8653
8849
|
}
|
|
8654
8850
|
};
|
|
8655
8851
|
|
|
8656
|
-
// libs/
|
|
8852
|
+
// libs/core/src/scoring/scorer.interface.ts
|
|
8657
8853
|
var BaseScorer = class {
|
|
8658
8854
|
ready = false;
|
|
8659
8855
|
async initialize() {
|
|
@@ -8683,7 +8879,7 @@ var BaseScorer = class {
|
|
|
8683
8879
|
}
|
|
8684
8880
|
};
|
|
8685
8881
|
|
|
8686
|
-
// libs/
|
|
8882
|
+
// libs/core/src/scoring/scorers/disabled.scorer.ts
|
|
8687
8883
|
var DisabledScorer = class extends BaseScorer {
|
|
8688
8884
|
type = "disabled";
|
|
8689
8885
|
name = "DisabledScorer";
|
|
@@ -8702,7 +8898,7 @@ var DisabledScorer = class extends BaseScorer {
|
|
|
8702
8898
|
}
|
|
8703
8899
|
};
|
|
8704
8900
|
|
|
8705
|
-
// libs/
|
|
8901
|
+
// libs/core/src/scoring/scorers/rule-based.scorer.ts
|
|
8706
8902
|
var RULE_SCORES = {
|
|
8707
8903
|
SENSITIVE_FIELD: 35,
|
|
8708
8904
|
// Base score for sensitive field access
|
|
@@ -8964,7 +9160,7 @@ var RuleBasedScorer = class extends BaseScorer {
|
|
|
8964
9160
|
}
|
|
8965
9161
|
};
|
|
8966
9162
|
|
|
8967
|
-
// libs/
|
|
9163
|
+
// libs/core/src/scoring/scorers/external-api.scorer.ts
|
|
8968
9164
|
var VALID_RISK_LEVELS = ["none", "low", "medium", "high", "critical"];
|
|
8969
9165
|
var ExternalApiScorer = class extends BaseScorer {
|
|
8970
9166
|
type = "external-api";
|
|
@@ -9077,7 +9273,7 @@ var ExternalApiScorerError = class extends Error {
|
|
|
9077
9273
|
}
|
|
9078
9274
|
};
|
|
9079
9275
|
|
|
9080
|
-
// libs/
|
|
9276
|
+
// libs/core/src/scoring/scorers/local-llm.scorer.ts
|
|
9081
9277
|
var import_node_os = require("node:os");
|
|
9082
9278
|
var import_node_path = require("node:path");
|
|
9083
9279
|
var LEGACY_DEFAULT_CACHE_DIR = "./.cache/transformers";
|
|
@@ -9465,7 +9661,7 @@ var LocalLlmScorerError = class extends Error {
|
|
|
9465
9661
|
}
|
|
9466
9662
|
};
|
|
9467
9663
|
|
|
9468
|
-
// libs/
|
|
9664
|
+
// libs/core/src/scoring/scorers/progressive.scorer.ts
|
|
9469
9665
|
var ProgressiveScorer = class extends BaseScorer {
|
|
9470
9666
|
type = "progressive";
|
|
9471
9667
|
name = "ProgressiveScorer";
|
|
@@ -9614,7 +9810,7 @@ var ProgressiveScorer = class extends BaseScorer {
|
|
|
9614
9810
|
}
|
|
9615
9811
|
};
|
|
9616
9812
|
|
|
9617
|
-
// libs/
|
|
9813
|
+
// libs/core/src/scoring/scoring-gate.ts
|
|
9618
9814
|
var ScoringGate = class {
|
|
9619
9815
|
extractor;
|
|
9620
9816
|
config;
|
|
@@ -9819,7 +10015,7 @@ function createScoringGate(config) {
|
|
|
9819
10015
|
return new ScoringGate(config);
|
|
9820
10016
|
}
|
|
9821
10017
|
|
|
9822
|
-
// libs/
|
|
10018
|
+
// libs/core/src/enclave.ts
|
|
9823
10019
|
var DEFAULT_SECURITY_LEVEL = "STANDARD";
|
|
9824
10020
|
var DEFAULT_TOOL_BRIDGE_MAX_PAYLOAD_BYTES = 5 * 1024 * 1024;
|
|
9825
10021
|
function getConfigFromSecurityLevel(securityLevel, options) {
|
|
@@ -9873,6 +10069,7 @@ var Enclave = class {
|
|
|
9873
10069
|
referenceConfig;
|
|
9874
10070
|
scoringGate;
|
|
9875
10071
|
doubleVmConfig;
|
|
10072
|
+
customGlobalNames;
|
|
9876
10073
|
adapter;
|
|
9877
10074
|
constructor(options = {}) {
|
|
9878
10075
|
this.securityLevel = options.securityLevel ?? DEFAULT_SECURITY_LEVEL;
|
|
@@ -9944,8 +10141,8 @@ var Enclave = class {
|
|
|
9944
10141
|
secureProxyConfig: securityConfig.secureProxyConfig,
|
|
9945
10142
|
globals: initialGlobals
|
|
9946
10143
|
};
|
|
9947
|
-
|
|
9948
|
-
const customAllowedGlobals = customGlobalNames.flatMap((name) => [name, `__safe_${name}`]);
|
|
10144
|
+
this.customGlobalNames = Object.keys(initialGlobals);
|
|
10145
|
+
const customAllowedGlobals = this.customGlobalNames.flatMap((name) => [name, `__safe_${name}`]);
|
|
9949
10146
|
this.validator = this.createValidator(presetName, customAllowedGlobals);
|
|
9950
10147
|
this.validateCode = options.validate !== false;
|
|
9951
10148
|
this.transformCode = options.transform !== false;
|
|
@@ -10009,7 +10206,9 @@ var Enclave = class {
|
|
|
10009
10206
|
transformedCode = (0, import_ast4.transformAgentScript)(code, {
|
|
10010
10207
|
wrapInMain: needsWrapping,
|
|
10011
10208
|
transformCallTool: true,
|
|
10012
|
-
transformLoops: true
|
|
10209
|
+
transformLoops: true,
|
|
10210
|
+
// Pass custom global names so they aren't transformed to __safe_ prefix
|
|
10211
|
+
additionalIdentifiers: this.customGlobalNames
|
|
10013
10212
|
});
|
|
10014
10213
|
}
|
|
10015
10214
|
if (this.validateCode) {
|
|
@@ -10335,16 +10534,16 @@ async function runAgentScript(code, options = {}) {
|
|
|
10335
10534
|
}
|
|
10336
10535
|
}
|
|
10337
10536
|
|
|
10338
|
-
// libs/
|
|
10537
|
+
// libs/core/src/index.ts
|
|
10339
10538
|
init_safe_runtime();
|
|
10340
10539
|
init_secure_proxy();
|
|
10341
10540
|
init_memory_tracker();
|
|
10342
10541
|
init_worker_pool();
|
|
10343
10542
|
|
|
10344
|
-
// libs/
|
|
10543
|
+
// libs/core/src/session/session.ts
|
|
10345
10544
|
var import_types9 = require("@enclave-vm/types");
|
|
10346
10545
|
|
|
10347
|
-
// libs/
|
|
10546
|
+
// libs/core/src/session/session-emitter.ts
|
|
10348
10547
|
var import_types8 = require("@enclave-vm/types");
|
|
10349
10548
|
var SessionEmitter = class {
|
|
10350
10549
|
sessionId;
|
|
@@ -10575,7 +10774,7 @@ function createSessionEmitter(sessionId, options = {}) {
|
|
|
10575
10774
|
});
|
|
10576
10775
|
}
|
|
10577
10776
|
|
|
10578
|
-
// libs/
|
|
10777
|
+
// libs/core/src/session/session-state-machine.ts
|
|
10579
10778
|
var VALID_TRANSITIONS = {
|
|
10580
10779
|
starting: ["running", "failed", "cancelled"],
|
|
10581
10780
|
running: ["waiting_for_tool", "completed", "failed", "cancelled"],
|
|
@@ -10734,7 +10933,7 @@ function createSessionStateMachine(initialState) {
|
|
|
10734
10933
|
return new SessionStateMachine(initialState);
|
|
10735
10934
|
}
|
|
10736
10935
|
|
|
10737
|
-
// libs/
|
|
10936
|
+
// libs/core/src/session/session.ts
|
|
10738
10937
|
var Session = class {
|
|
10739
10938
|
sessionId;
|
|
10740
10939
|
createdAt;
|
|
@@ -11073,7 +11272,7 @@ function createSession(options) {
|
|
|
11073
11272
|
return new Session(options);
|
|
11074
11273
|
}
|
|
11075
11274
|
|
|
11076
|
-
// libs/
|
|
11275
|
+
// libs/core/src/session/channels/embedded-channel.ts
|
|
11077
11276
|
var EmbeddedChannel = class {
|
|
11078
11277
|
_isOpen = true;
|
|
11079
11278
|
eventHandlers;
|
|
@@ -11176,7 +11375,7 @@ function createEmbeddedChannelPair() {
|
|
|
11176
11375
|
};
|
|
11177
11376
|
}
|
|
11178
11377
|
|
|
11179
|
-
// libs/
|
|
11378
|
+
// libs/core/src/session-types.ts
|
|
11180
11379
|
function isSession(obj) {
|
|
11181
11380
|
return typeof obj === "object" && obj !== null && "sessionId" in obj && "state" in obj && "submitToolResult" in obj && typeof obj.submitToolResult === "function";
|
|
11182
11381
|
}
|