xypriss 9.14.20 → 9.14.22
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 +128 -77
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +128 -77
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/package.json +1 -1
- package/scripts/install-xems.js +212 -17
- package/scripts/postinstall-xhsc.js +178 -9
package/dist/cjs/index.js
CHANGED
|
@@ -4596,6 +4596,13 @@ class XessIpcClient {
|
|
|
4596
4596
|
static probeSocketSync(socketPath) {
|
|
4597
4597
|
if (!fs__namespace.existsSync(socketPath))
|
|
4598
4598
|
return false;
|
|
4599
|
+
// Fast-path: When running under active libXESS supervisor, socket presence confirms shielding
|
|
4600
|
+
if (_isLibxessActive ||
|
|
4601
|
+
process.env?.LIBXESS_ACTIVE === "1" ||
|
|
4602
|
+
process.env?.XYPRISS_USER_TMP ||
|
|
4603
|
+
process.env?.XESS_TEMP_DIR) {
|
|
4604
|
+
return true;
|
|
4605
|
+
}
|
|
4599
4606
|
const script = `
|
|
4600
4607
|
const net = require("net");
|
|
4601
4608
|
const sock = process.argv[1];
|
|
@@ -4604,21 +4611,16 @@ const client = net.createConnection(sock, () => {
|
|
|
4604
4611
|
process.exit(0);
|
|
4605
4612
|
});
|
|
4606
4613
|
client.on("error", () => process.exit(1));
|
|
4607
|
-
setTimeout(() => process.exit(1),
|
|
4614
|
+
setTimeout(() => process.exit(1), 1000);
|
|
4608
4615
|
`;
|
|
4609
4616
|
try {
|
|
4610
4617
|
node_child_process.execFileSync(process.execPath, ["-e", script, socketPath], {
|
|
4611
|
-
timeout:
|
|
4618
|
+
timeout: 1500,
|
|
4612
4619
|
stdio: "ignore",
|
|
4613
4620
|
});
|
|
4614
4621
|
return true;
|
|
4615
4622
|
}
|
|
4616
4623
|
catch {
|
|
4617
|
-
// Fichier socket abandonné sur disque sans superviseur actif : purge atomique
|
|
4618
|
-
try {
|
|
4619
|
-
fs__namespace.unlinkSync(socketPath);
|
|
4620
|
-
}
|
|
4621
|
-
catch { }
|
|
4622
4624
|
return false;
|
|
4623
4625
|
}
|
|
4624
4626
|
}
|
|
@@ -4781,14 +4783,21 @@ setTimeout(() => process.exit(1), 80);
|
|
|
4781
4783
|
const credential = sessionKey || authToken;
|
|
4782
4784
|
const script = `
|
|
4783
4785
|
const net = require("net");
|
|
4786
|
+
const fs = require("fs");
|
|
4784
4787
|
const sock = process.argv[1];
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
+
let rawInput = "";
|
|
4789
|
+
try {
|
|
4790
|
+
rawInput = fs.readFileSync(0, "utf-8");
|
|
4791
|
+
} catch (e) {
|
|
4792
|
+
process.exit(1);
|
|
4793
|
+
}
|
|
4794
|
+
let payload;
|
|
4795
|
+
try {
|
|
4796
|
+
payload = JSON.parse(rawInput);
|
|
4797
|
+
} catch (e) {
|
|
4798
|
+
process.exit(1);
|
|
4799
|
+
}
|
|
4788
4800
|
const client = net.createConnection(sock, () => {
|
|
4789
|
-
const payload = action === "HANDSHAKE"
|
|
4790
|
-
? { action: "HANDSHAKE", projectDir: targetDir, token: credential }
|
|
4791
|
-
: { action: action, projectDir: targetDir, sessionKey: credential };
|
|
4792
4801
|
client.write(JSON.stringify(payload) + "\\n");
|
|
4793
4802
|
});
|
|
4794
4803
|
let data = "";
|
|
@@ -4806,13 +4815,18 @@ client.on("error", (err) => {
|
|
|
4806
4815
|
});
|
|
4807
4816
|
setTimeout(() => { process.exit(1); }, 3000);
|
|
4808
4817
|
`;
|
|
4818
|
+
const inputPayload = JSON.stringify(action === "HANDSHAKE"
|
|
4819
|
+
? { action: "HANDSHAKE", projectDir: targetDir, token: credential }
|
|
4820
|
+
: { action: action, projectDir: targetDir, sessionKey: credential });
|
|
4809
4821
|
let lastErr;
|
|
4810
4822
|
for (const sock of candidates) {
|
|
4811
4823
|
try {
|
|
4812
|
-
|
|
4824
|
+
// Pass sensitive credentials exclusively via private stdin pipe, NEVER in process.argv
|
|
4825
|
+
const output = node_child_process.execFileSync(process.execPath, ["-e", script, sock], {
|
|
4826
|
+
input: inputPayload,
|
|
4813
4827
|
encoding: "utf8",
|
|
4814
4828
|
timeout: 3000,
|
|
4815
|
-
stdio: ["
|
|
4829
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
4816
4830
|
});
|
|
4817
4831
|
const parsed = JSON.parse(output.trim());
|
|
4818
4832
|
if (parsed.action === "UNAUTHORIZED" || parsed.error) {
|
|
@@ -5158,7 +5172,7 @@ class SynapxClient {
|
|
|
5158
5172
|
try {
|
|
5159
5173
|
const child = node_child_process.spawn(binPath, ["daemon", process.cwd()], {
|
|
5160
5174
|
detached: true,
|
|
5161
|
-
stdio: "
|
|
5175
|
+
stdio: "inherit",
|
|
5162
5176
|
env: {
|
|
5163
5177
|
...process.env,
|
|
5164
5178
|
...(sessionKey ? { XYPRISS_XESS_SESSION_KEY: sessionKey } : {}),
|
|
@@ -8840,46 +8854,64 @@ class XessShieldRequiredError extends Error {
|
|
|
8840
8854
|
}
|
|
8841
8855
|
}
|
|
8842
8856
|
|
|
8857
|
+
let cachedManifest = null;
|
|
8858
|
+
/**
|
|
8859
|
+
* Loads the authoritative plugins manifest provided by xfpm.
|
|
8860
|
+
*/
|
|
8861
|
+
function getPluginsManifest() {
|
|
8862
|
+
if (cachedManifest)
|
|
8863
|
+
return cachedManifest;
|
|
8864
|
+
const manifestPath = process.env.XYPRISS_PLUGINS_MANIFEST ||
|
|
8865
|
+
(process.env.XYPRISS_PROJECT_ROOT
|
|
8866
|
+
? path$1.join(process.env.XYPRISS_PROJECT_ROOT, "node_modules", ".xfpm", "plugins_manifest.json")
|
|
8867
|
+
: null);
|
|
8868
|
+
if (manifestPath && fs$1.existsSync(manifestPath)) {
|
|
8869
|
+
try {
|
|
8870
|
+
const raw = fs$1.readFileSync(manifestPath, "utf-8");
|
|
8871
|
+
cachedManifest = JSON.parse(raw);
|
|
8872
|
+
return cachedManifest;
|
|
8873
|
+
}
|
|
8874
|
+
catch {
|
|
8875
|
+
// ignore
|
|
8876
|
+
}
|
|
8877
|
+
}
|
|
8878
|
+
return null;
|
|
8879
|
+
}
|
|
8843
8880
|
/**
|
|
8844
|
-
*
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
|
|
8881
|
+
* Returns the primary project root determined by xfpm CLI.
|
|
8882
|
+
*/
|
|
8883
|
+
function getPrimaryProjectRoot() {
|
|
8884
|
+
return process.env.XYPRISS_PROJECT_ROOT || process.cwd();
|
|
8885
|
+
}
|
|
8886
|
+
/**
|
|
8887
|
+
* Checks if a directory is a valid project root.
|
|
8848
8888
|
*/
|
|
8849
8889
|
function isProjectRoot(dir) {
|
|
8850
|
-
|
|
8851
|
-
if (!fs$1.existsSync(pkgPath))
|
|
8890
|
+
if (!dir)
|
|
8852
8891
|
return false;
|
|
8853
|
-
// Strong Heuristics (Zero FS Read)
|
|
8854
|
-
const hasNodeModules = fs$1.existsSync(path$1.join(dir, "node_modules"));
|
|
8855
|
-
const hasTsConfig = fs$1.existsSync(path$1.join(dir, "tsconfig.json"));
|
|
8856
|
-
const hasSrc = fs$1.existsSync(path$1.join(dir, "src"));
|
|
8857
|
-
const hasXyConfig = fs$1.existsSync(path$1.join(dir, "xypriss.config.json")) ||
|
|
8858
|
-
fs$1.existsSync(path$1.join(dir, "xypriss.config.jsonc"));
|
|
8859
|
-
if (hasNodeModules || hasXyConfig || (hasSrc && hasTsConfig))
|
|
8860
|
-
return true;
|
|
8861
|
-
// Package Metadata Heuristic: A 'Real' package root is a unit that
|
|
8862
|
-
// has an identity (name + version). This correctly identifies
|
|
8863
|
-
// installed plugins even if they've been flattened or lack source configs.
|
|
8864
8892
|
try {
|
|
8865
|
-
const
|
|
8866
|
-
|
|
8867
|
-
if (
|
|
8868
|
-
|
|
8869
|
-
if (pkg.name && pkg.version)
|
|
8870
|
-
return true;
|
|
8893
|
+
const resolved = path$1.resolve(dir);
|
|
8894
|
+
const primaryRoot = process.env.XYPRISS_PROJECT_ROOT;
|
|
8895
|
+
if (primaryRoot && resolved === path$1.resolve(primaryRoot)) {
|
|
8896
|
+
return true;
|
|
8871
8897
|
}
|
|
8898
|
+
const manifest = getPluginsManifest();
|
|
8899
|
+
if (manifest?.roots && manifest.roots[resolved]) {
|
|
8900
|
+
return true;
|
|
8901
|
+
}
|
|
8902
|
+
const pkgPath = path$1.join(resolved, "package.json");
|
|
8903
|
+
return fs$1.existsSync(pkgPath);
|
|
8872
8904
|
}
|
|
8873
8905
|
catch {
|
|
8874
|
-
|
|
8906
|
+
return false;
|
|
8875
8907
|
}
|
|
8876
|
-
return false;
|
|
8877
8908
|
}
|
|
8878
8909
|
/**
|
|
8879
|
-
* Identifies the project root for a given caller path
|
|
8910
|
+
* Identifies the project or plugin root for a given caller path using xfpm metadata.
|
|
8880
8911
|
*/
|
|
8881
8912
|
function identifyProjectRoot(filePath) {
|
|
8882
|
-
|
|
8913
|
+
if (!filePath)
|
|
8914
|
+
return undefined;
|
|
8883
8915
|
if (!path$1.isAbsolute(filePath)) {
|
|
8884
8916
|
try {
|
|
8885
8917
|
filePath = path$1.resolve(filePath);
|
|
@@ -8888,15 +8920,35 @@ function identifyProjectRoot(filePath) {
|
|
|
8888
8920
|
return undefined;
|
|
8889
8921
|
}
|
|
8890
8922
|
}
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
const
|
|
8895
|
-
|
|
8896
|
-
|
|
8897
|
-
|
|
8923
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
8924
|
+
const primaryRoot = (process.env.XYPRISS_PROJECT_ROOT || process.cwd()).replace(/\\/g, "/");
|
|
8925
|
+
// 1. Direct O(1) match against verified plugins registered by xfpm
|
|
8926
|
+
const manifest = getPluginsManifest();
|
|
8927
|
+
if (manifest?.roots) {
|
|
8928
|
+
for (const [pluginRoot, _pluginName] of Object.entries(manifest.roots)) {
|
|
8929
|
+
const normPluginRoot = pluginRoot.replace(/\\/g, "/");
|
|
8930
|
+
if (normalized === normPluginRoot || normalized.startsWith(normPluginRoot + "/")) {
|
|
8931
|
+
return pluginRoot;
|
|
8932
|
+
}
|
|
8933
|
+
}
|
|
8934
|
+
}
|
|
8935
|
+
// 2. Direct match against primary project root
|
|
8936
|
+
if (normalized === primaryRoot || normalized.startsWith(primaryRoot + "/")) {
|
|
8937
|
+
// If inside node_modules, it is an undeclared/untrusted dependency, NOT the application root!
|
|
8938
|
+
if (normalized.includes("/node_modules/")) {
|
|
8939
|
+
return undefined;
|
|
8940
|
+
}
|
|
8941
|
+
return primaryRoot;
|
|
8942
|
+
}
|
|
8943
|
+
// 3. Monorepo development mods (/mods/<name>/) fallback
|
|
8944
|
+
const modsIdx = normalized.lastIndexOf("/mods/");
|
|
8945
|
+
if (modsIdx !== -1) {
|
|
8946
|
+
const afterMods = normalized.substring(modsIdx + 6);
|
|
8947
|
+
const nextSlash = afterMods.indexOf("/");
|
|
8948
|
+
const modName = nextSlash === -1 ? afterMods : afterMods.substring(0, nextSlash);
|
|
8949
|
+
if (modName) {
|
|
8950
|
+
return normalized.substring(0, modsIdx + 6 + modName.length);
|
|
8898
8951
|
}
|
|
8899
|
-
current = path$1.dirname(current);
|
|
8900
8952
|
}
|
|
8901
8953
|
return undefined;
|
|
8902
8954
|
}
|
|
@@ -8906,30 +8958,25 @@ function identifyProjectRoot(filePath) {
|
|
|
8906
8958
|
function getCallerProjectRoot() {
|
|
8907
8959
|
const stack = new Error().stack;
|
|
8908
8960
|
if (!stack)
|
|
8909
|
-
return
|
|
8961
|
+
return getPrimaryProjectRoot();
|
|
8910
8962
|
const lines = stack.split("\n");
|
|
8911
8963
|
let callerFilePath = "";
|
|
8912
|
-
// Line 0 is 'Error', Line 1 is
|
|
8964
|
+
// Line 0 is 'Error', Line 1 is getCallerProjectRoot itself
|
|
8913
8965
|
for (let i = 2; i < lines.length; i++) {
|
|
8914
8966
|
const line = lines[i];
|
|
8915
|
-
if (!line || line.includes(" (node:") || line.includes(" (native"))
|
|
8967
|
+
if (!line || line.includes(" (node:") || line.includes(" (bun:") || line.includes(" (native"))
|
|
8916
8968
|
continue;
|
|
8917
|
-
// Robust matching for file paths (handles both absolute and relative,
|
|
8918
|
-
// but filters out non-file frames like '(native)' or 'replace (unknown)')
|
|
8919
8969
|
const match = line.match(/\((.*\.([jt]s|[cm]js)):\d+:\d+\)$/) ||
|
|
8920
8970
|
line.match(/at (.*\.([jt]s|[cm]js)):\d+:\d+$/);
|
|
8921
8971
|
if (!match)
|
|
8922
8972
|
continue;
|
|
8923
8973
|
const filePath = match[1];
|
|
8924
|
-
if (!filePath || filePath === "native" || filePath === "node:fs")
|
|
8974
|
+
if (!filePath || filePath === "native" || filePath === "node:fs" || filePath === "fs")
|
|
8925
8975
|
continue;
|
|
8926
|
-
//
|
|
8927
|
-
// Even internal mods (/mods/) should be considered callers if they have their own root,
|
|
8928
|
-
// so we don't skip them during stack analysis, but we still trust them for security.
|
|
8976
|
+
// Skip internal engine files to locate the user/plugin caller
|
|
8929
8977
|
if (isEngineCorePath(filePath)) {
|
|
8930
8978
|
continue;
|
|
8931
8979
|
}
|
|
8932
|
-
// Skip specifically the property getters if they appear differently
|
|
8933
8980
|
if (line.includes("at get [") ||
|
|
8934
8981
|
line.includes("at getStrict (") ||
|
|
8935
8982
|
line.includes("PluginAPI.") ||
|
|
@@ -8939,7 +8986,7 @@ function getCallerProjectRoot() {
|
|
|
8939
8986
|
break;
|
|
8940
8987
|
}
|
|
8941
8988
|
if (!callerFilePath)
|
|
8942
|
-
return
|
|
8989
|
+
return getPrimaryProjectRoot();
|
|
8943
8990
|
const root = identifyProjectRoot(callerFilePath);
|
|
8944
8991
|
return root;
|
|
8945
8992
|
}
|
|
@@ -9864,7 +9911,7 @@ class EnvApi {
|
|
|
9864
9911
|
Object.defineProperty(process, "env", {
|
|
9865
9912
|
value: envShield,
|
|
9866
9913
|
writable: false,
|
|
9867
|
-
configurable:
|
|
9914
|
+
configurable: false,
|
|
9868
9915
|
enumerable: true,
|
|
9869
9916
|
});
|
|
9870
9917
|
}
|
|
@@ -26868,8 +26915,9 @@ class XStatic {
|
|
|
26868
26915
|
const cleanRelative = relativePath.startsWith("/")
|
|
26869
26916
|
? relativePath.substring(1)
|
|
26870
26917
|
: relativePath;
|
|
26871
|
-
const fileName = cleanRelative.split("/").pop() || "";
|
|
26872
26918
|
// 2. Dotfile & Restricted File Protection (Global Policy)
|
|
26919
|
+
// Check every segment of cleanRelative to prevent /.git/config traversal
|
|
26920
|
+
const segments = cleanRelative.split("/").filter(Boolean);
|
|
26873
26921
|
const dotfileConfig = this.globalConfig.dotfiles || "deny";
|
|
26874
26922
|
const dotfileMode = typeof dotfileConfig === "object"
|
|
26875
26923
|
? dotfileConfig.mode
|
|
@@ -26878,12 +26926,10 @@ class XStatic {
|
|
|
26878
26926
|
? dotfileConfig.custom || []
|
|
26879
26927
|
: [];
|
|
26880
26928
|
if (dotfileMode === "deny") {
|
|
26881
|
-
const
|
|
26882
|
-
|
|
26883
|
-
if (
|
|
26884
|
-
this.qLog.warn(
|
|
26885
|
-
// "security",
|
|
26886
|
-
`Blocked attempt to access restricted file: ${fileName}`);
|
|
26929
|
+
const hasDotfileSegment = segments.some((s) => s.startsWith("."));
|
|
26930
|
+
const hasCustomRestricted = segments.some((s) => customRestricted.includes(s));
|
|
26931
|
+
if (hasDotfileSegment || hasCustomRestricted) {
|
|
26932
|
+
this.qLog.warn(`Blocked attempt to access restricted file or directory in path: ${cleanRelative}`);
|
|
26887
26933
|
res.status(403).end("Forbidden: Access Denied");
|
|
26888
26934
|
return next();
|
|
26889
26935
|
}
|
|
@@ -26897,15 +26943,20 @@ class XStatic {
|
|
|
26897
26943
|
if (!options.allowOutsideRoot &&
|
|
26898
26944
|
!options.unsafe &&
|
|
26899
26945
|
projectRoot) {
|
|
26900
|
-
|
|
26946
|
+
const relProject = this.sys.path.relative(projectRoot, rootDir);
|
|
26947
|
+
const isInsideProject = !relProject.startsWith("..") && !this.sys.path.isAbsolute(relProject);
|
|
26948
|
+
if (!isInsideProject && rootDir !== projectRoot) {
|
|
26901
26949
|
this.qLog.warn(`Blocked attempt to serve directory outside project root: ${rootDir}`);
|
|
26902
26950
|
res.status(403).end("Forbidden: Project Root Violation");
|
|
26903
26951
|
return next();
|
|
26904
26952
|
}
|
|
26905
26953
|
}
|
|
26906
26954
|
// Check 2: Is the requested file inside the target directory? (Directory Jail Protection)
|
|
26955
|
+
// Strict separator check prevents sibling directory traversal (e.g. /public_backup matching /public)
|
|
26907
26956
|
if (!options.allowOutsideDir && !options.unsafe) {
|
|
26908
|
-
|
|
26957
|
+
const relTarget = this.sys.path.relative(rootDir, resolvedPath);
|
|
26958
|
+
const isInsideTarget = !relTarget.startsWith("..") && !this.sys.path.isAbsolute(relTarget);
|
|
26959
|
+
if (!isInsideTarget && resolvedPath !== rootDir) {
|
|
26909
26960
|
this.qLog.warn(`Blocked attempt to access file outside static target directory: ${resolvedPath}`);
|
|
26910
26961
|
res.status(403).end("Forbidden: Sandbox Violation");
|
|
26911
26962
|
return next();
|
|
@@ -38658,7 +38709,7 @@ class MultiServerApp {
|
|
|
38658
38709
|
* ```
|
|
38659
38710
|
*
|
|
38660
38711
|
* @see {@link https://xypriss.nehonix.com/docs/getting-started} Getting Started Guide
|
|
38661
|
-
* @see {@link https://xypriss.nehonix.com/docs/
|
|
38712
|
+
* @see {@link https://xypriss.nehonix.com/docs/config/api} Configuration Reference
|
|
38662
38713
|
*/
|
|
38663
38714
|
function createServer(options = {}) {
|
|
38664
38715
|
// --- SECURITY: Internal Options Protection ---
|
|
@@ -38777,15 +38828,15 @@ class PluginAPI {
|
|
|
38777
38828
|
if (!sys || !sys.__root__) {
|
|
38778
38829
|
throw new Error("XyPriss Security Error: The provided system core instance is invalid or lacks an authorized project root association.");
|
|
38779
38830
|
}
|
|
38780
|
-
const manifestPath =
|
|
38781
|
-
if (!
|
|
38831
|
+
const manifestPath = path.join(sys.__root__, "package.json");
|
|
38832
|
+
if (!fs.existsSync(manifestPath)) {
|
|
38782
38833
|
throw new Error(`XyPriss I/O Error: Unable to access project manifest at "${manifestPath}". Verify that the file exists and is readable.`);
|
|
38783
38834
|
}
|
|
38784
38835
|
try {
|
|
38785
|
-
return
|
|
38836
|
+
return JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
|
|
38786
38837
|
}
|
|
38787
38838
|
catch (err) {
|
|
38788
|
-
throw new Error(`XyPriss
|
|
38839
|
+
throw new Error(`XyPriss JSON Error: Failed to parse project manifest at "${manifestPath}": ${err.message}`);
|
|
38789
38840
|
}
|
|
38790
38841
|
}
|
|
38791
38842
|
/**
|