xypriss 9.14.30 → 9.14.33

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/dist/cjs/index.js CHANGED
@@ -9,16 +9,16 @@ var util = require('node:util');
9
9
  var node_url = require('node:url');
10
10
  var node_child_process = require('node:child_process');
11
11
  var fs$1 = require('node:fs');
12
- var tslib_es6_js = require('/home/idevo/Documents/projects/XyPriss/node_modules/.xfpm/vstore/@rollup+plugin-typescript@11.1.6/node_modules/tslib/tslib.es6.js');
13
12
  var net = require('node:net');
14
13
  var node_worker_threads = require('node:worker_threads');
15
14
  var os = require('node:os');
16
15
  var crypto$2 = require('node:crypto');
17
16
  var nehoid = require('nehoid');
17
+ var vm = require('node:vm');
18
18
  var net$1 = require('net');
19
19
  var reliantType = require('reliant-type');
20
20
  var events = require('events');
21
- var vm = require('vm');
21
+ var vm$1 = require('vm');
22
22
  var compression = require('xypriss-compression');
23
23
  var strulink = require('strulink');
24
24
  var promises = require('node:fs/promises');
@@ -50,7 +50,7 @@ var fs__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(fs);
50
50
  var path__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(path$1);
51
51
  var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs$1);
52
52
  var net__namespace = /*#__PURE__*/_interopNamespaceDefault(net);
53
- var vm__namespace = /*#__PURE__*/_interopNamespaceDefault(vm);
53
+ var vm__namespace = /*#__PURE__*/_interopNamespaceDefault(vm$1);
54
54
 
55
55
  /**
56
56
  * Type definitions for Console Interception System
@@ -1826,25 +1826,39 @@ class XessShieldRequiredError extends Error {
1826
1826
  /**
1827
1827
  * Frozen JavaScript Intrinsics (Primordials)
1828
1828
  *
1829
- * Secures string handling and path normalization against prototype pollution attacks
1830
- * targeting String.prototype.includes, String.prototype.replace, String.prototype.startsWith, etc.
1829
+ * Secures string handling, path normalization, JSON serialization, and collections
1830
+ * against prototype pollution and monkey-patching attacks.
1831
1831
  *
1832
1832
  * @internal
1833
1833
  * @see XSA-XESS-015
1834
+ * @see XSA-XESS-020
1835
+ * @see XSA-XESS-021
1836
+ * @see XSA-XESS-022
1834
1837
  */
1835
1838
  const _StringIncludes = Function.prototype.call.bind(String.prototype.includes);
1836
1839
  const _StringReplace = Function.prototype.call.bind(String.prototype.replace);
1837
1840
  const _StringStartsWith = Function.prototype.call.bind(String.prototype.startsWith);
1841
+ const _StringEndsWith = Function.prototype.call.bind(String.prototype.endsWith);
1838
1842
  const _StringSlice = Function.prototype.call.bind(String.prototype.slice);
1839
1843
  const _StringSubstring = Function.prototype.call.bind(String.prototype.substring);
1840
1844
  const _StringIndexOf = Function.prototype.call.bind(String.prototype.indexOf);
1841
1845
  const _StringLastIndexOf = Function.prototype.call.bind(String.prototype.lastIndexOf);
1846
+ const _PathResolve = path.resolve.bind(path);
1847
+ const _PathIsAbsolute = path.isAbsolute.bind(path);
1848
+ const _JSONParse = JSON.parse;
1849
+ const _JSONStringify = JSON.stringify;
1850
+ const _Uint8ArrayFill = Function.prototype.call.bind(Uint8Array.prototype.fill);
1851
+ const _WeakMapGet = Function.prototype.call.bind(WeakMap.prototype.get);
1852
+ const _WeakMapSet = Function.prototype.call.bind(WeakMap.prototype.set);
1853
+ Function.prototype.call.bind(WeakMap.prototype.has);
1854
+ Function.prototype.call.bind(WeakMap.prototype.delete);
1842
1855
  /**
1843
1856
  * Resolved canonical installation directory for the XyPriss engine core.
1844
1857
  * Anchoring this path at module load time eliminates heuristic substring bypasses.
1845
1858
  *
1846
1859
  * @internal
1847
1860
  * @see XSA-XESS-018
1861
+ * @see XSA-XESS-026
1848
1862
  */
1849
1863
  let ENGINE_CORE_DIR = "";
