@enclave-vm/core 2.15.1 → 2.15.3
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/README.md +98 -0
- package/adapters/worker-pool/protocol.d.ts +12 -0
- package/double-vm/parent-vm-bootstrap.d.ts +8 -0
- package/enclave.d.ts +13 -0
- package/esm/index.mjs +1270 -387
- package/esm/worker.mjs +163 -5
- package/global-function-gate.d.ts +74 -0
- package/globals-validator.d.ts +8 -1
- package/index.d.ts +1 -1
- package/index.js +1289 -407
- package/package.json +3 -3
- package/safe-error.d.ts +5 -1
- package/safe-runtime.d.ts +13 -2
- package/secure-proxy.d.ts +23 -0
- package/src/adapters/worker-pool/package.json +3 -3
- package/src/adapters/worker-pool/worker-script.js +96 -3
- package/stack-trace.d.ts +38 -0
- package/tool-namespaces.d.ts +38 -0
- package/types.d.ts +117 -2
- package/worker.js +163 -5
package/worker.js
CHANGED
|
@@ -565,7 +565,11 @@ var Interpreter = class {
|
|
|
565
565
|
const obj = value ?? {};
|
|
566
566
|
for (const prop of pattern.properties) {
|
|
567
567
|
if (prop.type === "RestElement") continue;
|
|
568
|
-
|
|
568
|
+
if (prop.computed) throw new InterpreterError("Computed destructuring keys are not allowed");
|
|
569
|
+
let key;
|
|
570
|
+
if (prop.key.type === "Identifier") key = prop.key.name;
|
|
571
|
+
else if (prop.key.type === "Literal") key = String(prop.key.value);
|
|
572
|
+
else throw new InterpreterError("Unsupported destructuring key");
|
|
569
573
|
if (BLOCKED_KEYS.has(key)) throw new InterpreterError(`Forbidden destructured key: ${key}`);
|
|
570
574
|
this.bindPattern(prop.value, obj[key], scope, mutable);
|
|
571
575
|
}
|
|
@@ -627,6 +631,157 @@ function applyBinary(op, l, r) {
|
|
|
627
631
|
}
|
|
628
632
|
}
|
|
629
633
|
|
|
634
|
+
// libs/core/src/stack-trace.ts
|
|
635
|
+
var SENSITIVE_STACK_PATTERNS = [
|
|
636
|
+
// Unix file system paths
|
|
637
|
+
/\/Users\/[^/]+\/[^\s):]*/gi,
|
|
638
|
+
// macOS home directories
|
|
639
|
+
/\/home\/[^/]+\/[^\s):]*/gi,
|
|
640
|
+
// Linux home directories
|
|
641
|
+
/\/var\/[^\s):]*/gi,
|
|
642
|
+
// System var directories
|
|
643
|
+
/\/opt\/[^\s):]*/gi,
|
|
644
|
+
// Optional software
|
|
645
|
+
/\/tmp\/[^\s):]*/gi,
|
|
646
|
+
// Temporary files
|
|
647
|
+
/\/etc\/[^\s):]*/gi,
|
|
648
|
+
// System configuration
|
|
649
|
+
/\/root\/[^\s):]*/gi,
|
|
650
|
+
// Root home directory
|
|
651
|
+
/\/mnt\/[^\s):]*/gi,
|
|
652
|
+
// Mount points
|
|
653
|
+
/\/srv\/[^\s):]*/gi,
|
|
654
|
+
// Service data
|
|
655
|
+
/\/data\/[^\s):]*/gi,
|
|
656
|
+
// Data directories
|
|
657
|
+
/\/app\/[^\s):]*/gi,
|
|
658
|
+
// Application directories
|
|
659
|
+
/\/proc\/[^\s):]*/gi,
|
|
660
|
+
// Process information
|
|
661
|
+
/\/sys\/[^\s):]*/gi,
|
|
662
|
+
// System files
|
|
663
|
+
// Windows paths
|
|
664
|
+
/\\\\[^\s):]*/g,
|
|
665
|
+
// UNC paths
|
|
666
|
+
/[A-Z]:\\[^\s):]+/gi,
|
|
667
|
+
// Windows drive paths
|
|
668
|
+
// URL-based paths
|
|
669
|
+
/file:\/\/[^\s):]+/gi,
|
|
670
|
+
// File URLs
|
|
671
|
+
/webpack:\/\/[^\s):]+/gi,
|
|
672
|
+
// Webpack paths
|
|
673
|
+
/%2F[^\s):]+/gi,
|
|
674
|
+
// URL-encoded paths
|
|
675
|
+
// Package managers and node
|
|
676
|
+
/node_modules\/[^\s):]+/gi,
|
|
677
|
+
// Node modules paths
|
|
678
|
+
/\/nix\/store\/[^\s):]*/gi,
|
|
679
|
+
// Nix store paths
|
|
680
|
+
/\.npm\/[^\s):]*/gi,
|
|
681
|
+
// NPM cache
|
|
682
|
+
/\.yarn\/[^\s):]*/gi,
|
|
683
|
+
// Yarn cache
|
|
684
|
+
/\.pnpm\/[^\s):]*/gi,
|
|
685
|
+
// PNPM cache
|
|
686
|
+
// Container and orchestration
|
|
687
|
+
/\/run\/secrets\/[^\s):]*/gi,
|
|
688
|
+
// Docker/K8s secrets
|
|
689
|
+
/\/var\/run\/[^\s):]*/gi,
|
|
690
|
+
// Runtime directories
|
|
691
|
+
/\/docker\/[^\s):]*/gi,
|
|
692
|
+
// Docker paths
|
|
693
|
+
/\/containers\/[^\s):]*/gi,
|
|
694
|
+
// Container paths
|
|
695
|
+
/\/kubelet\/[^\s):]*/gi,
|
|
696
|
+
// Kubernetes kubelet
|
|
697
|
+
// CI/CD systems
|
|
698
|
+
/\/github\/workspace\/[^\s):]*/gi,
|
|
699
|
+
// GitHub Actions
|
|
700
|
+
/\/runner\/[^\s):]*/gi,
|
|
701
|
+
// GitHub/GitLab runner
|
|
702
|
+
/\/builds\/[^\s):]*/gi,
|
|
703
|
+
// CI builds
|
|
704
|
+
/\/workspace\/[^\s):]*/gi,
|
|
705
|
+
// Generic workspace
|
|
706
|
+
/\/pipeline\/[^\s):]*/gi,
|
|
707
|
+
// CI pipelines
|
|
708
|
+
/\/jenkins\/[^\s):]*/gi,
|
|
709
|
+
// Jenkins
|
|
710
|
+
/\/bamboo\/[^\s):]*/gi,
|
|
711
|
+
// Bamboo
|
|
712
|
+
/\/teamcity\/[^\s):]*/gi,
|
|
713
|
+
// TeamCity
|
|
714
|
+
/\/circleci\/[^\s):]*/gi,
|
|
715
|
+
// CircleCI
|
|
716
|
+
// Cloud providers
|
|
717
|
+
/\/aws\/[^\s):]*/gi,
|
|
718
|
+
// AWS paths
|
|
719
|
+
/\/gcloud\/[^\s):]*/gi,
|
|
720
|
+
// Google Cloud
|
|
721
|
+
/\/azure\/[^\s):]*/gi,
|
|
722
|
+
// Azure paths
|
|
723
|
+
/s3:\/\/[^\s):]+/gi,
|
|
724
|
+
// S3 URIs
|
|
725
|
+
/gs:\/\/[^\s):]+/gi,
|
|
726
|
+
// GCS URIs
|
|
727
|
+
// Secrets and credentials (patterns that might appear in paths or errors)
|
|
728
|
+
/[A-Z0-9]{20,}/g,
|
|
729
|
+
// AWS-style access keys (20+ uppercase chars)
|
|
730
|
+
/sk-[a-zA-Z0-9]{32,}/g,
|
|
731
|
+
// OpenAI/Stripe-style secret keys
|
|
732
|
+
/ghp_[a-zA-Z0-9]{36,}/g,
|
|
733
|
+
// GitHub personal access tokens
|
|
734
|
+
/gho_[a-zA-Z0-9]{36,}/g,
|
|
735
|
+
// GitHub OAuth tokens
|
|
736
|
+
/github_pat_[a-zA-Z0-9_]{22,}/g,
|
|
737
|
+
// GitHub fine-grained tokens
|
|
738
|
+
/xox[baprs]-[a-zA-Z0-9-]+/g,
|
|
739
|
+
// Slack tokens
|
|
740
|
+
/Bearer\s+[a-zA-Z0-9._-]+/gi,
|
|
741
|
+
// Bearer tokens
|
|
742
|
+
/Basic\s+[a-zA-Z0-9+/=]+/gi,
|
|
743
|
+
// Basic auth
|
|
744
|
+
// Internal network info
|
|
745
|
+
/(?:10|172\.(?:1[6-9]|2\d|3[01])|192\.168)\.\d+\.\d+/g,
|
|
746
|
+
// Private IPs
|
|
747
|
+
/[a-z0-9-]+\.internal(?:\.[a-z]+)?/gi,
|
|
748
|
+
// Internal hostnames
|
|
749
|
+
/localhost:\d+/gi,
|
|
750
|
+
// Localhost with port
|
|
751
|
+
/127\.0\.0\.1:\d+/gi,
|
|
752
|
+
// Loopback with port
|
|
753
|
+
// User information
|
|
754
|
+
/\/u\/[^/]+\//gi,
|
|
755
|
+
// User subdirectories
|
|
756
|
+
/~[a-z_][a-z0-9_-]*/gi,
|
|
757
|
+
// Unix user home shorthand
|
|
758
|
+
// Anything else that is still shaped like a location: an absolute path of two or more
|
|
759
|
+
// segments, a URL, or a script location such as `agentscript.js:3` / `index.mjs:10:5`.
|
|
760
|
+
/[a-z][a-z0-9+.-]*:\/\/[^\s)]+/gi,
|
|
761
|
+
// Other URLs (http://host/bundle.js:1:2)
|
|
762
|
+
/(?:\/[\w.@%+-]+){2,}\/?/g,
|
|
763
|
+
// Remaining absolute paths
|
|
764
|
+
/[\w.@-]+\.(?:[cm]?[jt]sx?|json|node|wasm)(?::\d+){1,2}/gi
|
|
765
|
+
// file.ext:line[:column]
|
|
766
|
+
];
|
|
767
|
+
var FRAME_LINE = /^\s*at\s/;
|
|
768
|
+
var MAX_STACK_LENGTH = 16 * 1024;
|
|
769
|
+
var MAX_LINE_LENGTH = 1e3;
|
|
770
|
+
var REDACTED_FRAME = " at [REDACTED]";
|
|
771
|
+
function redactLine(line) {
|
|
772
|
+
let out = line.length > MAX_LINE_LENGTH ? `${line.slice(0, MAX_LINE_LENGTH)}\u2026` : line;
|
|
773
|
+
for (const pattern of SENSITIVE_STACK_PATTERNS) {
|
|
774
|
+
pattern.lastIndex = 0;
|
|
775
|
+
out = out.replace(pattern, "[REDACTED]");
|
|
776
|
+
}
|
|
777
|
+
return out;
|
|
778
|
+
}
|
|
779
|
+
function sanitizeStackTrace(stack, sanitize = true) {
|
|
780
|
+
if (typeof stack !== "string" || !stack || !sanitize) return stack;
|
|
781
|
+
const bounded = stack.length > MAX_STACK_LENGTH ? stack.slice(0, MAX_STACK_LENGTH) : stack;
|
|
782
|
+
return bounded.split("\n").map((line) => FRAME_LINE.test(line) ? REDACTED_FRAME : redactLine(line)).join("\n");
|
|
783
|
+
}
|
|
784
|
+
|
|
630
785
|
// libs/core/src/adapters/interpreter-adapter.ts
|
|
631
786
|
var SAFE_GLOBALS = Object.freeze({ Math, JSON });
|
|
632
787
|
var DEFAULT_MAX_STEPS = 5e6;
|
|
@@ -638,6 +793,7 @@ var InterpreterAdapter = class {
|
|
|
638
793
|
async execute(code, context) {
|
|
639
794
|
const startTime = Date.now();
|
|
640
795
|
let toolCallCount = 0;
|
|
796
|
+
const sanitizeStacks = context.config.sanitizeStackTraces === true;
|
|
641
797
|
const maxToolCalls = context.config.maxToolCalls ?? Number.POSITIVE_INFINITY;
|
|
642
798
|
const toolHandler = context.toolHandler ?? context.config.toolHandler;
|
|
643
799
|
const __safe_callTool = async (name, args) => {
|
|
@@ -654,7 +810,7 @@ var InterpreterAdapter = class {
|
|
|
654
810
|
try {
|
|
655
811
|
program = acorn.parse(code, { ecmaVersion: "latest", sourceType: "script" });
|
|
656
812
|
} catch (error) {
|
|
657
|
-
return this.fail(error, startTime, toolCallCount, 0, "SyntaxError");
|
|
813
|
+
return this.fail(error, startTime, toolCallCount, 0, sanitizeStacks, "SyntaxError");
|
|
658
814
|
}
|
|
659
815
|
const timeout = context.config.timeout;
|
|
660
816
|
const timer = timeout && timeout > 0 ? setTimeout(() => context.abortController.abort(), timeout) : void 0;
|
|
@@ -679,6 +835,7 @@ var InterpreterAdapter = class {
|
|
|
679
835
|
startTime,
|
|
680
836
|
toolCallCount,
|
|
681
837
|
interpreter.stepCount,
|
|
838
|
+
sanitizeStacks,
|
|
682
839
|
"TimeoutError",
|
|
683
840
|
"EXECUTION_TIMEOUT"
|
|
684
841
|
);
|
|
@@ -690,7 +847,7 @@ var InterpreterAdapter = class {
|
|
|
690
847
|
};
|
|
691
848
|
} catch (error) {
|
|
692
849
|
const code2 = error instanceof StepLimitError ? "STEP_LIMIT_EXCEEDED" : void 0;
|
|
693
|
-
return this.fail(error, startTime, toolCallCount, interpreter.stepCount, void 0, code2);
|
|
850
|
+
return this.fail(error, startTime, toolCallCount, interpreter.stepCount, sanitizeStacks, void 0, code2);
|
|
694
851
|
} finally {
|
|
695
852
|
if (timer) clearTimeout(timer);
|
|
696
853
|
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
@@ -702,12 +859,13 @@ var InterpreterAdapter = class {
|
|
|
702
859
|
const endTime = Date.now();
|
|
703
860
|
return { duration: endTime - startTime, toolCallCount, iterationCount, startTime, endTime };
|
|
704
861
|
}
|
|
705
|
-
fail(error, startTime, toolCallCount, iterationCount, name, code) {
|
|
862
|
+
fail(error, startTime, toolCallCount, iterationCount, sanitizeStacks, name, code) {
|
|
706
863
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
864
|
+
const stack = sanitizeStackTrace(err.stack, sanitizeStacks);
|
|
707
865
|
const execError = {
|
|
708
866
|
message: err.message,
|
|
709
867
|
name: name ?? err.name,
|
|
710
|
-
...
|
|
868
|
+
...stack ? { stack } : {},
|
|
711
869
|
...code ? { code } : {}
|
|
712
870
|
};
|
|
713
871
|
return { success: false, error: execError, stats: this.stats(startTime, toolCallCount, iterationCount) };
|