xypriss 9.14.17 → 9.14.19
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 +30 -16
- package/dist/cjs/index.js +271 -114
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +271 -113
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/package.json +2 -2
- package/scripts/install-xems.js +44 -17
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ This separation allows each layer to operate in its optimal domain: compiled nat
|
|
|
59
59
|
- **Filesystem Engine & Binary Streaming** — High-performance filesystem operations, duplicate detection, and robust **Zero-Copy Ranged Streaming** via `res.sendFile()`, optimized for media delivery and large assets.
|
|
60
60
|
- **File Upload Management** — Production-ready multipart/form-data handling with automatic validation, error handling, and the `getMimes()` helper for extension-to-mime mapping.
|
|
61
61
|
- **Native XML/JSON Conversion Framework** — High-speed, streaming conversion layer integrated into the XHSC core. Automatically transcodes incoming XML to JSON and mirrors outgoing responses, supporting legacy XML clients with zero application-layer effort.
|
|
62
|
-
- **Environment Security Shield** —
|
|
62
|
+
- **Environment Security Shield (Powered by `libXESS`)** — Kernel- and OS-level Zero-Trust secret isolation. Unlike standard runtimes that only proxy `process.env`, `libXESS` enforces OS process boundaries and serves active **decoy honeypots** on direct `.env` filesystem reads, neutralizing supply-chain exfiltration attacks.
|
|
63
63
|
- **Built-in DotEnv Loader** — Zero-dependency, ultra-fast `.env` parser with automatic support for `.env`, `.env.local`.
|
|
64
64
|
- **Extensible Plugin System** — Permission-based plugin architecture with lifecycle hooks and strict security controls (sandboxed restricted instances).
|
|
65
65
|
- **XInS (XyPriss Intelligent Scaling)** — Native Auto-Scaling engine powered by AIMD congestion control. Dynamically adjusts Node.js concurrency based on real-time event loop latency to prevent starvation and ensure zero-downtime stability under extreme load (5000+ concurrent connections). [Read the XInS Guide](https://xypriss.nehonix.com/docs/XInS.md).
|
|
@@ -318,38 +318,52 @@ XyPriss uses a Capability-Based Security Model for plugins. Each plugin operates
|
|
|
318
318
|
|
|
319
319
|
**[Learn more about Plugin Permissions →](https://xypriss.nehonix.com/docs/plugins/permissions)**
|
|
320
320
|
|
|
321
|
-
### Environment Security Shield
|
|
321
|
+
### Environment Security Shield (Powered by `libXESS`)
|
|
322
322
|
|
|
323
|
-
|
|
323
|
+
Most Node.js security tools merely wrap `process.env` in a JavaScript Proxy. However, malicious npm dependencies or automated supply-chain scanners can effortlessly bypass JavaScript Proxies by reading the filesystem directly via `fs.readFileSync(".env")` or running shell sub-commands.
|
|
324
324
|
|
|
325
|
-
|
|
325
|
+
**XyPriss does not settle for JavaScript-level masking.** It enforces an operating system-level process boundary powered by **`libXESS`** (Bipolar Zero-Trust Confinement), embedded directly within the native `xfpm` supervisor and `XHSC` runtime:
|
|
326
|
+
|
|
327
|
+
- **OS & Kernel-Level Confinement**: Live secrets are vaulted strictly in-memory during bootstrap and never exposed in plaintext to the host filesystem.
|
|
328
|
+
- **Active Honeypot Canaries (Tarpits)**: When an unauthorized third-party library attempts to bypass JavaScript by reading `.env` directly from the disk, `libXESS` intercepts the I/O at the OS level and transparently serves **synthetic decoy values** (honeypot canaries). Attackers and automated harvesters exfiltrate useless tokens, alerting your monitoring systems without compromising real credentials.
|
|
329
|
+
- **Mandatory Supervision**: Unconfined execution (launching via standard `node` instead of `xfpm`) is blocked by design. The native `XHSC` engine refuses to bind network ports without an active `libXESS` security session.
|
|
326
330
|
|
|
327
|
-
|
|
331
|
+
#### 1. Zero-Dependency Loader
|
|
328
332
|
|
|
333
|
+
No need for `dotenv` or external packages. XyPriss automatically loads variables from:
|
|
329
334
|
1. `.env`
|
|
330
335
|
2. `.env.local`
|
|
331
336
|
|
|
332
|
-
#### 2. The Shield in Action
|
|
333
|
-
|
|
334
|
-
Standard system variables (like `PATH`, `USER`, `NODE_ENV`) are whitelisted for system stability, but your custom application variables are protected.
|
|
337
|
+
#### 2. The Shield in Action: JS Masking vs. OS-Level Honeypot
|
|
335
338
|
|
|
336
339
|
```typescript
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
340
|
+
import fs from "node:fs";
|
|
341
|
+
|
|
342
|
+
// ❌ 1. Secret harvesting via process.env
|
|
343
|
+
console.log(process.env.DATABASE_PASSWORD);
|
|
344
|
+
// Output: undefined
|
|
345
|
+
// Status: ACCESS BLOCKED (JavaScript-level masking active)
|
|
346
|
+
|
|
347
|
+
// ❌ 2. Bypassing JS via direct filesystem read (.env)
|
|
348
|
+
console.log(fs.readFileSync(".env", "utf-8"));
|
|
349
|
+
// Output: DATABASE_PASSWORD="xy_decoy_db_pass_5c940b2874c0"
|
|
350
|
+
// Status: 🛡️ HONEYPOT ENGAGED (libXESS intercepts at the OS level and returns decoys!)
|
|
351
|
+
|
|
352
|
+
// ✅ 3. Official authenticated business logic in memory
|
|
353
|
+
console.log(__sys__.__env__.get("DATABASE_PASSWORD"));
|
|
354
|
+
// Output: "postgresql://admin:super_secret@db.prod.internal:5432/main"
|
|
355
|
+
// Status: SECURE (Authentic credentials delivered strictly in-memory to authorized code)
|
|
342
356
|
```
|
|
343
357
|
|
|
344
|
-
#### 3.
|
|
358
|
+
#### 3. Internal Framework Configuration
|
|
345
359
|
|
|
346
|
-
|
|
360
|
+
Internal framework variables using the `XYPRISS_` prefix bypass the shield for platform-level configurations:
|
|
347
361
|
|
|
348
362
|
- `XYPRISS_PORT`
|
|
349
363
|
- `XYPRISS_HOST`
|
|
350
364
|
- `XYPRISS_REDIS_URL`
|
|
351
365
|
|
|
352
|
-
**[
|
|
366
|
+
👉 **[Read the Full Environment Security Shield & libXESS Documentation →](https://xypriss.nehonix.com/docs/security/environment-shield)**
|
|
353
367
|
|
|
354
368
|
### Security Disclosure Policy
|
|
355
369
|
|
package/dist/cjs/index.js
CHANGED
|
@@ -18,7 +18,6 @@ var events = require('events');
|
|
|
18
18
|
var vm = require('vm');
|
|
19
19
|
var compression = require('xypriss-compression');
|
|
20
20
|
var strulink = require('strulink');
|
|
21
|
-
var readline = require('node:readline');
|
|
22
21
|
var promises = require('node:fs/promises');
|
|
23
22
|
var http = require('http');
|
|
24
23
|
var stream = require('stream');
|
|
@@ -50,7 +49,6 @@ var net__namespace = /*#__PURE__*/_interopNamespaceDefault(net);
|
|
|
50
49
|
var fs__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(fs$1);
|
|
51
50
|
var path__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(path$1);
|
|
52
51
|
var vm__namespace = /*#__PURE__*/_interopNamespaceDefault(vm);
|
|
53
|
-
var readline__namespace = /*#__PURE__*/_interopNamespaceDefault(readline);
|
|
54
52
|
|
|
55
53
|
/**
|
|
56
54
|
* Type definitions for Console Interception System
|
|
@@ -16777,12 +16775,47 @@ class ConfigLoader {
|
|
|
16777
16775
|
__sys__$1.vars.update(config.$vars);
|
|
16778
16776
|
}
|
|
16779
16777
|
}
|
|
16778
|
+
// Apply ServerOptions sections to Configs (centralized configuration management)
|
|
16779
|
+
const recognizedServerOptionKeys = [
|
|
16780
|
+
"server",
|
|
16781
|
+
"multiServer",
|
|
16782
|
+
"security",
|
|
16783
|
+
"logging",
|
|
16784
|
+
"fileUpload",
|
|
16785
|
+
"performance",
|
|
16786
|
+
"cache",
|
|
16787
|
+
"requestManagement",
|
|
16788
|
+
"notFound",
|
|
16789
|
+
"send",
|
|
16790
|
+
"env",
|
|
16791
|
+
"cluster",
|
|
16792
|
+
"plugins",
|
|
16793
|
+
];
|
|
16794
|
+
const serverOptionsToApply = {};
|
|
16795
|
+
for (const key of recognizedServerOptionKeys) {
|
|
16796
|
+
if (config[key] !== undefined) {
|
|
16797
|
+
serverOptionsToApply[key] = config[key];
|
|
16798
|
+
}
|
|
16799
|
+
}
|
|
16800
|
+
if (Object.keys(serverOptionsToApply).length > 0) {
|
|
16801
|
+
logger$2.debug("server", `ConfigLoader: Merging discovered server configuration into Configs`);
|
|
16802
|
+
ConfigurationManager.merge(serverOptionsToApply);
|
|
16803
|
+
}
|
|
16780
16804
|
// Process internal configuration
|
|
16781
16805
|
const internal = config?.vars?.internal || config?.internal || config?.$internal;
|
|
16782
16806
|
if (internal) {
|
|
16783
16807
|
this.processInternalConfig(internal, projectRoot, configDir);
|
|
16784
16808
|
}
|
|
16785
16809
|
}
|
|
16810
|
+
/**
|
|
16811
|
+
* Centralized application of server options provided to createServer()
|
|
16812
|
+
* Enriches global configuration state and reconciles mutual exclusivity
|
|
16813
|
+
*/
|
|
16814
|
+
applyServerOptions(options = {}) {
|
|
16815
|
+
if (!options || typeof options !== "object")
|
|
16816
|
+
return;
|
|
16817
|
+
ConfigurationManager.merge(options);
|
|
16818
|
+
}
|
|
16786
16819
|
/**
|
|
16787
16820
|
* Processes the internal configuration block.
|
|
16788
16821
|
* Handle specialized filesystems and meta logic defined by plugin IDs.
|
|
@@ -34955,6 +34988,9 @@ class XemsError extends Error {
|
|
|
34955
34988
|
class XemsRunner {
|
|
34956
34989
|
constructor(options = {}) {
|
|
34957
34990
|
this.process = null;
|
|
34991
|
+
this.synapxClient = null;
|
|
34992
|
+
this.socketPath = null;
|
|
34993
|
+
this.initPromise = null;
|
|
34958
34994
|
this.queue = [];
|
|
34959
34995
|
this.isReady = false;
|
|
34960
34996
|
this.options = {};
|
|
@@ -35017,9 +35053,21 @@ class XemsRunner {
|
|
|
35017
35053
|
// Remove the close listener before killing to prevent auto-respawn in a loop
|
|
35018
35054
|
this.process.removeAllListeners("close");
|
|
35019
35055
|
this.process.kill();
|
|
35056
|
+
this.process = null;
|
|
35020
35057
|
}
|
|
35058
|
+
if (this.synapxClient) {
|
|
35059
|
+
try {
|
|
35060
|
+
this.synapxClient.destroy();
|
|
35061
|
+
}
|
|
35062
|
+
catch { }
|
|
35063
|
+
this.synapxClient = null;
|
|
35064
|
+
}
|
|
35065
|
+
this.isReady = false;
|
|
35066
|
+
this.initPromise = null;
|
|
35021
35067
|
// Re-init immediately
|
|
35022
|
-
this.init()
|
|
35068
|
+
this.init().catch((err) => {
|
|
35069
|
+
this.logger.error("xems", `Failed to restart XEMS with persistence: ${err}`);
|
|
35070
|
+
});
|
|
35023
35071
|
}
|
|
35024
35072
|
/**
|
|
35025
35073
|
* Finds the XEMS binary location.
|
|
@@ -35085,90 +35133,167 @@ class XemsRunner {
|
|
|
35085
35133
|
// 5. Global fallback to PATH (Binary must be globally available)
|
|
35086
35134
|
return binName;
|
|
35087
35135
|
}
|
|
35088
|
-
init() {
|
|
35089
|
-
if (
|
|
35090
|
-
|
|
35091
|
-
this.logger.error("xems", `Critical: Binary not found at ${this.binaryPath}`);
|
|
35092
|
-
return; // Cannot spawn
|
|
35136
|
+
async init() {
|
|
35137
|
+
if (this.initPromise) {
|
|
35138
|
+
return this.initPromise;
|
|
35093
35139
|
}
|
|
35094
|
-
|
|
35095
|
-
|
|
35096
|
-
|
|
35097
|
-
|
|
35098
|
-
|
|
35099
|
-
if (this.options.secret) {
|
|
35100
|
-
args.push("--secret", this.options.secret);
|
|
35101
|
-
}
|
|
35102
|
-
if (this.options.cacheSize) {
|
|
35103
|
-
args.push("--cache-size", this.options.cacheSize.toString());
|
|
35140
|
+
this.initPromise = (async () => {
|
|
35141
|
+
if (!fs.existsSync(this.binaryPath) &&
|
|
35142
|
+
!this.binaryPath.endsWith("xems")) {
|
|
35143
|
+
this.logger.error("xems", `Critical: Binary not found at ${this.binaryPath}`);
|
|
35144
|
+
return;
|
|
35104
35145
|
}
|
|
35105
|
-
|
|
35106
|
-
|
|
35107
|
-
|
|
35108
|
-
|
|
35109
|
-
|
|
35110
|
-
|
|
35111
|
-
|
|
35112
|
-
|
|
35146
|
+
try {
|
|
35147
|
+
// Determine isolated session directory (inherits from libXESS confinement environment)
|
|
35148
|
+
const sessionDir = process.env.XYPRISS_USER_TMP ||
|
|
35149
|
+
process.env.XESS_SESSION_TMP ||
|
|
35150
|
+
path.resolve(process.cwd(), ".private");
|
|
35151
|
+
if (!fs.existsSync(sessionDir)) {
|
|
35152
|
+
try {
|
|
35153
|
+
fs.mkdirSync(sessionDir, { recursive: true });
|
|
35154
|
+
}
|
|
35155
|
+
catch { }
|
|
35113
35156
|
}
|
|
35114
|
-
|
|
35115
|
-
|
|
35116
|
-
this.
|
|
35117
|
-
|
|
35118
|
-
|
|
35119
|
-
|
|
35120
|
-
|
|
35121
|
-
|
|
35122
|
-
|
|
35157
|
+
// Dedicated private socket inside the mode 0700 session folder
|
|
35158
|
+
const hash = process.env.XYPRISS_SESSION_HASH || String(process.pid);
|
|
35159
|
+
this.socketPath = path.join(sessionDir, `xems_${hash}.sock`);
|
|
35160
|
+
// Clean stale socket if it exists
|
|
35161
|
+
if (fs.existsSync(this.socketPath)) {
|
|
35162
|
+
try {
|
|
35163
|
+
fs.unlinkSync(this.socketPath);
|
|
35164
|
+
}
|
|
35165
|
+
catch { }
|
|
35123
35166
|
}
|
|
35124
|
-
|
|
35125
|
-
|
|
35126
|
-
|
|
35127
|
-
catch (e) {
|
|
35128
|
-
this.logger.error("xems", `Failed to spawn process ${e}`);
|
|
35129
|
-
}
|
|
35130
|
-
}
|
|
35131
|
-
handleResponse(jsonString) {
|
|
35132
|
-
if (this.queue.length > 0) {
|
|
35133
|
-
const resolver = this.queue.shift();
|
|
35134
|
-
try {
|
|
35135
|
-
const response = JSON.parse(jsonString);
|
|
35136
|
-
if (response.status === "error") {
|
|
35137
|
-
// We resolve even on error to let the caller handle it via the response object,
|
|
35138
|
-
// or we could reject. For XyPriss style, let's just return the response object.
|
|
35139
|
-
resolver && resolver(response, null);
|
|
35167
|
+
const args = ["--socket", this.socketPath];
|
|
35168
|
+
if (this.options.persistPath) {
|
|
35169
|
+
args.push("--persist", this.options.persistPath);
|
|
35140
35170
|
}
|
|
35141
|
-
|
|
35142
|
-
|
|
35171
|
+
// CRITICAL SECURITY REMEDIATION:
|
|
35172
|
+
// NEVER pass this.options.secret in CLI args!
|
|
35173
|
+
// It is transmitted exclusively over the authenticated libSynapx private IPC stream.
|
|
35174
|
+
if (this.options.cacheSize) {
|
|
35175
|
+
args.push("--cache-size", this.options.cacheSize.toString());
|
|
35176
|
+
}
|
|
35177
|
+
this.process = node_child_process.spawn(this.binaryPath, args, {
|
|
35178
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
35179
|
+
});
|
|
35180
|
+
this.process.stderr?.on("data", (data) => {
|
|
35181
|
+
this.logger.error("xems", `[XEMS Log] ${data}`);
|
|
35182
|
+
});
|
|
35183
|
+
this.process.on("close", (code) => {
|
|
35184
|
+
this.isReady = false;
|
|
35185
|
+
if (this.synapxClient) {
|
|
35186
|
+
try {
|
|
35187
|
+
this.synapxClient.destroy();
|
|
35188
|
+
}
|
|
35189
|
+
catch { }
|
|
35190
|
+
this.synapxClient = null;
|
|
35191
|
+
}
|
|
35192
|
+
this.initPromise = null;
|
|
35193
|
+
if (code !== 0 && code !== null) {
|
|
35194
|
+
this.logger.warn("xems", `Process exited unexpectedly with code ${code}. Restarting in 2s...`);
|
|
35195
|
+
setTimeout(() => this.init(), 2000);
|
|
35196
|
+
}
|
|
35197
|
+
});
|
|
35198
|
+
// Wait for socket to become active (up to 3 seconds)
|
|
35199
|
+
let connected = false;
|
|
35200
|
+
for (let i = 0; i < 30; i++) {
|
|
35201
|
+
if (fs.existsSync(this.socketPath)) {
|
|
35202
|
+
connected = true;
|
|
35203
|
+
break;
|
|
35204
|
+
}
|
|
35205
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
35143
35206
|
}
|
|
35207
|
+
if (!connected) {
|
|
35208
|
+
throw new Error(`Timeout waiting for XEMS IPC socket at ${this.socketPath}`);
|
|
35209
|
+
}
|
|
35210
|
+
// Connect SynapxClient to xems.sock
|
|
35211
|
+
this.synapxClient = new SynapxClient(this.socketPath);
|
|
35212
|
+
await this.synapxClient.connect();
|
|
35213
|
+
// Zero-Trust Handshake: Transmit vault secret over private IPC stream
|
|
35214
|
+
if (this.options.secret || this.options.persistPath) {
|
|
35215
|
+
await this.synapxClient.call("xems", "init", [], {
|
|
35216
|
+
secret: this.options.secret || "",
|
|
35217
|
+
persistPath: this.options.persistPath || "",
|
|
35218
|
+
});
|
|
35219
|
+
}
|
|
35220
|
+
this.isReady = true;
|
|
35144
35221
|
}
|
|
35145
35222
|
catch (e) {
|
|
35146
|
-
this.logger.error("xems", `Failed to
|
|
35223
|
+
this.logger.error("xems", `Failed to spawn/initialize XEMS process: ${e}`);
|
|
35224
|
+
this.initPromise = null;
|
|
35147
35225
|
}
|
|
35148
|
-
}
|
|
35226
|
+
})();
|
|
35227
|
+
return this.initPromise;
|
|
35149
35228
|
}
|
|
35150
35229
|
async execute(cmd) {
|
|
35151
|
-
|
|
35152
|
-
|
|
35153
|
-
this.init();
|
|
35230
|
+
if (!this.process || !this.synapxClient) {
|
|
35231
|
+
await this.init();
|
|
35154
35232
|
}
|
|
35155
|
-
// Wait a bit if not ready (startup grace period)
|
|
35156
35233
|
if (!this.isReady) {
|
|
35157
|
-
for (let i = 0; i <
|
|
35234
|
+
for (let i = 0; i < 30; i++) {
|
|
35158
35235
|
if (this.isReady)
|
|
35159
35236
|
break;
|
|
35160
35237
|
await new Promise((r) => setTimeout(r, 100));
|
|
35161
35238
|
}
|
|
35162
35239
|
}
|
|
35163
|
-
|
|
35164
|
-
|
|
35165
|
-
|
|
35166
|
-
|
|
35240
|
+
if (!this.isReady || !this.synapxClient) {
|
|
35241
|
+
throw new XemsError(cmd.action, "XEMS not ready (process dead or initializing)");
|
|
35242
|
+
}
|
|
35243
|
+
try {
|
|
35244
|
+
switch (cmd.action) {
|
|
35245
|
+
case "ping": {
|
|
35246
|
+
const res = await this.synapxClient.call("xems", "ping");
|
|
35247
|
+
return { status: "ok", data: typeof res === "object" ? res.data : res };
|
|
35248
|
+
}
|
|
35249
|
+
case "set": {
|
|
35250
|
+
const args = [cmd.sandbox || "default", cmd.key || "", cmd.value || ""];
|
|
35251
|
+
const opts = {};
|
|
35252
|
+
if (cmd.ttl)
|
|
35253
|
+
opts.ttl = cmd.ttl;
|
|
35254
|
+
const res = await this.synapxClient.call("xems", "set", args, opts);
|
|
35255
|
+
return { status: "ok", data: typeof res === "object" ? res.data : res };
|
|
35256
|
+
}
|
|
35257
|
+
case "get": {
|
|
35258
|
+
const args = [cmd.sandbox || "default", cmd.key || ""];
|
|
35259
|
+
const opts = {};
|
|
35260
|
+
if (cmd.rotate)
|
|
35261
|
+
opts.rotate = true;
|
|
35262
|
+
if (cmd.grace_period)
|
|
35263
|
+
opts.gracePeriod = cmd.grace_period;
|
|
35264
|
+
if (cmd.ttl)
|
|
35265
|
+
opts.ttl = cmd.ttl;
|
|
35266
|
+
const res = await this.synapxClient.call("xems", "get", args, opts);
|
|
35267
|
+
if (typeof res === "object" && res !== null) {
|
|
35268
|
+
return {
|
|
35269
|
+
status: "ok",
|
|
35270
|
+
data: res.data !== undefined ? res.data : res.value,
|
|
35271
|
+
new_token: res.new_token || res.newToken,
|
|
35272
|
+
};
|
|
35273
|
+
}
|
|
35274
|
+
return { status: "ok", data: res };
|
|
35275
|
+
}
|
|
35276
|
+
case "del": {
|
|
35277
|
+
const args = [cmd.sandbox || "default", cmd.key || ""];
|
|
35278
|
+
const res = await this.synapxClient.call("xems", "del", args);
|
|
35279
|
+
return { status: "ok", data: typeof res === "object" ? res.data : res };
|
|
35280
|
+
}
|
|
35281
|
+
default: {
|
|
35282
|
+
const res = await this.synapxClient.call("xems", cmd.action, [
|
|
35283
|
+
cmd.sandbox || "",
|
|
35284
|
+
cmd.key || "",
|
|
35285
|
+
cmd.value || "",
|
|
35286
|
+
]);
|
|
35287
|
+
return { status: "ok", data: typeof res === "object" ? res.data : res };
|
|
35288
|
+
}
|
|
35167
35289
|
}
|
|
35168
|
-
|
|
35169
|
-
|
|
35170
|
-
|
|
35171
|
-
|
|
35290
|
+
}
|
|
35291
|
+
catch (err) {
|
|
35292
|
+
return {
|
|
35293
|
+
status: "error",
|
|
35294
|
+
error: err?.message || String(err),
|
|
35295
|
+
};
|
|
35296
|
+
}
|
|
35172
35297
|
}
|
|
35173
35298
|
// --- Public API Sugar ---
|
|
35174
35299
|
async ping() {
|
|
@@ -35283,12 +35408,26 @@ class XemsRunner {
|
|
|
35283
35408
|
* Forcefully stops the XEMS process and cleans up resources.
|
|
35284
35409
|
*/
|
|
35285
35410
|
destroy() {
|
|
35411
|
+
if (this.synapxClient) {
|
|
35412
|
+
try {
|
|
35413
|
+
this.synapxClient.destroy();
|
|
35414
|
+
}
|
|
35415
|
+
catch { }
|
|
35416
|
+
this.synapxClient = null;
|
|
35417
|
+
}
|
|
35286
35418
|
if (this.process) {
|
|
35287
35419
|
this.process.removeAllListeners("close");
|
|
35288
35420
|
this.process.kill();
|
|
35289
35421
|
this.process = null;
|
|
35290
|
-
this.isReady = false;
|
|
35291
35422
|
}
|
|
35423
|
+
if (this.socketPath && fs.existsSync(this.socketPath)) {
|
|
35424
|
+
try {
|
|
35425
|
+
fs.unlinkSync(this.socketPath);
|
|
35426
|
+
}
|
|
35427
|
+
catch { }
|
|
35428
|
+
}
|
|
35429
|
+
this.isReady = false;
|
|
35430
|
+
this.initPromise = null;
|
|
35292
35431
|
}
|
|
35293
35432
|
}
|
|
35294
35433
|
/**
|
|
@@ -35379,22 +35518,23 @@ class XemsBuiltinPlugin {
|
|
|
35379
35518
|
const app = server.app;
|
|
35380
35519
|
const logger = app.logger;
|
|
35381
35520
|
// 1. Configuration Extraction
|
|
35382
|
-
//
|
|
35383
|
-
|
|
35384
|
-
|
|
35385
|
-
|
|
35386
|
-
|
|
35387
|
-
|
|
35388
|
-
|
|
35389
|
-
|
|
35390
|
-
|
|
35391
|
-
|
|
35392
|
-
|
|
35393
|
-
|
|
35394
|
-
|
|
35521
|
+
// Cascade defaults from global configuration if child only specified partial options or none
|
|
35522
|
+
const globalXems = ConfigurationManager.get("server")?.xems;
|
|
35523
|
+
const localXems = app.configs?.server?.xems;
|
|
35524
|
+
let xemsOptions;
|
|
35525
|
+
if (localXems && globalXems && typeof globalXems === "object") {
|
|
35526
|
+
// Intelligent cascade merge: child inherits parent defaults but can override selectively
|
|
35527
|
+
xemsOptions = mergeWithDefaults(globalXems, localXems);
|
|
35528
|
+
}
|
|
35529
|
+
else if (localXems) {
|
|
35530
|
+
xemsOptions = localXems;
|
|
35531
|
+
}
|
|
35532
|
+
else if (globalXems) {
|
|
35533
|
+
xemsOptions = globalXems;
|
|
35534
|
+
}
|
|
35535
|
+
else {
|
|
35536
|
+
xemsOptions = { enable: false };
|
|
35395
35537
|
}
|
|
35396
|
-
// Expose this instance's runner on the app object for multi-server support
|
|
35397
|
-
app.xems = this.runner;
|
|
35398
35538
|
const isAuxiliary = app.configs?.isAuxiliary;
|
|
35399
35539
|
if (!isAuxiliary) {
|
|
35400
35540
|
logger.info("plugins", "Initializing XEMS Built-in Core Plugin...");
|
|
@@ -35404,6 +35544,7 @@ class XemsBuiltinPlugin {
|
|
|
35404
35544
|
const rawSecret = xemsOptions.secret || xemsOptions.persistence?.secret;
|
|
35405
35545
|
const rawResources = xemsOptions.resources ||
|
|
35406
35546
|
xemsOptions.persistence?.resources;
|
|
35547
|
+
const rawCookieOpts = xemsOptions.cookieOptions || {};
|
|
35407
35548
|
this.sessionOptions = {
|
|
35408
35549
|
sandbox: xemsOptions.sandbox || "auth-session",
|
|
35409
35550
|
cookieName: xemsOptions.cookieName || "xems_token",
|
|
@@ -35412,10 +35553,13 @@ class XemsBuiltinPlugin {
|
|
|
35412
35553
|
autoRotation: xemsOptions.autoRotation ?? true,
|
|
35413
35554
|
attachTo: xemsOptions.attachTo || "session",
|
|
35414
35555
|
gracePeriod: xemsOptions.gracePeriod || 15000,
|
|
35415
|
-
cookieOptions:
|
|
35416
|
-
httpOnly: true,
|
|
35417
|
-
secure: true,
|
|
35418
|
-
sameSite: "Strict",
|
|
35556
|
+
cookieOptions: {
|
|
35557
|
+
httpOnly: rawCookieOpts.httpOnly ?? true,
|
|
35558
|
+
secure: rawCookieOpts.secure ?? true,
|
|
35559
|
+
sameSite: rawCookieOpts.sameSite ?? "Strict",
|
|
35560
|
+
...(rawCookieOpts.domain ? { domain: rawCookieOpts.domain } : {}),
|
|
35561
|
+
...(rawCookieOpts.path ? { path: rawCookieOpts.path } : {}),
|
|
35562
|
+
...rawCookieOpts,
|
|
35419
35563
|
},
|
|
35420
35564
|
};
|
|
35421
35565
|
if (!isAuxiliary) {
|
|
@@ -35434,10 +35578,12 @@ class XemsBuiltinPlugin {
|
|
|
35434
35578
|
}
|
|
35435
35579
|
this.logger.debug("xems", `Server ${app.id ?? "(unknown)"} initialized XEMS. hasValidSecret: ${this.hasValidSecret}, secret: ${secret ? "PROVIDED" : "MISSING"}`);
|
|
35436
35580
|
// 2. Storage & Vault Initialization
|
|
35437
|
-
if (
|
|
35438
|
-
|
|
35581
|
+
if (secret && this.hasValidSecret) {
|
|
35582
|
+
// If path is specified, use file-based persistent runner.
|
|
35583
|
+
// If no path is specified, use shared volatile runner for all instances sharing this secret/cluster.
|
|
35584
|
+
const pathStr = rawPath || "__shared_volatile_vault__";
|
|
35439
35585
|
// Use the static factory to get/create a runner for this path.
|
|
35440
|
-
// This ensures multiple servers/plugins sharing a path also share the process.
|
|
35586
|
+
// This ensures multiple servers/plugins sharing a path (or cluster) also share the process.
|
|
35441
35587
|
this.runner = XemsRunner.getInstance(pathStr, {
|
|
35442
35588
|
secret,
|
|
35443
35589
|
cacheSize: rawResources?.cacheSize,
|
|
@@ -35445,17 +35591,23 @@ class XemsBuiltinPlugin {
|
|
|
35445
35591
|
this.logger.debug("xems", `XemsRunner instances count: ${XemsRunner.runnersByPath?.size ?? 0} for path: ${pathStr}`);
|
|
35446
35592
|
// Attach the shared runner to the app
|
|
35447
35593
|
app.xems = this.runner;
|
|
35448
|
-
|
|
35449
|
-
|
|
35450
|
-
|
|
35451
|
-
|
|
35452
|
-
|
|
35453
|
-
|
|
35454
|
-
|
|
35594
|
+
if (rawPath) {
|
|
35595
|
+
try {
|
|
35596
|
+
this.runner.enablePersistence(rawPath, secret, {
|
|
35597
|
+
cacheSize: rawResources?.cacheSize,
|
|
35598
|
+
});
|
|
35599
|
+
}
|
|
35600
|
+
catch (err) {
|
|
35601
|
+
logger.error("plugins", "Failed to enable XEMS persistence on shared runner", err);
|
|
35602
|
+
}
|
|
35455
35603
|
}
|
|
35456
35604
|
}
|
|
35457
|
-
else
|
|
35458
|
-
|
|
35605
|
+
else {
|
|
35606
|
+
// Expose fallback runner on app
|
|
35607
|
+
app.xems = this.runner;
|
|
35608
|
+
if (!isAuxiliary && xemsOptions.enable !== false) {
|
|
35609
|
+
logger.warn("plugins", "XEMS requested but mandatory 'path' or 32-byte 'secret' is missing. Please provide both.");
|
|
35610
|
+
}
|
|
35459
35611
|
}
|
|
35460
35612
|
// 3. Resource & Health Validation (Warmup)
|
|
35461
35613
|
try {
|
|
@@ -37178,23 +37330,27 @@ class MultiServerManager {
|
|
|
37178
37330
|
// 3. Handle port and host explicitly to ensure they are in the right place
|
|
37179
37331
|
// MultiServerConfig has top-level port/host for convenience,
|
|
37180
37332
|
// but ServerOptions expects them in the 'server' object.
|
|
37181
|
-
//
|
|
37182
|
-
|
|
37183
|
-
|
|
37184
|
-
|
|
37185
|
-
|
|
37186
|
-
|
|
37187
|
-
|
|
37188
|
-
|
|
37189
|
-
|
|
37190
|
-
|
|
37191
|
-
|
|
37192
|
-
|
|
37193
|
-
|
|
37333
|
+
// Cascade and merge security options deeply
|
|
37334
|
+
const baseSecurity = this.baseConfig?.security || {};
|
|
37335
|
+
const childSecurity = config.server?.security || config.security || {};
|
|
37336
|
+
if (Object.keys(baseSecurity).length > 0 || Object.keys(childSecurity).length > 0) {
|
|
37337
|
+
overrides.security = mergeWithDefaults(baseSecurity, childSecurity);
|
|
37338
|
+
}
|
|
37339
|
+
// Cascade server options (specifically server.xems, cookieOptions, secret, etc.)
|
|
37340
|
+
const baseServer = this.baseConfig?.server || {};
|
|
37341
|
+
const childServer = config.server || {};
|
|
37342
|
+
const mergedServer = mergeWithDefaults(baseServer, childServer);
|
|
37343
|
+
if (config.port)
|
|
37344
|
+
mergedServer.port = config.port;
|
|
37345
|
+
if (config.host)
|
|
37346
|
+
mergedServer.host = config.host;
|
|
37347
|
+
overrides.server = mergedServer;
|
|
37194
37348
|
// Enforce mutual exclusivity: autoKillConflict vs autoPortSwitch per server instance
|
|
37195
37349
|
reconcilePortConflictResolution(overrides.server, config.server);
|
|
37350
|
+
const baseLogging = this.baseConfig?.logging || {};
|
|
37351
|
+
const childLogging = config.logging || {};
|
|
37196
37352
|
overrides.logging = {
|
|
37197
|
-
...(
|
|
37353
|
+
...mergeWithDefaults(baseLogging, childLogging),
|
|
37198
37354
|
instanceName: config.id,
|
|
37199
37355
|
};
|
|
37200
37356
|
rejectInternalFlag(overrides);
|
|
@@ -38415,6 +38571,7 @@ function createServer(options = {}) {
|
|
|
38415
38571
|
rejectInternalFlag(options);
|
|
38416
38572
|
// 1. Initial setup
|
|
38417
38573
|
configLoader.loadAndApplySysConfig();
|
|
38574
|
+
configLoader.applyServerOptions(options);
|
|
38418
38575
|
Logger.getInstance(options.logging);
|
|
38419
38576
|
const xms = options?.multiServer?.servers; // XMS = Xypriss MultiServer
|
|
38420
38577
|
// 2. Check for Multi-Server mode
|