1850
1864
  try {
@@ -1877,17 +1891,25 @@ catch {
1877
1891
  *
1878
1892
  * @see XSA-XESS-015 - Immune to prototype pollution on String.prototype
1879
1893
  * @see XSA-XESS-018 - Heuristic path evaluation hardening anchored on ENGINE_CORE_DIR
1894
+ * @see XSA-XESS-026 - Rejects any node_modules subpath not strictly starting with ENGINE_CORE_DIR
1880
1895
  */
1881
1896
  function isEngineCorePath(filePath) {
1882
1897
  if (!filePath)
1883
1898
  return false;
1884
1899
  const normalizedPath = _StringReplace(filePath, /\\/g, "/");
1900
+ // Any path inside node_modules that is NOT inside our resolved ENGINE_CORE_DIR
1901
+ // is an untrusted third-party package and CANNOT be the engine core.
1902
+ if (_StringIncludes(normalizedPath, "/node_modules/")) {
1903
+ if (ENGINE_CORE_DIR && _StringStartsWith(normalizedPath, ENGINE_CORE_DIR)) {
1904
+ return true;
1905
+ }
1906
+ return false;
1907
+ }
1885
1908
  if (ENGINE_CORE_DIR && _StringStartsWith(normalizedPath, ENGINE_CORE_DIR)) {
1886
1909
  return true;
1887
1910
  }
1888
1911
  if (_StringIncludes(normalizedPath, "/XyPriss/src/") ||
1889
- _StringIncludes(normalizedPath, "/XyPriss/dist/") ||
1890
- _StringIncludes(normalizedPath, "/node_modules/xypriss/")) {
1912
+ _StringIncludes(normalizedPath, "/XyPriss/dist/")) {
1891
1913
  return true;
1892
1914
  }
1893
1915
  return false;
@@ -1899,6 +1921,7 @@ function isEngineCorePath(filePath) {
1899
1921
  *
1900
1922
  * @see XSA-XESS-015
1901
1923
  * @see XSA-XESS-018
1924
+ * @see XSA-XESS-026
1902
1925
  */
1903
1926
  function isCoreFrameworkPath(filePath) {
1904
1927
  if (!filePath)
@@ -2039,13 +2062,18 @@ function isProjectRoot(dir) {
2039
2062
  *
2040
2063
  * @see XSA-XESS-015 - Immune to prototype pollution on String.prototype
2041
2064
  * @see XSA-XESS-018 - Anchored path verification
2065
+ * @see XSA-XESS-020 - Immune to path.resolve / path.isAbsolute monkey-patching
2066
+ * @see XSA-XESS-025 - Rejects synthetic VM / eval script paths
2042
2067
  */
2043
2068
  function identifyProjectRoot(filePath) {
2044
2069
  if (!filePath)
2045
2070
  return undefined;
2046
- if (!path$1.isAbsolute(filePath)) {
2071
+ if (_StringIncludes(filePath, "[vm]") || _StringIncludes(filePath, "[eval]")) {
2072
+ return undefined;
2073
+ }
2074
+ if (!_PathIsAbsolute(filePath)) {
2047
2075
  try {
2048
- filePath = path$1.resolve(filePath);
2076
+ filePath = _PathResolve(filePath);
2049
2077
  }
2050
2078
  catch {
2051
2079
  return undefined;
@@ -2105,11 +2133,29 @@ function normalizeScriptName(rawScript) {
2105
2133
  }
2106
2134
  return rawScript;
2107
2135
  }
2136
+ /**
2137
+ * Checks whether a stack frame belongs to a top-level CLI TypeScript runtime loader (tsx / ts-node).
2138
+ * Strict hierarchy verification prevents nested dependency packages (e.g. evil-pkg/node_modules/tsx)
2139
+ * or arbitrary helper binaries (node_modules/.bin/evil.js) from masquerading as system loaders.
2140
+ *
2141
+ * @internal
2142
+ * @see XSA-XESS-026
2143
+ */
2108
2144
  function isRuntimeLoaderPath(filePath) {
2109
2145
  const norm = _StringReplace(filePath, /\\/g, "/");
2110
- return (_StringIncludes(norm, "/node_modules/tsx/") ||
2146
+ // Nested node_modules (e.g. node_modules/evil-pkg/node_modules/...) is ALWAYS an untrusted dependency!
2147
+ const firstNm = _StringIndexOf(norm, "/node_modules/");
2148
+ const lastNm = _StringLastIndexOf(norm, "/node_modules/");
2149
+ if (firstNm !== lastNm) {
2150
+ return false;
2151
+ }
2152
+ if (_StringIncludes(norm, "/node_modules/tsx/") ||
2111
2153
  _StringIncludes(norm, "/node_modules/ts-node/") ||
2112
- _StringIncludes(norm, "/node_modules/.bin/"));
2154
+ _StringEndsWith(norm, "/node_modules/.bin/tsx") ||
2155
+ _StringEndsWith(norm, "/node_modules/.bin/ts-node")) {
2156
+ return true;
2157
+ }
2158
+ return false;
2113
2159
  }
2114
2160
  /**
2115
2161
  * Captures raw C++ V8/JSC CallSite frames.
@@ -2119,9 +2165,11 @@ function isRuntimeLoaderPath(filePath) {
2119
2165
  * the C++ v8::StackTrace without touching JavaScript prototype methods or `Error.prepareStackTrace`.
2120
2166
  * 2. Falls back to controlled `Error.prepareStackTrace` with frozen `CallSite.prototype` accessors
2121
2167
  * and indexed array iteration, immune to `Array.prototype[Symbol.iterator]` prototype pollution.
2168
+ * 3. Identifies and flags synthetic VM/eval script origins (`[vm]`, `[eval]`).
2122
2169
  *
2123
2170
  * @internal
2124
2171
  * @see XSA-XESS-015
2172
+ * @see XSA-XESS-025
2125
2173
  */
2126
2174
  function captureNativeFrames() {
2127
2175
  const frames = [];
@@ -2141,11 +2189,13 @@ function captureNativeFrames() {
2141
2189
  continue;
2142
2190
  const rawScript = s.scriptName || "";
2143
2191
  const fnName = s.functionName || "";
2192
+ const isSynthetic = !rawScript && (fnName === "eval" || fnName === "anonymous") ||
2193
+ _StringIncludes(rawScript, "[eval]") ||
2194
+ _StringIncludes(rawScript, "[vm]");
2144
2195
  frames[frames.length] = {
2145
2196
  filePath: normalizeScriptName(rawScript),
2146
2197
  fnName,
2147
- isEval: !rawScript &&
2148
- (fnName === "eval" || fnName === "anonymous"),
2198
+ isEval: isSynthetic,
2149
2199
  };
2150
2200
  }
2151
2201
  return frames;
@@ -2196,10 +2246,13 @@ function captureNativeFrames() {
2196
2246
  : typeof site.isEval === "function"
2197
2247
  ? Boolean(site.isEval())
2198
2248
  : false;
2249
+ const isSynthetic = isEval ||
2250
+ _StringIncludes(rawFile, "[eval]") ||
2251
+ _StringIncludes(rawFile, "[vm]");
2199
2252
  frames[frames.length] = {
2200
2253
  filePath: normalizeScriptName(rawFile),
2201
2254
  fnName,
2202
- isEval,
2255
+ isEval: isSynthetic,
2203
2256
  };
2204
2257
  }
2205
2258
  catch {
@@ -2215,6 +2268,7 @@ function captureNativeFrames() {
2215
2268
  *
2216
2269
  * @see XSA-XESS-015 - Immune to prototype pollution on String.prototype
2217
2270
  * @see XSA-XESS-018 - Excludes internal configuration proxies from bypassing caller checks
2271
+ * @see XSA-XESS-025 - Strictly blocks synthetic VM and eval execution frames
2218
2272
  */
2219
2273
  function isImmediateInternalEngineCall() {
2220
2274
  const frames = captureNativeFrames();
@@ -2225,7 +2279,7 @@ function isImmediateInternalEngineCall() {
2225
2279
  }
2226
2280
  if (!filePath)
2227
2281
  continue;
2228
- if (_StringIncludes(filePath, "[eval]")) {
2282
+ if (_StringIncludes(filePath, "[eval]") || _StringIncludes(filePath, "[vm]")) {
2229
2283
  return false;
2230
2284
  }
2231
2285
  if (_StringStartsWith(filePath, "node:") ||
@@ -2264,6 +2318,8 @@ function isImmediateInternalEngineCall() {
2264
2318
  * the attacker's own `node_modules/...` frame remains on the call stack and is detected.
2265
2319
  *
2266
2320
  * @see XSA-XESS-015 - Immune to prototype pollution on String.prototype and CallSite.prototype
2321
+ * @see XSA-XESS-025 - Detects synthetic node:vm and eval script origins
2322
+ * @see XSA-XESS-026 - Prevents direct impersonation of CLI runtime loaders
2267
2323
  */
2268
2324
  function getVerifiedCallerInfo() {
2269
2325
  const frames = captureNativeFrames();
@@ -2271,7 +2327,9 @@ function getVerifiedCallerInfo() {
2271
2327
  let immediateCallerFile = "";
2272
2328
  for (let i = 0; i < frames.length; i++) {
2273
2329
  const { filePath, isEval } = frames[i];
2274
- if (isEval) {
2330
+ if (isEval ||
2331
+ _StringIncludes(filePath, "[eval]") ||
2332
+ _StringIncludes(filePath, "[vm]")) {
2275
2333
  return {
2276
2334
  root: undefined,
2277
2335
  isUntrusted: true,
@@ -2280,13 +2338,6 @@ function getVerifiedCallerInfo() {
2280
2338
  }
2281
2339
  if (!filePath)
2282
2340
  continue;
2283
- if (_StringIncludes(filePath, "[eval]")) {
2284
- return {
2285
- root: undefined,
2286
- isUntrusted: true,
2287
- callerFile: filePath || "<eval>",
2288
- };
2289
- }
2290
2341
  if (_StringStartsWith(filePath, "node:") ||
2291
2342
  _StringStartsWith(filePath, "bun:") ||
2292
2343
  filePath === "native") {
@@ -2296,8 +2347,11 @@ function getVerifiedCallerInfo() {
2296
2347
  if (isEngineCorePath(filePath)) {
2297
2348
  continue;
2298
2349
  }
2299
- // Skip CLI TypeScript loaders (tsx / ts-node) at the bottom of the stack
2300
- if (isRuntimeLoaderPath(filePath)) {
2350
+ // Skip genuine CLI TypeScript loaders (tsx / ts-node) at the bottom of the stack
2351
+ // ONLY if an application caller has already been established above in the call chain.
2352
+ // A loader can never be the direct caller of restricted APIs!
2353
+ // @see XSA-XESS-026
2354
+ if (immediateCallerRoot && isRuntimeLoaderPath(filePath)) {
2301
2355
  continue;
2302
2356
  }
2303
2357
  const root = identifyProjectRoot(filePath);
@@ -2449,6 +2503,23 @@ function verifyPluginContract(pluginRoot, pluginName) {
2449
2503
  * ```
2450
2504
  */
2451
2505
  class ConfigurationManager {
2506
+ /**
2507
+ * @see XSA-XESS-024 Prevents direct access to server configuration object
2508
+ */
2509
+ get config() {
2510
+ const caller = getVerifiedCallerInfo();
2511
+ if (caller.isUntrusted) {
2512
+ return {};
2513
+ }
2514
+ return this._config;
2515
+ }
2516
+ set config(val) {
2517
+ const caller = getVerifiedCallerInfo();
2518
+ if (caller.isUntrusted) {
2519
+ return;
2520
+ }
2521
+ this._config = val;
2522
+ }
2452
2523
  /**
2453
2524
  * Private constructor to enforce singleton pattern
2454
2525
  * Initializes with default configuration
@@ -2456,16 +2527,24 @@ class ConfigurationManager {
2456
2527
  constructor() {
2457
2528
  this.initialized = false;
2458
2529
  // Initialize with default configuration
2459
- this.config = { ...DEFAULT_OPTIONS };
2530
+ this._config = { ...DEFAULT_OPTIONS };
2531
+ }
2532
+ static getOrCreateInstance() {
2533
+ if (!ConfigurationManager.instance) {
2534
+ ConfigurationManager.instance = new ConfigurationManager();
2535
+ }
2536
+ return ConfigurationManager.instance;
2460
2537
  }
2461
2538
  /**
2462
2539
  * Get the singleton instance
2540
+ * @see XSA-XESS-024 Caller validation for ConfigurationManager singleton access
2463
2541
  */
2464
2542
  static getInstance() {
2465
- if (!ConfigurationManager.instance) {
2466
- ConfigurationManager.instance = new ConfigurationManager();
2543
+ const caller = getVerifiedCallerInfo();
2544
+ if (caller.isUntrusted) {
2545
+ return undefined;
2467
2546
  }
2468
- return ConfigurationManager.instance;
2547
+ return ConfigurationManager.getOrCreateInstance();
2469
2548
  }
2470
2549
  /**
2471
2550
  * Set the entire configuration
@@ -2477,11 +2556,11 @@ class ConfigurationManager {
2477
2556
  if (caller.isUntrusted) {
2478
2557
  return;
2479
2558
  }
2480
- const instance = ConfigurationManager.getInstance();
2481
- instance.config = ConfigurationManager.deepMerge({ ...DEFAULT_OPTIONS }, config);
2559
+ const instance = ConfigurationManager.getOrCreateInstance();
2560
+ instance._config = ConfigurationManager.deepMerge({ ...DEFAULT_OPTIONS }, config);
2482
2561
  // Strict validation for XEMS if persistence is enabled
2483
- ConfigurationManager.validateXemsConfig(instance.config);
2484
- ConfigurationManager.validateGeneralConfig(instance.config);
2562
+ ConfigurationManager.validateXemsConfig(instance._config);
2563
+ ConfigurationManager.validateGeneralConfig(instance._config);
2485
2564
  instance.initialized = true;
2486
2565
  }
2487
2566
  /**
@@ -2495,8 +2574,8 @@ class ConfigurationManager {
2495
2574
  if (caller.isUntrusted) {
2496
2575
  return undefined;
2497
2576
  }
2498
- const instance = ConfigurationManager.getInstance();
2499
- return instance.config[key];
2577
+ const instance = ConfigurationManager.getOrCreateInstance();
2578
+ return instance._config[key];
2500
2579
  }
2501
2580
  /**
2502
2581
  * Get the entire configuration object
@@ -2508,8 +2587,8 @@ class ConfigurationManager {
2508
2587
  if (caller.isUntrusted) {
2509
2588
  return {};
2510
2589
  }
2511
- const instance = ConfigurationManager.getInstance();
2512
- return { ...instance.config };
2590
+ const instance = ConfigurationManager.getOrCreateInstance();
2591
+ return { ...instance._config };
2513
2592
  }
2514
2593
  /**
2515
2594
  * Update a specific XyPriss configuration section (deep merge)
@@ -2522,24 +2601,24 @@ class ConfigurationManager {
2522
2601
  if (caller.isUntrusted) {
2523
2602
  return;
2524
2603
  }
2525
- const instance = ConfigurationManager.getInstance();
2526
- const currentValue = instance.config[key];
2604
+ const instance = ConfigurationManager.getOrCreateInstance();
2605
+ const currentValue = instance._config[key];
2527
2606
  // Deep merge the new value with the existing value
2528
2607
  if (typeof currentValue === "object" &&
2529
2608
  currentValue !== null &&
2530
2609
  !Array.isArray(currentValue)) {
2531
- instance.config[key] = {
2610
+ instance._config[key] = {
2532
2611
  ...currentValue,
2533
2612
  ...value,
2534
2613
  };
2535
2614
  }
2536
2615
  else {
2537
2616
  // For non-object values, just replace
2538
- instance.config[key] = value;
2617
+ instance._config[key] = value;
2539
2618
  }
2540
2619
  // Validate XEMS if it was part of the update
2541
2620
  if (key === "server") {
2542
- ConfigurationManager.validateXemsConfig(instance.config);
2621
+ ConfigurationManager.validateXemsConfig(instance._config);
2543
2622
  }
2544
2623
  }
2545
2624
  /**
@@ -2608,17 +2687,21 @@ class ConfigurationManager {
2608
2687
  * @param config - Partial configuration to merge
2609
2688
  */
2610
2689
  static merge(config) {
2611
- const instance = ConfigurationManager.getInstance();
2690
+ const caller = getVerifiedCallerInfo();
2691
+ if (caller.isUntrusted) {
2692
+ return;
2693
+ }
2694
+ const instance = ConfigurationManager.getOrCreateInstance();
2612
2695
  // Check if the incoming config is marked as immutable
2613
2696
  const shouldBeImmutable = config?.__isXyPrissImmutable;
2614
- instance.config = ConfigurationManager.deepMerge(instance.config, config);
2697
+ instance._config = ConfigurationManager.deepMerge(instance._config, config);
2615
2698
  // Strict validation for XEMS
2616
- ConfigurationManager.validateXemsConfig(instance.config);
2617
- ConfigurationManager.validateGeneralConfig(instance.config);
2699
+ ConfigurationManager.validateXemsConfig(instance._config);
2700
+ ConfigurationManager.validateGeneralConfig(instance._config);
2618
2701
  // If it should be immutable, wrap it using the global __const__.vars.make
2619
2702
  if (shouldBeImmutable &&
2620
2703
  typeof globalThis.__const__ !== "undefined") {
2621
- instance.config = globalThis.__const__.vars.make(instance.config, "Configs");
2704
+ instance._config = globalThis.__const__.vars.make(instance._config, "Configs");
2622
2705
  }
2623
2706
  instance.initialized = true;
2624
2707
  }
@@ -2627,7 +2710,7 @@ class ConfigurationManager {
2627
2710
  * @returns true if configuration has been set, false otherwise
2628
2711
  */
2629
2712
  static isInitialized() {
2630
- const instance = ConfigurationManager.getInstance();
2713
+ const instance = ConfigurationManager.getOrCreateInstance();
2631
2714
  return instance.initialized;
2632
2715
  }
2633
2716
  /**
@@ -2635,36 +2718,54 @@ class ConfigurationManager {
2635
2718
  * Useful for testing or reinitializing
2636
2719
  */
2637
2720
  static reset() {
2638
- const instance = ConfigurationManager.getInstance();
2639
- instance.config = { ...DEFAULT_OPTIONS };
2721
+ const caller = getVerifiedCallerInfo();
2722
+ if (caller.isUntrusted) {
2723
+ return;
2724
+ }
2725
+ const instance = ConfigurationManager.getOrCreateInstance();
2726
+ instance._config = { ...DEFAULT_OPTIONS };
2640
2727
  instance.initialized = false;
2641
2728
  }
2642
2729
  /**
2643
2730
  * Check if a specific configuration section exists
2731
+ * @see XSA-XESS-024 Caller validation for configuration section existence
2644
2732
  * @param key - Configuration key to check
2645
2733
  * @returns true if the configuration section exists
2646
2734
  */
2647
2735
  static has(key) {
2648
- const instance = ConfigurationManager.getInstance();
2649
- return key in instance.config && instance.config[key] !== undefined;
2736
+ const caller = getVerifiedCallerInfo();
2737
+ if (caller.isUntrusted) {
2738
+ return false;
2739
+ }
2740
+ const instance = ConfigurationManager.getOrCreateInstance();
2741
+ return key in instance._config && instance._config[key] !== undefined;
2650
2742
  }
2651
2743
  /**
2652
2744
  * Get configuration with a default value if not set
2745
+ * @see XSA-XESS-024 Caller validation for default config retrieval
2653
2746
  * @param key - Configuration key
2654
2747
  * @param defaultValue - Default value to return if key doesn't exist
2655
2748
  * @returns Configuration value or default value
2656
2749
  */
2657
2750
  static getOrDefault(key, defaultValue) {
2658
- const instance = ConfigurationManager.getInstance();
2659
- return instance.config[key] ?? defaultValue;
2751
+ const caller = getVerifiedCallerInfo();
2752
+ if (caller.isUntrusted) {
2753
+ return defaultValue;
2754
+ }
2755
+ const instance = ConfigurationManager.getOrCreateInstance();
2756
+ return instance._config[key] ?? defaultValue;
2660
2757
  }
2661
2758
  /**
2662
2759
  * Delete a specific configuration section
2663
2760
  * @param key - Configuration key to delete
2664
2761
  */
2665
2762
  static delete(key) {
2666
- const instance = ConfigurationManager.getInstance();
2667
- delete instance.config[key];
2763
+ const caller = getVerifiedCallerInfo();
2764
+ if (caller.isUntrusted) {
2765
+ return;
2766
+ }
2767
+ const instance = ConfigurationManager.getOrCreateInstance();
2768
+ delete instance._config[key];
2668
2769
  }
2669
2770
  /**
2670
2771
  * Validates XEMS configuration strictly
@@ -4682,6 +4783,41 @@ Discovery.STANDARD_PATHS = [
4682
4783
  path.join("tools", "XHSC", "dist"),
4683
4784
  ];
4684
4785
 
4786
+ /******************************************************************************
4787
+ Copyright (c) Microsoft Corporation.
4788
+
4789
+ Permission to use, copy, modify, and/or distribute this software for any
4790
+ purpose with or without fee is hereby granted.
4791
+
4792
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
4793
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4794
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
4795
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4796
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
4797
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4798
+ PERFORMANCE OF THIS SOFTWARE.
4799
+ ***************************************************************************** */
4800
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
4801
+
4802
+
4803
+ function __classPrivateFieldGet(receiver, state, kind, f) {
4804
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4805
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4806
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
4807
+ }
4808
+
4809
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
4810
+ if (kind === "m") throw new TypeError("Private method is not writable");
4811
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4812
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
4813
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
4814
+ }
4815
+
4816
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
4817
+ var e = new Error(message);
4818
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
4819
+ };
4820
+
4685
4821
  /* *****************************************************************************
4686
4822
  * Nehonix libSynapx — Synchronous Zero-Process-Spawn Shared Memory Bridge
4687
4823
  *
@@ -4936,8 +5072,15 @@ class SynapxSyncBridge {
4936
5072
  }
4937
5073
  /**
4938
5074
  * Executes a synchronous RPC call over shared memory and kernel futex.
5075
+ *
5076
+ * @see XSA-XESS-021 In-transit secret protection via frozen JSON/Uint8 primordials
5077
+ * @see XSA-XESS-022 Caller verification to prevent raw SynapxSyncBridge RPC from untrusted callers
4939
5078
  */
4940
5079
  callSync(module, action, args = [], opts = {}, timeoutMs = 5000) {
5080
+ const callerInfo = getVerifiedCallerInfo();
5081
+ if (callerInfo.isUntrusted || !isImmediateInternalEngineCall()) {
5082
+ throw new Error("libSynapx: Unauthorized caller for bridge");
5083
+ }
4941
5084
  if (!this.isReady || !this.worker) {
4942
5085
  // Lazy synchronous initialization if called before explicit init()
4943
5086
  try {
@@ -4955,7 +5098,7 @@ class SynapxSyncBridge {
4955
5098
  args: stringArgs,
4956
5099
  opts: opts || {},
4957
5100
  };
4958
- const serialized = Buffer.from(JSON.stringify(payloadObj));
5101
+ const serialized = Buffer.from(_JSONStringify(payloadObj));
4959
5102
  if (DATA_OFFSET + serialized.length > this.sab.byteLength) {
4960
5103
  throw new Error(`libSynapx: Payload exceeds SharedArrayBuffer capacity (${this.sab.byteLength} bytes)`);
4961
5104
  }
@@ -4979,7 +5122,7 @@ class SynapxSyncBridge {
4979
5122
  Atomics.store(this.int32, IDX_STATUS, STATUS_IDLE);
4980
5123
  let parsed;
4981
5124
  try {
4982
- parsed = JSON.parse(Buffer.from(respBytes).toString("utf8"));
5125
+ parsed = _JSONParse(Buffer.from(respBytes).toString("utf8"));
4983
5126
  }
4984
5127
  catch (e) {
4985
5128
  throw new Error(`libSynapx: Failed to decode response JSON: ${e.message}`);
@@ -4989,8 +5132,10 @@ class SynapxSyncBridge {
4989
5132
  * Ref: XSA-SYNAPX-001 (SharedArrayBuffer Memory Scrubbing)
4990
5133
  * Overwrite shared memory with zeros immediately following response consumption.
4991
5134
  * Prevents plaintext credential retention across the 128 MB SharedArrayBuffer lifecycle.
5135
+ *
5136
+ * @see XSA-XESS-021 - Uses frozen _Uint8ArrayFill primordial to prevent interception
4992
5137
  */
4993
- this.uint8.fill(0, DATA_OFFSET, DATA_OFFSET + totalUsedLen);
5138
+ _Uint8ArrayFill(this.uint8, 0, DATA_OFFSET, DATA_OFFSET + totalUsedLen);
4994
5139
  Atomics.store(this.int32, IDX_REQ_LEN, 0);
4995
5140
  Atomics.store(this.int32, IDX_RESP_LEN, 0);
4996
5141
  }
@@ -5136,14 +5281,14 @@ class SynapxClient {
5136
5281
  this.sessionHash =
5137
5282
  process.env.XYPRISS_SESSION_HASH ||
5138
5283
  (sessionDir ? path__namespace.basename(sessionDir) : "");
5139
- tslib_es6_js.__classPrivateFieldSet(this, _SynapxClient_authToken, process.env.XYPRISS_INTERNAL_TOKEN ||
5284
+ __classPrivateFieldSet(this, _SynapxClient_authToken, process.env.XYPRISS_INTERNAL_TOKEN ||
5140
5285
  process.env.XYPRISS_XESS_AUTH_TOKEN ||
5141
5286
  "", "f");
5142
- if (!tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_authToken, "f") && sessionDir) {
5287
+ if (!__classPrivateFieldGet(this, _SynapxClient_authToken, "f") && sessionDir) {
5143
5288
  try {
5144
5289
  const tokenFile = path__namespace.join(sessionDir, ".auth_token");
5145
5290
  if (fs__namespace.existsSync(tokenFile)) {
5146
- tslib_es6_js.__classPrivateFieldSet(this, _SynapxClient_authToken, fs__namespace.readFileSync(tokenFile, "utf8").trim(), "f");
5291
+ __classPrivateFieldSet(this, _SynapxClient_authToken, fs__namespace.readFileSync(tokenFile, "utf8").trim(), "f");
5147
5292
  }
5148
5293
  }
5149
5294
  catch { }
@@ -5258,7 +5403,7 @@ class SynapxClient {
5258
5403
  * Connects to the libSynapx server and performs the Zero-Trust handshake.
5259
5404
  */
5260
5405
  async connect() {
5261
- if (tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_socket, "f") && !tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_socket, "f").destroyed && this.isHandshakeComplete) {
5406
+ if (__classPrivateFieldGet(this, _SynapxClient_socket, "f") && !__classPrivateFieldGet(this, _SynapxClient_socket, "f").destroyed && this.isHandshakeComplete) {
5262
5407
  return;
5263
5408
  }
5264
5409
  if (!this.isAvailable()) {
@@ -5272,7 +5417,7 @@ class SynapxClient {
5272
5417
  return reject(new Error("libSynapx: No active session socket path configured (XYPRISS_USER_TMP is unset)"));
5273
5418
  }
5274
5419
  const client = net__namespace.createConnection(this.socketPath, () => {
5275
- tslib_es6_js.__classPrivateFieldSet(this, _SynapxClient_socket, client, "f");
5420
+ __classPrivateFieldSet(this, _SynapxClient_socket, client, "f");
5276
5421
  this.performHandshake()
5277
5422
  .then(() => {
5278
5423
  this.isHandshakeComplete = true;
@@ -5302,14 +5447,14 @@ class SynapxClient {
5302
5447
  * Writes a framed packet to the socket.
5303
5448
  */
5304
5449
  writeFrame(msgType, payload) {
5305
- if (!tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_socket, "f") || tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_socket, "f").destroyed) {
5450
+ if (!__classPrivateFieldGet(this, _SynapxClient_socket, "f") || __classPrivateFieldGet(this, _SynapxClient_socket, "f").destroyed) {
5306
5451
  throw new Error("libSynapx: socket is not connected");
5307
5452
  }
5308
5453
  const header = Buffer.alloc(HEADER_SIZE$1);
5309
5454
  header.writeUInt8(MAGIC_BYTE, 0);
5310
5455
  header.writeUInt8(msgType, 1);
5311
5456
  header.writeUInt32BE(payload.length, 2);
5312
- tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_socket, "f").write(Buffer.concat([header, payload]));
5457
+ __classPrivateFieldGet(this, _SynapxClient_socket, "f").write(Buffer.concat([header, payload]));
5313
5458
  }
5314
5459
  /**
5315
5460
  * Performs initial zero-trust handshake.
@@ -5321,7 +5466,7 @@ class SynapxClient {
5321
5466
  }, 3000);
5322
5467
  const hsPayload = Buffer.from(JSON.stringify({
5323
5468
  sessionHash: this.sessionHash,
5324
- token: tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_authToken, "f"),
5469
+ token: __classPrivateFieldGet(this, _SynapxClient_authToken, "f"),
5325
5470
  clientPid: process.pid,
5326
5471
  }));
5327
5472
  // Temporarily intercept handshake response frame
@@ -5348,9 +5493,9 @@ class SynapxClient {
5348
5493
  try {
5349
5494
  const ack = JSON.parse(payloadBuf.toString("utf8"));
5350
5495
  if (ack.auth) {
5351
- tslib_es6_js.__classPrivateFieldSet(this, _SynapxClient_sessionKey, ack.sessionKey || "", "f");
5496
+ __classPrivateFieldSet(this, _SynapxClient_sessionKey, ack.sessionKey || "", "f");
5352
5497
  try {
5353
- tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_socket, "f")?.unref();
5498
+ __classPrivateFieldGet(this, _SynapxClient_socket, "f")?.unref();
5354
5499
  }
5355
5500
  catch { }
5356
5501
  return resolve();
@@ -5515,10 +5660,10 @@ class SynapxClient {
5515
5660
  }
5516
5661
  }
5517
5662
  try {
5518
- if (!tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_syncBridge, "f")) {
5519
- tslib_es6_js.__classPrivateFieldSet(this, _SynapxClient_syncBridge, SynapxSyncBridge.getInstance(this.socketPath, this.sessionHash, tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_authToken, "f")), "f");
5663
+ if (!__classPrivateFieldGet(this, _SynapxClient_syncBridge, "f")) {
5664
+ __classPrivateFieldSet(this, _SynapxClient_syncBridge, SynapxSyncBridge.getInstance(this.socketPath, this.sessionHash, __classPrivateFieldGet(this, _SynapxClient_authToken, "f")), "f");
5520
5665
  }
5521
- return tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_syncBridge, "f").callSync(module, action, args, opts);
5666
+ return __classPrivateFieldGet(this, _SynapxClient_syncBridge, "f").callSync(module, action, args, opts);
5522
5667
  }
5523
5668
  catch {
5524
5669
  // Resilient fallback to stdin subprocess pipeline
@@ -5619,7 +5764,7 @@ setTimeout(() => process.exit(1), 5000);
5619
5764
  script,
5620
5765
  this.socketPath,
5621
5766
  this.sessionHash,
5622
- tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_authToken, "f"),
5767
+ __classPrivateFieldGet(this, _SynapxClient_authToken, "f"),
5623
5768
  ], {
5624
5769
  input: inputPayload,
5625
5770
  encoding: "utf8",
@@ -5635,14 +5780,14 @@ setTimeout(() => process.exit(1), 5000);
5635
5780
  }
5636
5781
  destroy() {
5637
5782
  this.isHandshakeComplete = false;
5638
- if (tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_syncBridge, "f")) {
5639
- tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_syncBridge, "f").destroy();
5640
- tslib_es6_js.__classPrivateFieldSet(this, _SynapxClient_syncBridge, null, "f");
5783
+ if (__classPrivateFieldGet(this, _SynapxClient_syncBridge, "f")) {
5784
+ __classPrivateFieldGet(this, _SynapxClient_syncBridge, "f").destroy();
5785
+ __classPrivateFieldSet(this, _SynapxClient_syncBridge, null, "f");
5641
5786
  }
5642
- if (tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_socket, "f")) {
5643
- tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_socket, "f").removeAllListeners();
5644
- tslib_es6_js.__classPrivateFieldGet(this, _SynapxClient_socket, "f").destroy();
5645
- tslib_es6_js.__classPrivateFieldSet(this, _SynapxClient_socket, null, "f");
5787
+ if (__classPrivateFieldGet(this, _SynapxClient_socket, "f")) {
5788
+ __classPrivateFieldGet(this, _SynapxClient_socket, "f").removeAllListeners();
5789
+ __classPrivateFieldGet(this, _SynapxClient_socket, "f").destroy();
5790
+ __classPrivateFieldSet(this, _SynapxClient_socket, null, "f");
5646
5791
  }
5647
5792
  for (const [id, pending] of this.pendingCalls.entries()) {
5648
5793
  clearTimeout(pending.timeout);
@@ -6030,7 +6175,7 @@ class BaseApi {
6030
6175
  * @param runner - The XyPrissRunner used to invoke native XHSC binaries.
6031
6176
  */
6032
6177
  constructor(runner) {
6033
- _runnerStore.set(this, runner);
6178
+ _WeakMapSet(_runnerStore, this, runner);
6034
6179
  }
6035
6180
  /**
6036
6181
  * Protected accessor for internal engine classes only.
@@ -6040,7 +6185,7 @@ class BaseApi {
6040
6185
  if (!isImmediateInternalEngineCall()) {
6041
6186
  return undefined;
6042
6187
  }
6043
- return _runnerStore.get(this);
6188
+ return _WeakMapGet(_runnerStore, this);
6044
6189
  }
6045
6190
  }
6046
6191
  /**
@@ -6674,24 +6819,24 @@ class FileHandle {
6674
6819
  _FileHandle_id.set(this, void 0);
6675
6820
  _FileHandle_runner.set(this, void 0);
6676
6821
  _FileHandle_synapx.set(this, void 0);
6677
- tslib_es6_js.__classPrivateFieldSet(this, _FileHandle_id, id, "f");
6678
- tslib_es6_js.__classPrivateFieldSet(this, _FileHandle_runner, runner, "f");
6679
- tslib_es6_js.__classPrivateFieldSet(this, _FileHandle_synapx, SynapxClient.getInstance(), "f");
6822
+ __classPrivateFieldSet(this, _FileHandle_id, id, "f");
6823
+ __classPrivateFieldSet(this, _FileHandle_runner, runner, "f");
6824
+ __classPrivateFieldSet(this, _FileHandle_synapx, SynapxClient.getInstance(), "f");
6680
6825
  }
6681
6826
  /**
6682
6827
  * **Get Native Handle ID**
6683
6828
  */
6684
6829
  get nativeId() {
6685
- return tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_id, "f");
6830
+ return __classPrivateFieldGet(this, _FileHandle_id, "f");
6686
6831
  }
6687
6832
  /**
6688
6833
  * **Read from File**
6689
6834
  * @param length - Max bytes to read
6690
6835
  */
6691
6836
  async read(length) {
6692
- if (tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_synapx, "f").isAvailable()) {
6693
- const res = await tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_synapx, "f").call("fs", "read-handle", [
6694
- String(tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_id, "f")),
6837
+ if (__classPrivateFieldGet(this, _FileHandle_synapx, "f").isAvailable()) {
6838
+ const res = await __classPrivateFieldGet(this, _FileHandle_synapx, "f").call("fs", "read-handle", [
6839
+ String(__classPrivateFieldGet(this, _FileHandle_id, "f")),
6695
6840
  String(length),
6696
6841
  ]);
6697
6842
  if (typeof res === "string") {
@@ -6704,8 +6849,8 @@ class FileHandle {
6704
6849
  }
6705
6850
  return Buffer.from(res || "");
6706
6851
  }
6707
- const res = (await tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_runner, "f").runAsync("fs", "read-handle", [
6708
- String(tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_id, "f")),
6852
+ const res = (await __classPrivateFieldGet(this, _FileHandle_runner, "f").runAsync("fs", "read-handle", [
6853
+ String(__classPrivateFieldGet(this, _FileHandle_id, "f")),
6709
6854
  String(length),
6710
6855
  ]));
6711
6856
  return Buffer.from(res?.content || res || "", "hex");
@@ -6716,15 +6861,15 @@ class FileHandle {
6716
6861
  */
6717
6862
  async write(data) {
6718
6863
  const raw = typeof data === "string" ? Buffer.from(data) : data;
6719
- if (tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_synapx, "f").isAvailable()) {
6720
- const res = await tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_synapx, "f").call("fs", "write-handle", [
6721
- String(tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_id, "f")),
6864
+ if (__classPrivateFieldGet(this, _FileHandle_synapx, "f").isAvailable()) {
6865
+ const res = await __classPrivateFieldGet(this, _FileHandle_synapx, "f").call("fs", "write-handle", [
6866
+ String(__classPrivateFieldGet(this, _FileHandle_id, "f")),
6722
6867
  raw.toString("hex"),
6723
6868
  ]);
6724
6869
  return typeof res === "number" ? res : (res?.n ?? raw.length);
6725
6870
  }
6726
- const res = (await tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_runner, "f").runAsync("fs", "write-handle", [
6727
- String(tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_id, "f")),
6871
+ const res = (await __classPrivateFieldGet(this, _FileHandle_runner, "f").runAsync("fs", "write-handle", [
6872
+ String(__classPrivateFieldGet(this, _FileHandle_id, "f")),
6728
6873
  raw.toString("hex"),
6729
6874
  ]));
6730
6875
  return typeof res === "number" ? res : (res?.n ?? raw.length);
@@ -6735,16 +6880,16 @@ class FileHandle {
6735
6880
  * @param whence - 0: Start, 1: Current, 2: End
6736
6881
  */
6737
6882
  async seek(offset, whence = 0) {
6738
- if (tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_synapx, "f").isAvailable()) {
6739
- const res = await tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_synapx, "f").call("fs", "seek-handle", [
6740
- String(tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_id, "f")),
6883
+ if (__classPrivateFieldGet(this, _FileHandle_synapx, "f").isAvailable()) {
6884
+ const res = await __classPrivateFieldGet(this, _FileHandle_synapx, "f").call("fs", "seek-handle", [
6885
+ String(__classPrivateFieldGet(this, _FileHandle_id, "f")),
6741
6886
  String(offset),
6742
6887
  String(whence),
6743
6888
  ]);
6744
6889
  return typeof res === "number" ? res : (res?.pos ?? 0);
6745
6890
  }
6746
- const res = (await tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_runner, "f").runAsync("fs", "seek-handle", [
6747
- String(tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_id, "f")),
6891
+ const res = (await __classPrivateFieldGet(this, _FileHandle_runner, "f").runAsync("fs", "seek-handle", [
6892
+ String(__classPrivateFieldGet(this, _FileHandle_id, "f")),
6748
6893
  String(offset),
6749
6894
  String(whence),
6750
6895
  ]));
@@ -6754,24 +6899,24 @@ class FileHandle {
6754
6899
  * **Get File Statistics**
6755
6900
  */
6756
6901
  async stat() {
6757
- if (tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_synapx, "f").isAvailable()) {
6758
- return await tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_synapx, "f").call("fs", "stat-handle", [
6759
- String(tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_id, "f")),
6902
+ if (__classPrivateFieldGet(this, _FileHandle_synapx, "f").isAvailable()) {
6903
+ return await __classPrivateFieldGet(this, _FileHandle_synapx, "f").call("fs", "stat-handle", [
6904
+ String(__classPrivateFieldGet(this, _FileHandle_id, "f")),
6760
6905
  ]);
6761
6906
  }
6762
- return (await tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_runner, "f").runAsync("fs", "stat-handle", [
6763
- String(tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_id, "f")),
6907
+ return (await __classPrivateFieldGet(this, _FileHandle_runner, "f").runAsync("fs", "stat-handle", [
6908
+ String(__classPrivateFieldGet(this, _FileHandle_id, "f")),
6764
6909
  ]));
6765
6910
  }
6766
6911
  /**
6767
6912
  * **Close Handle**
6768
6913
  */
6769
6914
  async close() {
6770
- if (tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_synapx, "f").isAvailable()) {
6771
- await tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_synapx, "f").call("fs", "close", [String(tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_id, "f"))]);
6915
+ if (__classPrivateFieldGet(this, _FileHandle_synapx, "f").isAvailable()) {
6916
+ await __classPrivateFieldGet(this, _FileHandle_synapx, "f").call("fs", "close", [String(__classPrivateFieldGet(this, _FileHandle_id, "f"))]);
6772
6917
  }
6773
6918
  else {
6774
- await tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_runner, "f").runAsync("fs", "close", [String(tslib_es6_js.__classPrivateFieldGet(this, _FileHandle_id, "f"))]);
6919
+ await __classPrivateFieldGet(this, _FileHandle_runner, "f").runAsync("fs", "close", [String(__classPrivateFieldGet(this, _FileHandle_id, "f"))]);
6775
6920
  }
6776
6921
  }
6777
6922
  }
@@ -7079,23 +7224,33 @@ class TempFileManager {
7079
7224
  };
7080
7225
  }
7081
7226
  /**
7082
- * Remove a single tracked temporary file safely using native XyPriss FS API.
7227
+ * Remove a single tracked temporary file safely.
7228
+ *
7229
+ * @see XSA-FS-002 Uses direct filesystem deletion to ensure timer-based TTL cleanup succeeds
7230
+ * even when asynchronous event-loop callbacks lack caller stack context.
7083
7231
  */
7084
7232
  removeFile(filePath) {
7085
- const sys = getSysApi$1();
7086
7233
  const entry = this.trackedFiles.get(filePath);
7087
7234
  if (entry?.timer) {
7088
7235
  clearTimeout(entry.timer);
7089
7236
  }
7090
7237
  this.trackedFiles.delete(filePath);
7091
7238
  try {
7092
- if (sys?.fs.exist(filePath)) {
7093
- sys?.fs.rm(filePath, { force: true });
7239
+ if (fs$1.existsSync(filePath)) {
7240
+ fs$1.unlinkSync(filePath);
7094
7241
  logger.debug("fs", `Cleaned up temp file: ${filePath}`);
7095
7242
  return true;
7096
7243
  }
7097
7244
  }
7098
7245
  catch (err) {
7246
+ const sys = getSysApi$1();
7247
+ try {
7248
+ if (sys?.fs.exist(filePath)) {
7249
+ sys.fs.rm(filePath, { force: true });
7250
+ return true;
7251
+ }
7252
+ }
7253
+ catch { }
7099
7254
  logger.warn("fs", `Failed to remove temp file ${filePath}: ${err?.message}`);
7100
7255
  }
7101
7256
  return false;
@@ -7104,14 +7259,13 @@ class TempFileManager {
7104
7259
  * Clean up all active tracked temporary files.
7105
7260
  */
7106
7261
  cleanupAll() {
7107
- const sys = getSysApi$1();
7108
7262
  let count = 0;
7109
7263
  for (const [filePath, entry] of this.trackedFiles.entries()) {
7110
7264
  if (entry.timer)
7111
7265
  clearTimeout(entry.timer);
7112
7266
  try {
7113
- if (sys?.fs.exist(filePath)) {
7114
- sys?.fs.rm(filePath, { force: true });
7267
+ if (fs$1.existsSync(filePath)) {
7268
+ fs$1.unlinkSync(filePath);
7115
7269
  count++;
7116
7270
  }
7117
7271
  }
@@ -7128,12 +7282,11 @@ class TempFileManager {
7128
7282
  return;
7129
7283
  this.exitHooksRegistered = true;
7130
7284
  const performExitCleanup = () => {
7131
- const sys = getSysApi$1();
7132
7285
  for (const [filePath, entry] of this.trackedFiles.entries()) {
7133
7286
  if (entry.autoCleanupOnExit) {
7134
7287
  try {
7135
- if (sys?.fs.exist(filePath)) {
7136
- sys?.fs.rm(filePath, { force: true });
7288
+ if (fs$1.existsSync(filePath)) {
7289
+ fs$1.unlinkSync(filePath);
7137
7290
  }
7138
7291
  }
7139
7292
  catch { }
@@ -7192,8 +7345,16 @@ class FSCore extends FSBase {
7192
7345
  * const content = __sys__.fs.readSync("/etc/hosts");
7193
7346
  */
7194
7347
  this.readSync = (p, options = {}) => {
7195
- const res = this.runner.runSync("fs", "read", [p, String(Boolean(options.bytes))], options);
7196
- return res?.data !== undefined ? res.data : res;
7348
+ try {
7349
+ const res = this.runner.runSync("fs", "read", [p, String(Boolean(options.bytes))], options);
7350
+ return res?.data !== undefined ? res.data : res;
7351
+ }
7352
+ catch (err) {
7353
+ if (err?.message?.includes("Access denied: untrusted caller")) {
7354
+ return "";
7355
+ }
7356
+ throw err;
7357
+ }
7197
7358
  };
7198
7359
  /**
7199
7360
  * **High-Performance Read Stream**
@@ -8969,6 +9130,15 @@ class FSExtended extends FSWatch {
8969
9130
  class FSApi extends FSExtended {
8970
9131
  }
8971
9132
 
9133
+ const _varsStore = new WeakMap();
9134
+ function getVarsMap(api) {
9135
+ let map = _WeakMapGet(_varsStore, api);
9136
+ if (!map) {
9137
+ map = new Map();
9138
+ _WeakMapSet(_varsStore, api, map);
9139
+ }
9140
+ return map;
9141
+ }
8972
9142
  /**
8973
9143
  * **Dynamic Variables & Configuration API**
8974
9144
  *
@@ -8976,14 +9146,15 @@ class FSApi extends FSExtended {
8976
9146
  * Protected with Zero-Trust Caller Verification against unauthorized third-party dependencies.
8977
9147
  *
8978
9148
  * @see XSA-VARS-001
9149
+ * @see XSA-XESS-023
9150
+ * @see XSA-FS-002
8979
9151
  */
8980
9152
  class VarsApi extends BaseApi {
8981
9153
  get __root__() {
8982
- return getCallerProjectRoot() || this.runner.getRoot();
9154
+ return getCallerProjectRoot();
8983
9155
  }
8984
9156
  constructor(runner) {
8985
9157
  super(runner);
8986
- this.vars = new Map();
8987
9158
  // Explicit typed properties for IntelliSense
8988
9159
  this.__version__ = "0.0.0";
8989
9160
  this.__author__ = "unknown";
@@ -8993,12 +9164,13 @@ class VarsApi extends BaseApi {
8993
9164
  this.__alias__ = "app";
8994
9165
  this.__port__ = 3000;
8995
9166
  this.__PORT__ = 3000;
9167
+ _WeakMapSet(_varsStore, this, new Map());
8996
9168
  // ==========================================
8997
9169
  // ENTERPRISE IMMUTABILITY SHIELD
8998
9170
  // ==========================================
8999
9171
  // Lock __root__ so hackers cannot override it via Object.defineProperty
9000
9172
  Object.defineProperty(this, "__root__", {
9001
- get: () => getCallerProjectRoot() || this.runner.getRoot(),
9173
+ get: () => getCallerProjectRoot(),
9002
9174
  enumerable: true,
9003
9175
  configurable: false,
9004
9176
  });
@@ -9038,7 +9210,8 @@ class VarsApi extends BaseApi {
9038
9210
  ].includes(key)) {
9039
9211
  return this[key] ?? defaultValue;
9040
9212
  }
9041
- return this.vars.has(key) ? this.vars.get(key) : defaultValue;
9213
+ const vars = getVarsMap(this);
9214
+ return vars.has(key) ? vars.get(key) : defaultValue;
9042
9215
  }
9043
9216
  /**
9044
9217
  * **Set Variable**
@@ -9075,7 +9248,7 @@ class VarsApi extends BaseApi {
9075
9248
  ].includes(key)) {
9076
9249
  this[key] = value;
9077
9250
  }
9078
- this.vars.set(key, value);
9251
+ getVarsMap(this).set(key, value);
9079
9252
  }
9080
9253
  /**
9081
9254
  * **Check Existence**
@@ -9089,7 +9262,7 @@ class VarsApi extends BaseApi {
9089
9262
  if (caller.isUntrusted) {
9090
9263
  return false;
9091
9264
  }
9092
- return key in this || this.vars.has(key);
9265
+ return key in this || getVarsMap(this).has(key);
9093
9266
  }
9094
9267
  /**
9095
9268
  * **Remove Variable**
@@ -9102,7 +9275,7 @@ class VarsApi extends BaseApi {
9102
9275
  if (caller.isUntrusted) {
9103
9276
  return;
9104
9277
  }
9105
- this.vars.delete(key);
9278
+ getVarsMap(this).delete(key);
9106
9279
  }
9107
9280
  /**
9108
9281
  * **Update Multiple Variables**
@@ -9147,7 +9320,7 @@ class VarsApi extends BaseApi {
9147
9320
  "__PORT__",
9148
9321
  "__root__",
9149
9322
  ];
9150
- return Array.from(new Set([...explicitKeys, ...this.vars.keys()]));
9323
+ return Array.from(new Set([...explicitKeys, ...getVarsMap(this).keys()]));
9151
9324
  }
9152
9325
  /**
9153
9326
  * **Get All Variables**
@@ -9183,15 +9356,62 @@ class VarsApi extends BaseApi {
9183
9356
  * **Clear All**
9184
9357
  */
9185
9358
  clear() {
9186
- this.vars.clear();
9359
+ getVarsMap(this).clear();
9187
9360
  }
9188
9361
  }
9189
9362
 
9190
9363
  const _envRunnerStore = new WeakMap();
9191
9364
  const _sealKeyStore = new WeakMap();
9365
+ const _whitelistStore = new WeakMap();
9366
+ const _whitelistedCacheStore = new WeakMap();
9192
9367
  const _shieldedInstances = new WeakSet();
9193
9368
  const SHIELD_MARKER = Symbol("xypriss.internal.env.shielded");
9369
+ /**
9370
+ * @see XSA-XESS-022 Prevents prototype exposure of capability seal key
9371
+ */
9372
+ function getSealKey(api) {
9373
+ let key = _WeakMapGet(_sealKeyStore, api);
9374
+ if (!key) {
9375
+ key = crypto$2.randomBytes(32).toString("hex");
9376
+ _WeakMapSet(_sealKeyStore, api, key);
9377
+ }
9378
+ return key;
9379
+ }
9380
+ /**
9381
+ * @see XSA-XESS-023 Secures whitelisted fields against direct prototype / object property tampering
9382
+ */
9383
+ function getWhitelist(api) {
9384
+ let wl = _WeakMapGet(_whitelistStore, api);
9385
+ if (!wl) {
9386
+ wl = new Set(api.defaultWhitelist);
9387
+ _WeakMapSet(_whitelistStore, api, wl);
9388
+ }
9389
+ return wl;
9390
+ }
9391
+ function setWhitelist(api, wl) {
9392
+ _WeakMapSet(_whitelistStore, api, wl);
9393
+ }
9394
+ function getWhitelistedCache(api) {
9395
+ let cache = _WeakMapGet(_whitelistedCacheStore, api);
9396
+ if (!cache) {
9397
+ cache = new Map();
9398
+ _WeakMapSet(_whitelistedCacheStore, api, cache);
9399
+ }
9400
+ return cache;
9401
+ }
9194
9402
  class EnvApi {
9403
+ /**
9404
+ * Keys that may pass through the Shield to the real `process.env`.
9405
+ *
9406
+ * @see XSA-XESS-023 Prevents external mutation of whitelisted fields Set from node_modules
9407
+ */
9408
+ get whitelistedFields() {
9409
+ const caller = getVerifiedCallerInfo();
9410
+ if (caller.isUntrusted || !isImmediateInternalEngineCall()) {
9411
+ return new Set();
9412
+ }
9413
+ return getWhitelist(this);
9414
+ }
9195
9415
  /**
9196
9416
  * @param runner - The XyPrissRunner used to invoke native Go binaries.
9197
9417
  * @param mode - The execution mode. Defaults to `"development"`.
@@ -9245,18 +9465,11 @@ class EnvApi {
9245
9465
  "TEMP",
9246
9466
  "TMP",
9247
9467
  ]);
9248
- this.whitelistedFields = new Set(this.defaultWhitelist);
9249
- /**
9250
- * In-memory cache for whitelisted environment variables.
9251
- * Populated directly from the Vault during engine bootstrap, enabling O(1)
9252
- * synchronous reads from process.env without IPC or caller validation conflicts.
9253
- *
9254
- * @see XSA-XESS-019
9255
- */
9256
- this._whitelistedCache = new Map();
9257
- _envRunnerStore.set(this, runner);
9468
+ _WeakMapSet(_envRunnerStore, this, runner);
9258
9469
  const sealKey = crypto$2.randomBytes(32).toString("hex");
9259
- _sealKeyStore.set(this, sealKey);
9470
+ _WeakMapSet(_sealKeyStore, this, sealKey);
9471
+ _WeakMapSet(_whitelistStore, this, new Set(this.defaultWhitelist));
9472
+ _WeakMapSet(_whitelistedCacheStore, this, new Map());
9260
9473
  try {
9261
9474
  runner.runSync("env", "seal", [sealKey], { __seal__: sealKey, pid: process.pid });
9262
9475
  }
@@ -9265,17 +9478,19 @@ class EnvApi {
9265
9478
  this.isDynamic = isDynamic;
9266
9479
  this.applyShield();
9267
9480
  }
9481
+ /**
9482
+ * @see XSA-XESS-022 Prevents seal key theft from untrusted callers
9483
+ */
9268
9484
  getSealKey() {
9269
- let key = _sealKeyStore.get(this);
9270
- if (!key) {
9271
- key = crypto$2.randomBytes(32).toString("hex");
9272
- _sealKeyStore.set(this, key);
9485
+ const caller = getVerifiedCallerInfo();
9486
+ if (caller.isUntrusted || !isImmediateInternalEngineCall()) {
9487
+ return undefined;
9273
9488
  }
9274
- return key;
9489
+ return getSealKey(this);
9275
9490
  }
9276
9491
  executeEnvCall(action, args = [], options = {}) {
9277
- const sealKey = this.getSealKey();
9278
- const runner = _envRunnerStore.get(this);
9492
+ const sealKey = getSealKey(this);
9493
+ const runner = _WeakMapGet(_envRunnerStore, this);
9279
9494
  if (!runner) {
9280
9495
  throw new EnvStoreError();
9281
9496
  }
@@ -9330,8 +9545,8 @@ class EnvApi {
9330
9545
  // @see XSA-XESS-017: Never mirror XEMS_*, ENC_*, DOTENV_*, XY_*, or __* into process.env,
9331
9546
  // because Bun.env and import.meta.env bypass the Proxy shield and would expose plain secrets.
9332
9547
  // @see XSA-XESS-019: Maintain in-memory whitelisted cache for O(1) process.env reads.
9333
- if (this.whitelistedFields.has(key)) {
9334
- this._whitelistedCache.set(key, value);
9548
+ if (getWhitelist(this).has(key)) {
9549
+ getWhitelistedCache(this).set(key, value);
9335
9550
  try {
9336
9551
  process.env[key] = value;
9337
9552
  }
@@ -9359,8 +9574,8 @@ class EnvApi {
9359
9574
  this.executeEnvCall("delete", [key], { root });
9360
9575
  // @see XSA-XESS-017
9361
9576
  // @see XSA-XESS-019: Invalidate whitelisted cache on delete.
9362
- if (this.whitelistedFields.has(key)) {
9363
- this._whitelistedCache.delete(key);
9577
+ if (getWhitelist(this).has(key)) {
9578
+ getWhitelistedCache(this).delete(key);
9364
9579
  try {
9365
9580
  delete process.env[key];
9366
9581
  }
@@ -9588,17 +9803,28 @@ class EnvApi {
9588
9803
  return;
9589
9804
  if (config.whitelist !== undefined) {
9590
9805
  if (config.replaceDefaultWhitelist) {
9591
- this.whitelistedFields = new Set(config.whitelist);
9806
+ setWhitelist(this, new Set(config.whitelist));
9592
9807
  }
9593
9808
  else {
9594
- this.whitelistedFields = new Set([
9809
+ setWhitelist(this, new Set([
9595
9810
  ...this.defaultWhitelist,
9596
9811
  ...config.whitelist,
9597
- ]);
9812
+ ]));
9598
9813
  }
9599
9814
  }
9600
9815
  // Cache all whitelisted values from the vault during trusted bootstrap
9601
- this.refreshWhitelistedCache();
9816
+ this._doRefreshWhitelistedCache();
9817
+ }
9818
+ /**
9819
+ * @see XSA-XESS-019
9820
+ * @see XSA-XESS-023 Guarded against untrusted execution
9821
+ */
9822
+ refreshWhitelistedCache() {
9823
+ const caller = getVerifiedCallerInfo();
9824
+ if (caller.isUntrusted || !isImmediateInternalEngineCall()) {
9825
+ return;
9826
+ }
9827
+ this._doRefreshWhitelistedCache();
9602
9828
  }
9603
9829
  /**
9604
9830
  * Pre-populates the in-memory cache of whitelisted variables from the secure vault
@@ -9610,15 +9836,17 @@ class EnvApi {
9610
9836
  * @internal
9611
9837
  * @see XSA-XESS-019
9612
9838
  */
9613
- refreshWhitelistedCache() {
9614
- const runner = _envRunnerStore.get(this);
9839
+ _doRefreshWhitelistedCache() {
9840
+ const runner = _WeakMapGet(_envRunnerStore, this);
9615
9841
  const hostRoot = runner ? runner.getRoot() : "";
9616
- for (const key of this.whitelistedFields) {
9842
+ const whitelist = getWhitelist(this);
9843
+ const cache = getWhitelistedCache(this);
9844
+ for (const key of whitelist) {
9617
9845
  if (!this.defaultWhitelist.has(key) || key === "PORT") {
9618
9846
  try {
9619
9847
  const res = this.executeEnvCall("get", [key], { root: hostRoot });
9620
9848
  if (res?.found && res.value !== undefined) {
9621
- this._whitelistedCache.set(key, res.value);
9849
+ cache.set(key, res.value);
9622
9850
  }
9623
9851
  }
9624
9852
  catch {
@@ -9646,7 +9874,7 @@ class EnvApi {
9646
9874
  */
9647
9875
  user() {
9648
9876
  try {
9649
- const runner = _envRunnerStore.get(this);
9877
+ const runner = _WeakMapGet(_envRunnerStore, this);
9650
9878
  if (!runner)
9651
9879
  return "";
9652
9880
  const result = runner.runSync("sys", "user");
@@ -9680,7 +9908,7 @@ class EnvApi {
9680
9908
  if (this.isDynamic && callerInfo.root) {
9681
9909
  return callerInfo.root;
9682
9910
  }
9683
- const runner = _envRunnerStore.get(this);
9911
+ const runner = _WeakMapGet(_envRunnerStore, this);
9684
9912
  const hostRoot = runner ? runner.getRoot() : null;
9685
9913
  return hostRoot || callerInfo.root || null;
9686
9914
  }
@@ -9855,9 +10083,11 @@ class EnvApi {
9855
10083
  *
9856
10084
  * @see XSA-XESS-019
9857
10085
  */
9858
- if (self.whitelistedFields.has(prop)) {
9859
- if (self._whitelistedCache.has(prop)) {
9860
- return self._whitelistedCache.get(prop);
10086
+ const whitelist = getWhitelist(self);
10087
+ const cache = getWhitelistedCache(self);
10088
+ if (whitelist.has(prop)) {
10089
+ if (cache.has(prop)) {
10090
+ return cache.get(prop);
9861
10091
  }
9862
10092
  return Reflect.get(target, prop, receiver);
9863
10093
  }
@@ -9940,7 +10170,7 @@ class EnvApi {
9940
10170
  }
9941
10171
  }
9942
10172
  // Allowed whitelisted non-critical keys
9943
- if (self.whitelistedFields.has(key)) {
10173
+ if (getWhitelist(self).has(key)) {
9944
10174
  try {
9945
10175
  target[key] = String(value);
9946
10176
  }
@@ -10000,7 +10230,7 @@ class EnvApi {
10000
10230
  }
10001
10231
  return true;
10002
10232
  }
10003
- if (self.whitelistedFields.has(prop)) {
10233
+ if (getWhitelist(self).has(prop)) {
10004
10234
  try {
10005
10235
  delete target[prop];
10006
10236
  }
@@ -10028,13 +10258,13 @@ class EnvApi {
10028
10258
  finally {
10029
10259
  isInsideShieldCheck = false;
10030
10260
  }
10031
- return [...self.whitelistedFields];
10261
+ return [...getWhitelist(self)];
10032
10262
  },
10033
10263
  // Align `in` operator behaviour with the restricted key set.
10034
10264
  has(target, prop) {
10035
10265
  if (typeof prop !== "string")
10036
10266
  return false;
10037
- if (self.whitelistedFields.has(prop))
10267
+ if (getWhitelist(self).has(prop))
10038
10268
  return true;
10039
10269
  if (prop.startsWith("XYPRISS_") ||
10040
10270
  prop.startsWith("LIBXESS_") ||
@@ -16380,9 +16610,15 @@ class XyPrissFS {
16380
16610
  *
16381
16611
  * The absolute path to the project root directory. This is the primary
16382
16612
  * resolution anchor for all system operations.
16613
+ *
16614
+ * @see XSA-FS-002 Fail-closed project root resolution for untrusted callers
16383
16615
  */
16384
16616
  get __root__() {
16385
- return getCallerProjectRoot() || this._internalRoot;
16617
+ const callerRoot = getCallerProjectRoot();
16618
+ if (!callerRoot) {
16619
+ return undefined;
16620
+ }
16621
+ return callerRoot;
16386
16622
  }
16387
16623
  /**
16388
16624
  * **Initialize System API**
@@ -16526,6 +16762,76 @@ function createSecurityShield(target, label = "__sys__") {
16526
16762
  return createProxy(target, label);
16527
16763
  }
16528
16764
 
16765
+ let _vmHardened = false;
16766
+ /**
16767
+ * Hardens `node:vm` to prevent asynchronous stack decoupling and script origin spoofing.
16768
+ *
16769
+ * Any script compiled through `node:vm` APIs (such as `runInThisContext`, `createScript`, or `new vm.Script`)
16770
+ * has its filename/script origin deterministically tagged with `[vm]`.
16771
+ * This enables the zero-trust stack inspector (`getVerifiedCallerInfo`) to detect synthetic VM frames
16772
+ * even after event loop timers have cleared the origin caller frames.
16773
+ *
16774
+ * @internal
16775
+ * @see XSA-XESS-025
16776
+ */
16777
+ function installVmHardening() {
16778
+ if (_vmHardened)
16779
+ return;
16780
+ _vmHardened = true;
16781
+ try {
16782
+ const wrapOptions = (opts) => {
16783
+ if (typeof opts === "string") {
16784
+ return "[vm] " + opts;
16785
+ }
16786
+ if (opts && typeof opts === "object") {
16787
+ const fname = opts.filename || opts.name;
16788
+ if (fname) {
16789
+ return { ...opts, filename: `[vm] ${fname}` };
16790
+ }
16791
+ return { ...opts, filename: "[vm] <vm-script>" };
16792
+ }
16793
+ return { filename: "[vm] <vm-script>" };
16794
+ };
16795
+ const origRunInThisContext = vm.runInThisContext;
16796
+ if (typeof origRunInThisContext === "function") {
16797
+ vm.runInThisContext = function (code, options) {
16798
+ return origRunInThisContext.call(this, code, wrapOptions(options));
16799
+ };
16800
+ }
16801
+ const origRunInContext = vm.runInContext;
16802
+ if (typeof origRunInContext === "function") {
16803
+ vm.runInContext = function (code, contextifiedObject, options) {
16804
+ return origRunInContext.call(this, code, contextifiedObject, wrapOptions(options));
16805
+ };
16806
+ }
16807
+ const origRunInNewContext = vm.runInNewContext;
16808
+ if (typeof origRunInNewContext === "function") {
16809
+ vm.runInNewContext = function (code, contextObject, options) {
16810
+ return origRunInNewContext.call(this, code, contextObject, wrapOptions(options));
16811
+ };
16812
+ }
16813
+ const origCreateScript = vm.createScript;
16814
+ if (typeof origCreateScript === "function") {
16815
+ vm.createScript = function (code, options) {
16816
+ return origCreateScript.call(this, code, wrapOptions(options));
16817
+ };
16818
+ }
16819
+ const origScript = vm.Script;
16820
+ if (typeof origScript === "function") {
16821
+ const PatchedScript = function (code, options) {
16822
+ return new origScript(code, wrapOptions(options));
16823
+ };
16824
+ PatchedScript.prototype = origScript.prototype;
16825
+ vm.Script = PatchedScript;
16826
+ }
16827
+ }
16828
+ catch {
16829
+ // ignore if vm is not available in environment
16830
+ }
16831
+ }
16832
+
16833
+ // Install VM hardening at engine bootstrap to prevent async stack decoupling
16834
+ installVmHardening();
16529
16835
  /**
16530
16836
  * **XyPriss System Variables (`__sys__`)**
16531
16837
  *
@@ -16542,8 +16848,15 @@ class XyPrissXHSC extends XyPrissFS {
16542
16848
  [XY_XHSC_REGISTER_FS](pluginId, instance) {
16543
16849
  this._pluginMap.set(pluginId, instance);
16544
16850
  }
16851
+ /**
16852
+ * @see XSA-FS-002 Fail-closed project root resolution for untrusted callers
16853
+ */
16545
16854
  get __root__() {
16546
- return getCallerProjectRoot() || this._internalRoot;
16855
+ const callerRoot = getCallerProjectRoot();
16856
+ if (!callerRoot) {
16857
+ return undefined;
16858
+ }
16859
+ return callerRoot;
16547
16860
  }
16548
16861
  constructor(data = {}) {
16549
16862
  const root = data.__root__ || process.cwd();
@@ -35208,6 +35521,12 @@ class XemsError extends Error {
35208
35521
  * XEMS Runner (Long-running process manager)
35209
35522
  * Manages the persistent Rust process for in-memory storage.
35210
35523
  */
35524
+ /**
35525
+ * Module-level storage for XEMS runners by path.
35526
+ *
35527
+ * @see XSA-XESS-024 Prevents exposing runners and secrets via static class reflection
35528
+ */
35529
+ const _runnersByPathStore = new Map();
35211
35530
  class XemsRunner {
35212
35531
  constructor(options = {}) {
35213
35532
  this.process = null;
@@ -35229,7 +35548,7 @@ class XemsRunner {
35229
35548
  */
35230
35549
  static getInstance(pathStr, options = {}) {
35231
35550
  const absPath = path.resolve(process.cwd(), pathStr);
35232
- const existing = XemsRunner.runnersByPath.get(absPath);
35551
+ const existing = _runnersByPathStore.get(absPath);
35233
35552
  if (existing) {
35234
35553
  // Merge options if provided
35235
35554
  if (options.secret)
@@ -35237,7 +35556,7 @@ class XemsRunner {
35237
35556
  return existing;
35238
35557
  }
35239
35558
  const runner = new XemsRunner({ ...options, persistPath: pathStr });
35240
- XemsRunner.runnersByPath.set(absPath, runner);
35559
+ _runnersByPathStore.set(absPath, runner);
35241
35560
  return runner;
35242
35561
  }
35243
35562
  enablePersistence(pathStr, secret, resources) {
@@ -35255,13 +35574,13 @@ class XemsRunner {
35255
35574
  }
35256
35575
  // Register this runner in the global registry for this path
35257
35576
  const absPath = path.resolve(process.cwd(), pathStr);
35258
- const existing = XemsRunner.runnersByPath.get(absPath);
35577
+ const existing = _runnersByPathStore.get(absPath);
35259
35578
  if (existing && existing !== this) {
35260
35579
  this.logger.warn("xems", `Path ${pathStr} is already being managed by another runner. Switching to shared mode.`);
35261
35580
  // Transitions this instance to delegate to the existing one if needed?
35262
35581
  // Actually, for simplicity, we just ensure WE don't spawn if another one is already there.
35263
35582
  }
35264
- XemsRunner.runnersByPath.set(absPath, this);
35583
+ _runnersByPathStore.set(absPath, this);
35265
35584
  // Avoid redundant restarts if path is the same
35266
35585
  if (this.options.persistPath === pathStr && this.process) {
35267
35586
  return;
@@ -35659,10 +35978,6 @@ class XemsRunner {
35659
35978
  this.initPromise = null;
35660
35979
  }
35661
35980
  }
35662
- /**
35663
- * Enables hardware-bound persistent storage for XEMS.
35664
- */
35665
- XemsRunner.runnersByPath = new Map();
35666
35981
  /**
35667
35982
  * Contextual wrapper for XEMS operations within a specific sandbox.
35668
35983
  * Provides a cleaner, fluent API for advanced operations.