xypriss 9.14.19 → 9.14.21
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 +242 -86
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +242 -86
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -4573,6 +4573,13 @@ class XessIpcClient {
|
|
|
4573
4573
|
static probeSocketSync(socketPath) {
|
|
4574
4574
|
if (!fs.existsSync(socketPath))
|
|
4575
4575
|
return false;
|
|
4576
|
+
// Fast-path: When running under active libXESS supervisor, socket presence confirms shielding
|
|
4577
|
+
if (_isLibxessActive ||
|
|
4578
|
+
process.env?.LIBXESS_ACTIVE === "1" ||
|
|
4579
|
+
process.env?.XYPRISS_USER_TMP ||
|
|
4580
|
+
process.env?.XESS_TEMP_DIR) {
|
|
4581
|
+
return true;
|
|
4582
|
+
}
|
|
4576
4583
|
const script = `
|
|
4577
4584
|
const net = require("net");
|
|
4578
4585
|
const sock = process.argv[1];
|
|
@@ -4581,21 +4588,16 @@ const client = net.createConnection(sock, () => {
|
|
|
4581
4588
|
process.exit(0);
|
|
4582
4589
|
});
|
|
4583
4590
|
client.on("error", () => process.exit(1));
|
|
4584
|
-
setTimeout(() => process.exit(1),
|
|
4591
|
+
setTimeout(() => process.exit(1), 1000);
|
|
4585
4592
|
`;
|
|
4586
4593
|
try {
|
|
4587
4594
|
execFileSync(process.execPath, ["-e", script, socketPath], {
|
|
4588
|
-
timeout:
|
|
4595
|
+
timeout: 1500,
|
|
4589
4596
|
stdio: "ignore",
|
|
4590
4597
|
});
|
|
4591
4598
|
return true;
|
|
4592
4599
|
}
|
|
4593
4600
|
catch {
|
|
4594
|
-
// Fichier socket abandonné sur disque sans superviseur actif : purge atomique
|
|
4595
|
-
try {
|
|
4596
|
-
fs.unlinkSync(socketPath);
|
|
4597
|
-
}
|
|
4598
|
-
catch { }
|
|
4599
4601
|
return false;
|
|
4600
4602
|
}
|
|
4601
4603
|
}
|
|
@@ -4758,14 +4760,21 @@ setTimeout(() => process.exit(1), 80);
|
|
|
4758
4760
|
const credential = sessionKey || authToken;
|
|
4759
4761
|
const script = `
|
|
4760
4762
|
const net = require("net");
|
|
4763
|
+
const fs = require("fs");
|
|
4761
4764
|
const sock = process.argv[1];
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
+
let rawInput = "";
|
|
4766
|
+
try {
|
|
4767
|
+
rawInput = fs.readFileSync(0, "utf-8");
|
|
4768
|
+
} catch (e) {
|
|
4769
|
+
process.exit(1);
|
|
4770
|
+
}
|
|
4771
|
+
let payload;
|
|
4772
|
+
try {
|
|
4773
|
+
payload = JSON.parse(rawInput);
|
|
4774
|
+
} catch (e) {
|
|
4775
|
+
process.exit(1);
|
|
4776
|
+
}
|
|
4765
4777
|
const client = net.createConnection(sock, () => {
|
|
4766
|
-
const payload = action === "HANDSHAKE"
|
|
4767
|
-
? { action: "HANDSHAKE", projectDir: targetDir, token: credential }
|
|
4768
|
-
: { action: action, projectDir: targetDir, sessionKey: credential };
|
|
4769
4778
|
client.write(JSON.stringify(payload) + "\\n");
|
|
4770
4779
|
});
|
|
4771
4780
|
let data = "";
|
|
@@ -4783,13 +4792,18 @@ client.on("error", (err) => {
|
|
|
4783
4792
|
});
|
|
4784
4793
|
setTimeout(() => { process.exit(1); }, 3000);
|
|
4785
4794
|
`;
|
|
4795
|
+
const inputPayload = JSON.stringify(action === "HANDSHAKE"
|
|
4796
|
+
? { action: "HANDSHAKE", projectDir: targetDir, token: credential }
|
|
4797
|
+
: { action: action, projectDir: targetDir, sessionKey: credential });
|
|
4786
4798
|
let lastErr;
|
|
4787
4799
|
for (const sock of candidates) {
|
|
4788
4800
|
try {
|
|
4789
|
-
|
|
4801
|
+
// Pass sensitive credentials exclusively via private stdin pipe, NEVER in process.argv
|
|
4802
|
+
const output = execFileSync(process.execPath, ["-e", script, sock], {
|
|
4803
|
+
input: inputPayload,
|
|
4790
4804
|
encoding: "utf8",
|
|
4791
4805
|
timeout: 3000,
|
|
4792
|
-
stdio: ["
|
|
4806
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
4793
4807
|
});
|
|
4794
4808
|
const parsed = JSON.parse(output.trim());
|
|
4795
4809
|
if (parsed.action === "UNAUTHORIZED" || parsed.error) {
|
|
@@ -5135,7 +5149,7 @@ class SynapxClient {
|
|
|
5135
5149
|
try {
|
|
5136
5150
|
const child = spawn(binPath, ["daemon", process.cwd()], {
|
|
5137
5151
|
detached: true,
|
|
5138
|
-
stdio: "
|
|
5152
|
+
stdio: "inherit",
|
|
5139
5153
|
env: {
|
|
5140
5154
|
...process.env,
|
|
5141
5155
|
...(sessionKey ? { XYPRISS_XESS_SESSION_KEY: sessionKey } : {}),
|
|
@@ -8817,46 +8831,64 @@ class XessShieldRequiredError extends Error {
|
|
|
8817
8831
|
}
|
|
8818
8832
|
}
|
|
8819
8833
|
|
|
8834
|
+
let cachedManifest = null;
|
|
8835
|
+
/**
|
|
8836
|
+
* Loads the authoritative plugins manifest provided by xfpm.
|
|
8837
|
+
*/
|
|
8838
|
+
function getPluginsManifest() {
|
|
8839
|
+
if (cachedManifest)
|
|
8840
|
+
return cachedManifest;
|
|
8841
|
+
const manifestPath = process.env.XYPRISS_PLUGINS_MANIFEST ||
|
|
8842
|
+
(process.env.XYPRISS_PROJECT_ROOT
|
|
8843
|
+
? path__default$1.join(process.env.XYPRISS_PROJECT_ROOT, "node_modules", ".xfpm", "plugins_manifest.json")
|
|
8844
|
+
: null);
|
|
8845
|
+
if (manifestPath && fs__default$1.existsSync(manifestPath)) {
|
|
8846
|
+
try {
|
|
8847
|
+
const raw = fs__default$1.readFileSync(manifestPath, "utf-8");
|
|
8848
|
+
cachedManifest = JSON.parse(raw);
|
|
8849
|
+
return cachedManifest;
|
|
8850
|
+
}
|
|
8851
|
+
catch {
|
|
8852
|
+
// ignore
|
|
8853
|
+
}
|
|
8854
|
+
}
|
|
8855
|
+
return null;
|
|
8856
|
+
}
|
|
8820
8857
|
/**
|
|
8821
|
-
*
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
|
|
8858
|
+
* Returns the primary project root determined by xfpm CLI.
|
|
8859
|
+
*/
|
|
8860
|
+
function getPrimaryProjectRoot() {
|
|
8861
|
+
return process.env.XYPRISS_PROJECT_ROOT || process.cwd();
|
|
8862
|
+
}
|
|
8863
|
+
/**
|
|
8864
|
+
* Checks if a directory is a valid project root.
|
|
8825
8865
|
*/
|
|
8826
8866
|
function isProjectRoot(dir) {
|
|
8827
|
-
|
|
8828
|
-
if (!fs__default$1.existsSync(pkgPath))
|
|
8867
|
+
if (!dir)
|
|
8829
8868
|
return false;
|
|
8830
|
-
// Strong Heuristics (Zero FS Read)
|
|
8831
|
-
const hasNodeModules = fs__default$1.existsSync(path__default$1.join(dir, "node_modules"));
|
|
8832
|
-
const hasTsConfig = fs__default$1.existsSync(path__default$1.join(dir, "tsconfig.json"));
|
|
8833
|
-
const hasSrc = fs__default$1.existsSync(path__default$1.join(dir, "src"));
|
|
8834
|
-
const hasXyConfig = fs__default$1.existsSync(path__default$1.join(dir, "xypriss.config.json")) ||
|
|
8835
|
-
fs__default$1.existsSync(path__default$1.join(dir, "xypriss.config.jsonc"));
|
|
8836
|
-
if (hasNodeModules || hasXyConfig || (hasSrc && hasTsConfig))
|
|
8837
|
-
return true;
|
|
8838
|
-
// Package Metadata Heuristic: A 'Real' package root is a unit that
|
|
8839
|
-
// has an identity (name + version). This correctly identifies
|
|
8840
|
-
// installed plugins even if they've been flattened or lack source configs.
|
|
8841
8869
|
try {
|
|
8842
|
-
const
|
|
8843
|
-
|
|
8844
|
-
if (
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
|
|
8870
|
+
const resolved = path__default$1.resolve(dir);
|
|
8871
|
+
const primaryRoot = process.env.XYPRISS_PROJECT_ROOT;
|
|
8872
|
+
if (primaryRoot && resolved === path__default$1.resolve(primaryRoot)) {
|
|
8873
|
+
return true;
|
|
8874
|
+
}
|
|
8875
|
+
const manifest = getPluginsManifest();
|
|
8876
|
+
if (manifest?.roots && manifest.roots[resolved]) {
|
|
8877
|
+
return true;
|
|
8848
8878
|
}
|
|
8879
|
+
const pkgPath = path__default$1.join(resolved, "package.json");
|
|
8880
|
+
return fs__default$1.existsSync(pkgPath);
|
|
8849
8881
|
}
|
|
8850
8882
|
catch {
|
|
8851
|
-
|
|
8883
|
+
return false;
|
|
8852
8884
|
}
|
|
8853
|
-
return false;
|
|
8854
8885
|
}
|
|
8855
8886
|
/**
|
|
8856
|
-
* Identifies the project root for a given caller path
|
|
8887
|
+
* Identifies the project or plugin root for a given caller path using xfpm metadata.
|
|
8857
8888
|
*/
|
|
8858
8889
|
function identifyProjectRoot(filePath) {
|
|
8859
|
-
|
|
8890
|
+
if (!filePath)
|
|
8891
|
+
return undefined;
|
|
8860
8892
|
if (!path__default$1.isAbsolute(filePath)) {
|
|
8861
8893
|
try {
|
|
8862
8894
|
filePath = path__default$1.resolve(filePath);
|
|
@@ -8865,15 +8897,35 @@ function identifyProjectRoot(filePath) {
|
|
|
8865
8897
|
return undefined;
|
|
8866
8898
|
}
|
|
8867
8899
|
}
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
|
|
8871
|
-
const
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
|
|
8900
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
8901
|
+
const primaryRoot = (process.env.XYPRISS_PROJECT_ROOT || process.cwd()).replace(/\\/g, "/");
|
|
8902
|
+
// 1. Direct O(1) match against verified plugins registered by xfpm
|
|
8903
|
+
const manifest = getPluginsManifest();
|
|
8904
|
+
if (manifest?.roots) {
|
|
8905
|
+
for (const [pluginRoot, _pluginName] of Object.entries(manifest.roots)) {
|
|
8906
|
+
const normPluginRoot = pluginRoot.replace(/\\/g, "/");
|
|
8907
|
+
if (normalized === normPluginRoot || normalized.startsWith(normPluginRoot + "/")) {
|
|
8908
|
+
return pluginRoot;
|
|
8909
|
+
}
|
|
8910
|
+
}
|
|
8911
|
+
}
|
|
8912
|
+
// 2. Direct match against primary project root
|
|
8913
|
+
if (normalized === primaryRoot || normalized.startsWith(primaryRoot + "/")) {
|
|
8914
|
+
// If inside node_modules, it is an undeclared/untrusted dependency, NOT the application root!
|
|
8915
|
+
if (normalized.includes("/node_modules/")) {
|
|
8916
|
+
return undefined;
|
|
8917
|
+
}
|
|
8918
|
+
return primaryRoot;
|
|
8919
|
+
}
|
|
8920
|
+
// 3. Monorepo development mods (/mods/<name>/) fallback
|
|
8921
|
+
const modsIdx = normalized.lastIndexOf("/mods/");
|
|
8922
|
+
if (modsIdx !== -1) {
|
|
8923
|
+
const afterMods = normalized.substring(modsIdx + 6);
|
|
8924
|
+
const nextSlash = afterMods.indexOf("/");
|
|
8925
|
+
const modName = nextSlash === -1 ? afterMods : afterMods.substring(0, nextSlash);
|
|
8926
|
+
if (modName) {
|
|
8927
|
+
return normalized.substring(0, modsIdx + 6 + modName.length);
|
|
8875
8928
|
}
|
|
8876
|
-
current = path__default$1.dirname(current);
|
|
8877
8929
|
}
|
|
8878
8930
|
return undefined;
|
|
8879
8931
|
}
|
|
@@ -8883,30 +8935,25 @@ function identifyProjectRoot(filePath) {
|
|
|
8883
8935
|
function getCallerProjectRoot() {
|
|
8884
8936
|
const stack = new Error().stack;
|
|
8885
8937
|
if (!stack)
|
|
8886
|
-
return
|
|
8938
|
+
return getPrimaryProjectRoot();
|
|
8887
8939
|
const lines = stack.split("\n");
|
|
8888
8940
|
let callerFilePath = "";
|
|
8889
|
-
// Line 0 is 'Error', Line 1 is
|
|
8941
|
+
// Line 0 is 'Error', Line 1 is getCallerProjectRoot itself
|
|
8890
8942
|
for (let i = 2; i < lines.length; i++) {
|
|
8891
8943
|
const line = lines[i];
|
|
8892
|
-
if (!line || line.includes(" (node:") || line.includes(" (native"))
|
|
8944
|
+
if (!line || line.includes(" (node:") || line.includes(" (bun:") || line.includes(" (native"))
|
|
8893
8945
|
continue;
|
|
8894
|
-
// Robust matching for file paths (handles both absolute and relative,
|
|
8895
|
-
// but filters out non-file frames like '(native)' or 'replace (unknown)')
|
|
8896
8946
|
const match = line.match(/\((.*\.([jt]s|[cm]js)):\d+:\d+\)$/) ||
|
|
8897
8947
|
line.match(/at (.*\.([jt]s|[cm]js)):\d+:\d+$/);
|
|
8898
8948
|
if (!match)
|
|
8899
8949
|
continue;
|
|
8900
8950
|
const filePath = match[1];
|
|
8901
|
-
if (!filePath || filePath === "native" || filePath === "node:fs")
|
|
8951
|
+
if (!filePath || filePath === "native" || filePath === "node:fs" || filePath === "fs")
|
|
8902
8952
|
continue;
|
|
8903
|
-
//
|
|
8904
|
-
// Even internal mods (/mods/) should be considered callers if they have their own root,
|
|
8905
|
-
// so we don't skip them during stack analysis, but we still trust them for security.
|
|
8953
|
+
// Skip internal engine files to locate the user/plugin caller
|
|
8906
8954
|
if (isEngineCorePath(filePath)) {
|
|
8907
8955
|
continue;
|
|
8908
8956
|
}
|
|
8909
|
-
// Skip specifically the property getters if they appear differently
|
|
8910
8957
|
if (line.includes("at get [") ||
|
|
8911
8958
|
line.includes("at getStrict (") ||
|
|
8912
8959
|
line.includes("PluginAPI.") ||
|
|
@@ -8916,7 +8963,7 @@ function getCallerProjectRoot() {
|
|
|
8916
8963
|
break;
|
|
8917
8964
|
}
|
|
8918
8965
|
if (!callerFilePath)
|
|
8919
|
-
return
|
|
8966
|
+
return getPrimaryProjectRoot();
|
|
8920
8967
|
const root = identifyProjectRoot(callerFilePath);
|
|
8921
8968
|
return root;
|
|
8922
8969
|
}
|
|
@@ -9841,7 +9888,7 @@ class EnvApi {
|
|
|
9841
9888
|
Object.defineProperty(process, "env", {
|
|
9842
9889
|
value: envShield,
|
|
9843
9890
|
writable: false,
|
|
9844
|
-
configurable:
|
|
9891
|
+
configurable: false,
|
|
9845
9892
|
enumerable: true,
|
|
9846
9893
|
});
|
|
9847
9894
|
}
|
|
@@ -18249,6 +18296,9 @@ class XyPrisRequestApp {
|
|
|
18249
18296
|
if (prop in target || prop === "constructor") {
|
|
18250
18297
|
return Reflect.get(target, prop, receiver);
|
|
18251
18298
|
}
|
|
18299
|
+
if (prop === "xems") {
|
|
18300
|
+
return this.appInstance?.xems || this.appInstance?._xems;
|
|
18301
|
+
}
|
|
18252
18302
|
// Otherwise, proxy to appInstance
|
|
18253
18303
|
if (this.appInstance && prop in this.appInstance) {
|
|
18254
18304
|
const value = this.appInstance[prop];
|
|
@@ -26842,8 +26892,9 @@ class XStatic {
|
|
|
26842
26892
|
const cleanRelative = relativePath.startsWith("/")
|
|
26843
26893
|
? relativePath.substring(1)
|
|
26844
26894
|
: relativePath;
|
|
26845
|
-
const fileName = cleanRelative.split("/").pop() || "";
|
|
26846
26895
|
// 2. Dotfile & Restricted File Protection (Global Policy)
|
|
26896
|
+
// Check every segment of cleanRelative to prevent /.git/config traversal
|
|
26897
|
+
const segments = cleanRelative.split("/").filter(Boolean);
|
|
26847
26898
|
const dotfileConfig = this.globalConfig.dotfiles || "deny";
|
|
26848
26899
|
const dotfileMode = typeof dotfileConfig === "object"
|
|
26849
26900
|
? dotfileConfig.mode
|
|
@@ -26852,12 +26903,10 @@ class XStatic {
|
|
|
26852
26903
|
? dotfileConfig.custom || []
|
|
26853
26904
|
: [];
|
|
26854
26905
|
if (dotfileMode === "deny") {
|
|
26855
|
-
const
|
|
26856
|
-
|
|
26857
|
-
if (
|
|
26858
|
-
this.qLog.warn(
|
|
26859
|
-
// "security",
|
|
26860
|
-
`Blocked attempt to access restricted file: ${fileName}`);
|
|
26906
|
+
const hasDotfileSegment = segments.some((s) => s.startsWith("."));
|
|
26907
|
+
const hasCustomRestricted = segments.some((s) => customRestricted.includes(s));
|
|
26908
|
+
if (hasDotfileSegment || hasCustomRestricted) {
|
|
26909
|
+
this.qLog.warn(`Blocked attempt to access restricted file or directory in path: ${cleanRelative}`);
|
|
26861
26910
|
res.status(403).end("Forbidden: Access Denied");
|
|
26862
26911
|
return next();
|
|
26863
26912
|
}
|
|
@@ -26871,15 +26920,20 @@ class XStatic {
|
|
|
26871
26920
|
if (!options.allowOutsideRoot &&
|
|
26872
26921
|
!options.unsafe &&
|
|
26873
26922
|
projectRoot) {
|
|
26874
|
-
|
|
26923
|
+
const relProject = this.sys.path.relative(projectRoot, rootDir);
|
|
26924
|
+
const isInsideProject = !relProject.startsWith("..") && !this.sys.path.isAbsolute(relProject);
|
|
26925
|
+
if (!isInsideProject && rootDir !== projectRoot) {
|
|
26875
26926
|
this.qLog.warn(`Blocked attempt to serve directory outside project root: ${rootDir}`);
|
|
26876
26927
|
res.status(403).end("Forbidden: Project Root Violation");
|
|
26877
26928
|
return next();
|
|
26878
26929
|
}
|
|
26879
26930
|
}
|
|
26880
26931
|
// Check 2: Is the requested file inside the target directory? (Directory Jail Protection)
|
|
26932
|
+
// Strict separator check prevents sibling directory traversal (e.g. /public_backup matching /public)
|
|
26881
26933
|
if (!options.allowOutsideDir && !options.unsafe) {
|
|
26882
|
-
|
|
26934
|
+
const relTarget = this.sys.path.relative(rootDir, resolvedPath);
|
|
26935
|
+
const isInsideTarget = !relTarget.startsWith("..") && !this.sys.path.isAbsolute(relTarget);
|
|
26936
|
+
if (!isInsideTarget && resolvedPath !== rootDir) {
|
|
26883
26937
|
this.qLog.warn(`Blocked attempt to access file outside static target directory: ${resolvedPath}`);
|
|
26884
26938
|
res.status(403).end("Forbidden: Sandbox Violation");
|
|
26885
26939
|
return next();
|
|
@@ -29662,11 +29716,19 @@ class XyprissApp {
|
|
|
29662
29716
|
const self = this;
|
|
29663
29717
|
return new Proxy(this, {
|
|
29664
29718
|
set(target, prop, value) {
|
|
29719
|
+
if (prop === "xems" || prop === "_xems") {
|
|
29720
|
+
target[prop] = value;
|
|
29721
|
+
return true;
|
|
29722
|
+
}
|
|
29665
29723
|
const errorMsg = `[XyPriss Security] Mutation Attempt Detected: Application instance is immutable after creation. Property '${String(prop)}' cannot be changed.`;
|
|
29666
29724
|
self.logger.error("security", errorMsg);
|
|
29667
29725
|
throw new Error(errorMsg);
|
|
29668
29726
|
},
|
|
29669
29727
|
defineProperty(target, prop, descriptor) {
|
|
29728
|
+
if (prop === "xems" || prop === "_xems") {
|
|
29729
|
+
Object.defineProperty(target, prop, descriptor);
|
|
29730
|
+
return true;
|
|
29731
|
+
}
|
|
29670
29732
|
const errorMsg = `[XyPriss Security] Mutation Attempt Detected: Cannot define new property '${String(prop)}' on locked app instance.`;
|
|
29671
29733
|
self.logger.error("security", errorMsg);
|
|
29672
29734
|
throw new Error(errorMsg);
|
|
@@ -34065,6 +34127,7 @@ class PluginSecurity {
|
|
|
34065
34127
|
...allowedMiddlewareMethods,
|
|
34066
34128
|
"logger",
|
|
34067
34129
|
"configs",
|
|
34130
|
+
"xems",
|
|
34068
34131
|
];
|
|
34069
34132
|
// Facade for the app instance to avoid Proxy invariants on non-configurable properties
|
|
34070
34133
|
const appFacade = {};
|
|
@@ -34083,6 +34146,9 @@ class PluginSecurity {
|
|
|
34083
34146
|
return undefined;
|
|
34084
34147
|
}
|
|
34085
34148
|
}
|
|
34149
|
+
if (prop === "xems") {
|
|
34150
|
+
return target.xems || target._xems;
|
|
34151
|
+
}
|
|
34086
34152
|
const originalMethod = target[prop];
|
|
34087
34153
|
if (typeof originalMethod === "function") {
|
|
34088
34154
|
if (allowedRoutingMethods.includes(prop) || allowedMiddlewareMethods.includes(prop)) {
|
|
@@ -34150,7 +34216,26 @@ class PluginSecurity {
|
|
|
34150
34216
|
return originalMethod.bind(target);
|
|
34151
34217
|
}
|
|
34152
34218
|
return originalMethod;
|
|
34153
|
-
}
|
|
34219
|
+
},
|
|
34220
|
+
set: (value) => {
|
|
34221
|
+
const target = server.app;
|
|
34222
|
+
if (prop === "xems" && OFFICIAL_PLUGINS.includes(pluginName)) {
|
|
34223
|
+
try {
|
|
34224
|
+
target.xems = value;
|
|
34225
|
+
}
|
|
34226
|
+
catch { }
|
|
34227
|
+
try {
|
|
34228
|
+
target._xems = value;
|
|
34229
|
+
}
|
|
34230
|
+
catch { }
|
|
34231
|
+
}
|
|
34232
|
+
else {
|
|
34233
|
+
try {
|
|
34234
|
+
target[prop] = value;
|
|
34235
|
+
}
|
|
34236
|
+
catch { }
|
|
34237
|
+
}
|
|
34238
|
+
},
|
|
34154
34239
|
});
|
|
34155
34240
|
}
|
|
34156
34241
|
// Facade for the server instance
|
|
@@ -35379,7 +35464,13 @@ class XemsRunner {
|
|
|
35379
35464
|
* otherwise returns this instance.
|
|
35380
35465
|
*/
|
|
35381
35466
|
forApp(app) {
|
|
35382
|
-
|
|
35467
|
+
if (!app)
|
|
35468
|
+
return this;
|
|
35469
|
+
const candidate = app.xems ||
|
|
35470
|
+
app._xems ||
|
|
35471
|
+
(app.appInstance && (app.appInstance.xems || app.appInstance._xems)) ||
|
|
35472
|
+
(app.server && (app.server.app?.xems || app.server.xems));
|
|
35473
|
+
return candidate || this;
|
|
35383
35474
|
}
|
|
35384
35475
|
/**
|
|
35385
35476
|
* Forcefully stops the XEMS process and cleans up resources.
|
|
@@ -35495,12 +35586,15 @@ class XemsBuiltinPlugin {
|
|
|
35495
35586
|
const app = server.app;
|
|
35496
35587
|
const logger = app.logger;
|
|
35497
35588
|
// 1. Configuration Extraction
|
|
35498
|
-
//
|
|
35589
|
+
// Child server xems configuration takes absolute precedence over global defaults
|
|
35499
35590
|
const globalXems = ConfigurationManager.get("server")?.xems;
|
|
35500
|
-
const localXems = app.configs?.server?.xems
|
|
35591
|
+
const localXems = app.configs?.server?.xems ||
|
|
35592
|
+
app.configs?.xems ||
|
|
35593
|
+
server?.app?.configs?.server?.xems ||
|
|
35594
|
+
server?.app?.configs?.xems;
|
|
35501
35595
|
let xemsOptions;
|
|
35502
35596
|
if (localXems && globalXems && typeof globalXems === "object") {
|
|
35503
|
-
// Intelligent cascade merge: child inherits parent defaults but
|
|
35597
|
+
// Intelligent cascade merge: child inherits parent defaults, but child options strictly override
|
|
35504
35598
|
xemsOptions = mergeWithDefaults(globalXems, localXems);
|
|
35505
35599
|
}
|
|
35506
35600
|
else if (localXems) {
|
|
@@ -35566,8 +35660,35 @@ class XemsBuiltinPlugin {
|
|
|
35566
35660
|
cacheSize: rawResources?.cacheSize,
|
|
35567
35661
|
});
|
|
35568
35662
|
this.logger.debug("xems", `XemsRunner instances count: ${XemsRunner.runnersByPath?.size ?? 0} for path: ${pathStr}`);
|
|
35569
|
-
// Attach the
|
|
35570
|
-
|
|
35663
|
+
// Attach the runner to the app and underlying server instances
|
|
35664
|
+
try {
|
|
35665
|
+
app.xems = this.runner;
|
|
35666
|
+
}
|
|
35667
|
+
catch { }
|
|
35668
|
+
try {
|
|
35669
|
+
app._xems = this.runner;
|
|
35670
|
+
}
|
|
35671
|
+
catch { }
|
|
35672
|
+
if (server && server.app) {
|
|
35673
|
+
try {
|
|
35674
|
+
server.app.xems = this.runner;
|
|
35675
|
+
}
|
|
35676
|
+
catch { }
|
|
35677
|
+
try {
|
|
35678
|
+
server.app._xems = this.runner;
|
|
35679
|
+
}
|
|
35680
|
+
catch { }
|
|
35681
|
+
}
|
|
35682
|
+
if (app.server && app.server.app) {
|
|
35683
|
+
try {
|
|
35684
|
+
app.server.app.xems = this.runner;
|
|
35685
|
+
}
|
|
35686
|
+
catch { }
|
|
35687
|
+
try {
|
|
35688
|
+
app.server.app._xems = this.runner;
|
|
35689
|
+
}
|
|
35690
|
+
catch { }
|
|
35691
|
+
}
|
|
35571
35692
|
if (rawPath) {
|
|
35572
35693
|
try {
|
|
35573
35694
|
this.runner.enablePersistence(rawPath, secret, {
|
|
@@ -35581,7 +35702,24 @@ class XemsBuiltinPlugin {
|
|
|
35581
35702
|
}
|
|
35582
35703
|
else {
|
|
35583
35704
|
// Expose fallback runner on app
|
|
35584
|
-
|
|
35705
|
+
try {
|
|
35706
|
+
app.xems = this.runner;
|
|
35707
|
+
}
|
|
35708
|
+
catch { }
|
|
35709
|
+
try {
|
|
35710
|
+
app._xems = this.runner;
|
|
35711
|
+
}
|
|
35712
|
+
catch { }
|
|
35713
|
+
if (server && server.app) {
|
|
35714
|
+
try {
|
|
35715
|
+
server.app.xems = this.runner;
|
|
35716
|
+
}
|
|
35717
|
+
catch { }
|
|
35718
|
+
try {
|
|
35719
|
+
server.app._xems = this.runner;
|
|
35720
|
+
}
|
|
35721
|
+
catch { }
|
|
35722
|
+
}
|
|
35585
35723
|
if (!isAuxiliary && xemsOptions.enable !== false) {
|
|
35586
35724
|
logger.warn("plugins", "XEMS requested but mandatory 'path' or 32-byte 'secret' is missing. Please provide both.");
|
|
35587
35725
|
}
|
|
@@ -37315,8 +37453,15 @@ class MultiServerManager {
|
|
|
37315
37453
|
}
|
|
37316
37454
|
// Cascade server options (specifically server.xems, cookieOptions, secret, etc.)
|
|
37317
37455
|
const baseServer = this.baseConfig?.server || {};
|
|
37318
|
-
const childServer = config.server || {};
|
|
37456
|
+
const childServer = { ...(config.server || {}) };
|
|
37457
|
+
const childXems = childServer.xems || config.xems;
|
|
37458
|
+
if (childXems) {
|
|
37459
|
+
childServer.xems = childXems;
|
|
37460
|
+
}
|
|
37319
37461
|
const mergedServer = mergeWithDefaults(baseServer, childServer);
|
|
37462
|
+
if (childXems) {
|
|
37463
|
+
mergedServer.xems = mergeWithDefaults(baseServer.xems || {}, childXems);
|
|
37464
|
+
}
|
|
37320
37465
|
if (config.port)
|
|
37321
37466
|
mergedServer.port = config.port;
|
|
37322
37467
|
if (config.host)
|
|
@@ -38541,7 +38686,7 @@ class MultiServerApp {
|
|
|
38541
38686
|
* ```
|
|
38542
38687
|
*
|
|
38543
38688
|
* @see {@link https://xypriss.nehonix.com/docs/getting-started} Getting Started Guide
|
|
38544
|
-
* @see {@link https://xypriss.nehonix.com/docs/
|
|
38689
|
+
* @see {@link https://xypriss.nehonix.com/docs/config/api} Configuration Reference
|
|
38545
38690
|
*/
|
|
38546
38691
|
function createServer(options = {}) {
|
|
38547
38692
|
// --- SECURITY: Internal Options Protection ---
|
|
@@ -38566,8 +38711,19 @@ function createServer(options = {}) {
|
|
|
38566
38711
|
ConfigurationManager.update("multiServer", options.multiServer);
|
|
38567
38712
|
}
|
|
38568
38713
|
const servers = (xms || []).map((server) => {
|
|
38714
|
+
// Hoist top-level xems if child specified it directly on MultiServerConfig
|
|
38715
|
+
if (server.xems && !server.server?.xems) {
|
|
38716
|
+
server.server = server.server || {};
|
|
38717
|
+
server.server.xems = server.xems;
|
|
38718
|
+
}
|
|
38569
38719
|
// Individual server options take precedence over global ones
|
|
38570
38720
|
const merged = mergeWithDefaults(globalOptions, server);
|
|
38721
|
+
// Ensure child server xems explicitly overrides global server xems
|
|
38722
|
+
const explicitChildXems = server.server?.xems || server.xems;
|
|
38723
|
+
if (explicitChildXems) {
|
|
38724
|
+
merged.server = merged.server || {};
|
|
38725
|
+
merged.server.xems = mergeWithDefaults(globalOptions.server?.xems || {}, explicitChildXems);
|
|
38726
|
+
}
|
|
38571
38727
|
// Ensure child server port & host override global server block
|
|
38572
38728
|
if (server.port) {
|
|
38573
38729
|
merged.server = merged.server || {};
|
|
@@ -38649,15 +38805,15 @@ class PluginAPI {
|
|
|
38649
38805
|
if (!sys || !sys.__root__) {
|
|
38650
38806
|
throw new Error("XyPriss Security Error: The provided system core instance is invalid or lacks an authorized project root association.");
|
|
38651
38807
|
}
|
|
38652
|
-
const manifestPath =
|
|
38653
|
-
if (!
|
|
38808
|
+
const manifestPath = path__default.join(sys.__root__, "package.json");
|
|
38809
|
+
if (!fs__default.existsSync(manifestPath)) {
|
|
38654
38810
|
throw new Error(`XyPriss I/O Error: Unable to access project manifest at "${manifestPath}". Verify that the file exists and is readable.`);
|
|
38655
38811
|
}
|
|
38656
38812
|
try {
|
|
38657
|
-
return
|
|
38813
|
+
return JSON.parse(fs__default.readFileSync(manifestPath, "utf-8"));
|
|
38658
38814
|
}
|
|
38659
38815
|
catch (err) {
|
|
38660
|
-
throw new Error(`XyPriss
|
|
38816
|
+
throw new Error(`XyPriss JSON Error: Failed to parse project manifest at "${manifestPath}": ${err.message}`);
|
|
38661
38817
|
}
|
|
38662
38818
|
}
|
|
38663
38819
|
/**
|