xypriss 9.14.24 → 9.14.25

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
@@ -3524,14 +3524,21 @@ function clearInternalSignature() {
3524
3524
  catch { }
3525
3525
  }
3526
3526
  /**
3527
- * Irreversibly locks the internal session authentication post-boot:
3528
- * - Shreds and unlinks the ephemeral .auth_token from disk
3529
- * - Clears in-memory ephemeral token references
3530
- * - Deletes environment variables
3531
- * After this call, no subsequent or rogue process can ever boot XHSC.
3527
+ * Locks internal session authentication post-boot:
3528
+ * - In development / watch mode (e.g. FileOnix hot-reload), preserves the session token on disk
3529
+ * so that reloaded workers can authenticate seamlessly without crashing.
3530
+ * - In production mode, irreversibly shreds and unlinks the ephemeral .auth_token from disk
3531
+ * and purges all references from memory and environment.
3532
3532
  */
3533
3533
  function lockSessionAuth() {
3534
3534
  _ephemeralToken = null;
3535
+ const isDev = process.env.NODE_ENV !== "production" ||
3536
+ process.env.FILEONIX === "1" ||
3537
+ process.env.FILEONIX_WATCH === "1" ||
3538
+ (globalThis.__sys__?.__env__?.isDevelopment?.() ?? false);
3539
+ if (isDev) {
3540
+ return;
3541
+ }
3535
3542
  try {
3536
3543
  const sessionDir = process.env.XYPRISS_USER_TMP || process.env.XESS_SESSION_TMP;
3537
3544
  if (sessionDir) {
@@ -5001,6 +5008,8 @@ class SynapxClient {
5001
5008
  stdio: "inherit",
5002
5009
  env: {
5003
5010
  ...process.env,
5011
+ XYPRISS_USER_TMP: sessionDir,
5012
+ XESS_SESSION_TMP: sessionDir,
5004
5013
  ...(internalSig ? { XYPRISS_INTERNAL_TOKEN: internalSig } : {}),
5005
5014
  NO_COLOR: "1",
5006
5015
  },
@@ -5220,7 +5229,7 @@ class SynapxClient {
5220
5229
  * Executes a multiplexed RPC call over the persistent private channel with full args and options descriptors.
5221
5230
  */
5222
5231
  async call(module, action, args = [], opts = {}, timeoutMs = 60000) {
5223
- if (module === "env") {
5232
+ if (module === "env" || module === "xems" || module === "sys") {
5224
5233
  const callerInfo = getVerifiedCallerInfo();
5225
5234
  if (callerInfo.isUntrusted || !isImmediateInternalEngineCall()) {
5226
5235
  throw new Error(`libSynapx: Unauthorized caller for restricted module '${module}'`);
@@ -5264,7 +5273,7 @@ class SynapxClient {
5264
5273
  * with transparent automatic fallback to stdin pipe subprocess on edge platforms.
5265
5274
  */
5266
5275
  callSync(module, action, args = [], opts = {}) {
5267
- if (module === "env") {
5276
+ if (module === "env" || module === "xems" || module === "sys") {
5268
5277
  const callerInfo = getVerifiedCallerInfo();
5269
5278
  if (callerInfo.isUntrusted || !isImmediateInternalEngineCall()) {
5270
5279
  throw new Error(`libSynapx: Unauthorized caller for restricted module '${module}'`);
@@ -5291,7 +5300,7 @@ class SynapxClient {
5291
5300
  * Subprocess-based synchronous fallback pipeline (streaming via stdin to prevent E2BIG).
5292
5301
  */
5293
5302
  callSyncSubprocess(module, action, args = [], opts = {}) {
5294
- if (module === "env") {
5303
+ if (module === "env" || module === "xems" || module === "sys") {
5295
5304
  const callerInfo = getVerifiedCallerInfo();
5296
5305
  if (callerInfo.isUntrusted || !isImmediateInternalEngineCall()) {
5297
5306
  throw new Error(`libSynapx: Unauthorized caller for restricted module '${module}'`);
@@ -5545,10 +5554,12 @@ class XyPrissRunner {
5545
5554
  cmdArgs.push(`--${flag}`, String(value));
5546
5555
  }
5547
5556
  }
5557
+ const sessionDir = process.env.XYPRISS_USER_TMP || process.env.XESS_SESSION_TMP || "";
5548
5558
  const child = node_child_process.spawn(this.binaryPath, cmdArgs, {
5549
5559
  cwd: this.root,
5550
5560
  env: {
5551
5561
  ...process.env,
5562
+ ...(sessionDir ? { XYPRISS_USER_TMP: sessionDir, XESS_SESSION_TMP: sessionDir } : {}),
5552
5563
  ...(internalSig ? { XYPRISS_INTERNAL_TOKEN: internalSig } : {}),
5553
5564
  },
5554
5565
  });
@@ -5582,10 +5593,12 @@ class XyPrissRunner {
5582
5593
  cmdArgs.push(`--${flag}`, String(value));
5583
5594
  }
5584
5595
  }
5596
+ const sessionDir = process.env.XYPRISS_USER_TMP || process.env.XESS_SESSION_TMP || "";
5585
5597
  const child = node_child_process.spawn(this.binaryPath, cmdArgs, {
5586
5598
  cwd: this.root,
5587
5599
  env: {
5588
5600
  ...process.env,
5601
+ ...(sessionDir ? { XYPRISS_USER_TMP: sessionDir, XESS_SESSION_TMP: sessionDir } : {}),
5589
5602
  ...(internalSig ? { XYPRISS_INTERNAL_TOKEN: internalSig } : {}),
5590
5603
  },
5591
5604
  });
@@ -8870,25 +8883,13 @@ class EnvApi {
8870
8883
  "NODE_DEBUG",
8871
8884
  "NODE_OPTIONS",
8872
8885
  "NODE_ENV",
8873
- "ENC_SECRET_KEY",
8874
- "ENC_SECRET_SEED",
8875
- "ENC_SECRET_SALT",
8876
8886
  "TRACE_DEPRECATION",
8877
8887
  "APPEND_DEPRECATION",
8878
8888
  "READABLE_STREAM",
8879
8889
  "BUN_CONFIG_VERBOSE_FETCH",
8880
8890
  "XYPRISS_ENV_SHIELD",
8881
- "XYPRISS_SESSION_HASH",
8882
- "XYPRISS_USER_TMP",
8883
- "XYPRISS_XESS_AUTH_TOKEN",
8884
- "LIBXESS_ACTIVE",
8885
- "XESS_SESSION_TMP",
8886
- "XESS_TEMP_DIR",
8887
- "LIBPORT_SOCKET_PATH",
8888
- "PORT_SOCKET_PATH",
8889
- "XPM_SOCKET_PATH",
8890
8891
  "BUN_DISABLE_DYNAMIC_CHUNK_SIZE",
8891
- // Node / Bun core HTTPS variables (Issue #43: prevent false-positive security blocking during outgoing TLS/HTTPS requests)
8892
+ // Node / Bun core HTTPS variables (read allowed for network clients, writes strictly guarded in set trap)
8892
8893
  "NODE_TLS_REJECT_UNAUTHORIZED",
8893
8894
  "NODE_EXTRA_CA_CERTS",
8894
8895
  // Standard OS environment paths (Windows / Cross-platform stability)
@@ -9426,6 +9427,18 @@ class EnvApi {
9426
9427
  // warning, preserving actionable signal without log flooding.
9427
9428
  const warnedKeys = new Set();
9428
9429
  const self = this;
9430
+ // Critical environment keys that must NEVER be mutated or poisoned by application or third-party code
9431
+ const CRITICAL_IMMUTABLE_ENV = new Set([
9432
+ "NODE_OPTIONS",
9433
+ "NODE_TLS_REJECT_UNAUTHORIZED",
9434
+ "NODE_EXTRA_CA_CERTS",
9435
+ "PATH",
9436
+ "LD_PRELOAD",
9437
+ "LD_LIBRARY_PATH",
9438
+ "DYLD_INSERT_LIBRARIES",
9439
+ "DYLD_LIBRARY_PATH",
9440
+ ]);
9441
+ let isInsideShieldCheck = false;
9429
9442
  const envShield = new Proxy(process.env, {
9430
9443
  get(target, prop, receiver) {
9431
9444
  if (prop === SHIELD_MARKER) {
@@ -9434,17 +9447,26 @@ class EnvApi {
9434
9447
  if (typeof prop !== "string") {
9435
9448
  return Reflect.get(target, prop, receiver);
9436
9449
  }
9437
- // Pass through whitelisted keys and framework-reserved prefixes.
9438
- if (self.whitelistedFields.has(prop) ||
9439
- prop.startsWith("XY_") ||
9440
- prop.startsWith("XYPRISS_") ||
9441
- prop.startsWith("LIBXESS_") ||
9442
- prop.startsWith("ENC_") ||
9443
- prop.startsWith("DOTENV_") ||
9444
- prop.startsWith("__")) {
9450
+ if (isInsideShieldCheck || prop === "XYPRISS_PROJECT_ROOT" || prop === "XYPRISS_ENV_SHIELD") {
9451
+ return Reflect.get(target, prop, receiver);
9452
+ }
9453
+ // Pass through whitelisted keys.
9454
+ if (self.whitelistedFields.has(prop)) {
9445
9455
  return Reflect.get(target, prop, receiver);
9446
9456
  }
9447
- // Emit one warning per unique blocked key.
9457
+ // Internal framework operations: allow verified engine callers to read environment safely
9458
+ isInsideShieldCheck = true;
9459
+ try {
9460
+ const caller = getVerifiedCallerInfo();
9461
+ if (!caller.isUntrusted && isImmediateInternalEngineCall()) {
9462
+ return Reflect.get(target, prop, receiver);
9463
+ }
9464
+ }
9465
+ finally {
9466
+ isInsideShieldCheck = false;
9467
+ }
9468
+ // All other keys (including ENC_*, DOTENV_*, __*, and application secrets):
9469
+ // direct process.env reads by untrusted/external callers are strictly intercepted and blocked!
9448
9470
  if (!warnedKeys.has(prop)) {
9449
9471
  const isSilent = target["XYPRISS_ENV_SHIELD"] === "silent";
9450
9472
  if (!isSilent) {
@@ -9458,35 +9480,51 @@ class EnvApi {
9458
9480
  return undefined;
9459
9481
  },
9460
9482
  /**
9461
- * Issue #43: Strict `set` trap on `process.env`.
9462
- *
9463
- * Under the Bun runtime, missing a `set` trap causes assignment on `process.env` to invoke
9464
- * `Reflect.defineProperty` with strict descriptor expectations, failing with:
9465
- * `'process.env' only accepts a configurable, writable, and enumerable data descriptor`.
9466
- *
9467
- * This trap permits safe mutation of whitelisted and framework-reserved keys (e.g. `XYPRISS_*`),
9468
- * while gracefully intercepting and auditing non-compliant mutations without crashing the host process.
9483
+ * Strict `set` trap on `process.env`.
9484
+ * Blocks tampering with critical system environment variables (CWE-471).
9485
+ * Restricts internal prefixes to verified engine callers.
9469
9486
  */
9470
9487
  set(target, prop, value, receiver) {
9471
9488
  if (typeof prop !== "string") {
9472
9489
  return Reflect.set(target, prop, value, receiver);
9473
9490
  }
9474
9491
  const key = prop;
9475
- // Allow whitelisted keys and framework-reserved prefixes
9476
- if (self.whitelistedFields.has(key) ||
9477
- key.startsWith("XY_") ||
9478
- key.startsWith("XYPRISS_") ||
9492
+ // Faille 4 (XSA_2026_XESS_007): Prevent poisoning of critical runtime & system variables
9493
+ if (CRITICAL_IMMUTABLE_ENV.has(key)) {
9494
+ if (!warnedKeys.has(key)) {
9495
+ process.stderr.write(`\x1b[31m[SECURITY]\x1b[0m ` +
9496
+ `Direct modification to critical system environment variable process.env["${key}"] is permanently blocked.\n`);
9497
+ warnedKeys.add(key);
9498
+ }
9499
+ return true; // Return true to avoid throwing in strict runtime modes while dropping the poisoned write
9500
+ }
9501
+ // Internal framework prefixes: only mutable by verified internal callers
9502
+ if (key.startsWith("XYPRISS_") ||
9479
9503
  key.startsWith("LIBXESS_") ||
9480
9504
  key.startsWith("XEMS_") ||
9481
- key.startsWith("ENC_") ||
9482
- key.startsWith("DOTENV_") ||
9483
- key.startsWith("__")) {
9505
+ key.startsWith("XESS_")) {
9506
+ isInsideShieldCheck = true;
9484
9507
  try {
9485
- target[key] = String(value);
9508
+ const caller = getVerifiedCallerInfo();
9509
+ if (!caller.isUntrusted &&
9510
+ isImmediateInternalEngineCall()) {
9511
+ try {
9512
+ target[key] = String(value);
9513
+ }
9514
+ catch { }
9515
+ return true;
9516
+ }
9486
9517
  }
9487
- catch {
9488
- // In case target descriptor cannot be mutated directly
9518
+ finally {
9519
+ isInsideShieldCheck = false;
9520
+ }
9521
+ }
9522
+ // Allowed whitelisted non-critical keys
9523
+ if (self.whitelistedFields.has(key)) {
9524
+ try {
9525
+ target[key] = String(value);
9489
9526
  }
9527
+ catch { }
9490
9528
  return true;
9491
9529
  }
9492
9530
  // Prevent fatal crashes in strict runtimes (like Bun) while auditing unauthorized modifications
@@ -9499,9 +9537,13 @@ class EnvApi {
9499
9537
  return true;
9500
9538
  },
9501
9539
  /**
9502
- * Issue #43: Explicit `defineProperty` trap to prevent uncaught descriptor exceptions under Bun.
9540
+ * Explicit `defineProperty` trap to prevent uncaught descriptor exceptions under Bun,
9541
+ * strictly forbidding definition of critical immutable environment keys.
9503
9542
  */
9504
9543
  defineProperty(target, prop, descriptor) {
9544
+ if (typeof prop === "string" && CRITICAL_IMMUTABLE_ENV.has(prop)) {
9545
+ return false;
9546
+ }
9505
9547
  try {
9506
9548
  return Reflect.defineProperty(target, prop, descriptor);
9507
9549
  }
@@ -9510,40 +9552,91 @@ class EnvApi {
9510
9552
  }
9511
9553
  },
9512
9554
  /**
9513
- * Issue #43: Explicit `deleteProperty` trap to allow removing allowed framework keys safely.
9555
+ * Explicit `deleteProperty` trap to allow removing allowed keys safely,
9556
+ * protecting critical environment variables and internal framework state.
9514
9557
  */
9515
9558
  deleteProperty(target, prop) {
9516
9559
  if (typeof prop === "string") {
9517
- if (self.whitelistedFields.has(prop) ||
9518
- prop.startsWith("XY_") ||
9519
- prop.startsWith("XYPRISS_") ||
9560
+ if (CRITICAL_IMMUTABLE_ENV.has(prop)) {
9561
+ return false;
9562
+ }
9563
+ if (prop.startsWith("XYPRISS_") ||
9520
9564
  prop.startsWith("LIBXESS_") ||
9521
9565
  prop.startsWith("XEMS_") ||
9522
- prop.startsWith("ENC_") ||
9523
- prop.startsWith("DOTENV_") ||
9524
- prop.startsWith("__")) {
9566
+ prop.startsWith("XESS_")) {
9567
+ isInsideShieldCheck = true;
9525
9568
  try {
9526
- delete target[prop];
9569
+ const caller = getVerifiedCallerInfo();
9570
+ if (!caller.isUntrusted && isImmediateInternalEngineCall()) {
9571
+ try {
9572
+ delete target[prop];
9573
+ }
9574
+ catch { }
9575
+ return true;
9576
+ }
9527
9577
  }
9528
- catch {
9529
- // ignore
9578
+ finally {
9579
+ isInsideShieldCheck = false;
9530
9580
  }
9531
9581
  return true;
9532
9582
  }
9583
+ if (self.whitelistedFields.has(prop)) {
9584
+ try {
9585
+ delete target[prop];
9586
+ }
9587
+ catch { }
9588
+ return true;
9589
+ }
9533
9590
  }
9534
9591
  return true;
9535
9592
  },
9536
- // Harden enumeration: restrict what callers see when they iterate
9537
- // or spread process.env. Without this trap, spread operators and
9538
- // Object.keys() bypass the get trap entirely.
9539
- ownKeys(_target) {
9593
+ // Harden enumeration: restrict what untrusted callers see when they iterate
9594
+ // or spread process.env, while preserving full environment for internal engine callers.
9595
+ ownKeys(target) {
9596
+ if (isInsideShieldCheck) {
9597
+ return Reflect.ownKeys(target);
9598
+ }
9599
+ isInsideShieldCheck = true;
9600
+ try {
9601
+ const caller = getVerifiedCallerInfo();
9602
+ if (!caller.isUntrusted && isImmediateInternalEngineCall()) {
9603
+ return Reflect.ownKeys(target);
9604
+ }
9605
+ }
9606
+ catch {
9607
+ }
9608
+ finally {
9609
+ isInsideShieldCheck = false;
9610
+ }
9540
9611
  return [...self.whitelistedFields];
9541
9612
  },
9542
9613
  // Align `in` operator behaviour with the restricted key set.
9543
- has(_target, prop) {
9614
+ has(target, prop) {
9544
9615
  if (typeof prop !== "string")
9545
9616
  return false;
9546
- return self.whitelistedFields.has(prop);
9617
+ if (self.whitelistedFields.has(prop))
9618
+ return true;
9619
+ if (prop.startsWith("XYPRISS_") ||
9620
+ prop.startsWith("LIBXESS_") ||
9621
+ prop.startsWith("XESS_") ||
9622
+ prop.startsWith("LIBPORT_") ||
9623
+ prop.startsWith("PORT_") ||
9624
+ prop.startsWith("XPM_")) {
9625
+ if (isInsideShieldCheck)
9626
+ return true;
9627
+ isInsideShieldCheck = true;
9628
+ try {
9629
+ const caller = getVerifiedCallerInfo();
9630
+ return !caller.isUntrusted && isImmediateInternalEngineCall();
9631
+ }
9632
+ catch {
9633
+ return false;
9634
+ }
9635
+ finally {
9636
+ isInsideShieldCheck = false;
9637
+ }
9638
+ }
9639
+ return false;
9547
9640
  },
9548
9641
  });
9549
9642
  try {
@@ -27370,6 +27463,9 @@ class EngineManager {
27370
27463
  detached: true,
27371
27464
  env: {
27372
27465
  ...process.env,
27466
+ XYPRISS_USER_TMP: tmpDir,
27467
+ XESS_SESSION_TMP: tmpDir,
27468
+ XYPRISS_SESSION_HASH: sessionHash,
27373
27469
  ...(internalSig
27374
27470
  ? { XYPRISS_INTERNAL_TOKEN: internalSig }
27375
27471
  : {}),