@enclave-vm/core 2.15.2 → 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/worker.js CHANGED
@@ -631,6 +631,157 @@ function applyBinary(op, l, r) {
631
631
  }
632
632
  }
633
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
+
634
785
  // libs/core/src/adapters/interpreter-adapter.ts
635
786
  var SAFE_GLOBALS = Object.freeze({ Math, JSON });
636
787
  var DEFAULT_MAX_STEPS = 5e6;
@@ -642,6 +793,7 @@ var InterpreterAdapter = class {
642
793
  async execute(code, context) {
643
794
  const startTime = Date.now();
644
795
  let toolCallCount = 0;
796
+ const sanitizeStacks = context.config.sanitizeStackTraces === true;
645
797
  const maxToolCalls = context.config.maxToolCalls ?? Number.POSITIVE_INFINITY;
646
798
  const toolHandler = context.toolHandler ?? context.config.toolHandler;
647
799
  const __safe_callTool = async (name, args) => {
@@ -658,7 +810,7 @@ var InterpreterAdapter = class {
658
810
  try {
659
811
  program = acorn.parse(code, { ecmaVersion: "latest", sourceType: "script" });
660
812
  } catch (error) {
661
- return this.fail(error, startTime, toolCallCount, 0, "SyntaxError");
813
+ return this.fail(error, startTime, toolCallCount, 0, sanitizeStacks, "SyntaxError");
662
814
  }
663
815
  const timeout = context.config.timeout;
664
816
  const timer = timeout && timeout > 0 ? setTimeout(() => context.abortController.abort(), timeout) : void 0;
@@ -683,6 +835,7 @@ var InterpreterAdapter = class {
683
835
  startTime,
684
836
  toolCallCount,
685
837
  interpreter.stepCount,
838
+ sanitizeStacks,
686
839
  "TimeoutError",
687
840
  "EXECUTION_TIMEOUT"
688
841
  );
@@ -694,7 +847,7 @@ var InterpreterAdapter = class {
694
847
  };
695
848
  } catch (error) {
696
849
  const code2 = error instanceof StepLimitError ? "STEP_LIMIT_EXCEEDED" : void 0;
697
- return this.fail(error, startTime, toolCallCount, interpreter.stepCount, void 0, code2);
850
+ return this.fail(error, startTime, toolCallCount, interpreter.stepCount, sanitizeStacks, void 0, code2);
698
851
  } finally {
699
852
  if (timer) clearTimeout(timer);
700
853
  if (timeoutHandle) clearTimeout(timeoutHandle);
@@ -706,12 +859,13 @@ var InterpreterAdapter = class {
706
859
  const endTime = Date.now();
707
860
  return { duration: endTime - startTime, toolCallCount, iterationCount, startTime, endTime };
708
861
  }
709
- fail(error, startTime, toolCallCount, iterationCount, name, code) {
862
+ fail(error, startTime, toolCallCount, iterationCount, sanitizeStacks, name, code) {
710
863
  const err = error instanceof Error ? error : new Error(String(error));
864
+ const stack = sanitizeStackTrace(err.stack, sanitizeStacks);
711
865
  const execError = {
712
866
  message: err.message,
713
867
  name: name ?? err.name,
714
- ...err.stack ? { stack: err.stack } : {},
868
+ ...stack ? { stack } : {},
715
869
  ...code ? { code } : {}
716
870
  };
717
871
  return { success: false, error: execError, stats: this.stats(startTime, toolCallCount, iterationCount) };