xypriss 9.14.20 → 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 +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/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
|
-
if (pkg.name && pkg.version)
|
|
8847
|
-
return true;
|
|
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;
|
|
8848
8874
|
}
|
|
8875
|
+
const manifest = getPluginsManifest();
|
|
8876
|
+
if (manifest?.roots && manifest.roots[resolved]) {
|
|
8877
|
+
return true;
|
|
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
|
}
|
|
@@ -26845,8 +26892,9 @@ class XStatic {
|
|
|
26845
26892
|
const cleanRelative = relativePath.startsWith("/")
|
|
26846
26893
|
? relativePath.substring(1)
|
|
26847
26894
|
: relativePath;
|
|
26848
|
-
const fileName = cleanRelative.split("/").pop() || "";
|
|
26849
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);
|
|
26850
26898
|
const dotfileConfig = this.globalConfig.dotfiles || "deny";
|
|
26851
26899
|
const dotfileMode = typeof dotfileConfig === "object"
|
|
26852
26900
|
? dotfileConfig.mode
|
|
@@ -26855,12 +26903,10 @@ class XStatic {
|
|
|
26855
26903
|
? dotfileConfig.custom || []
|
|
26856
26904
|
: [];
|
|
26857
26905
|
if (dotfileMode === "deny") {
|
|
26858
|
-
const
|
|
26859
|
-
|
|
26860
|
-
if (
|
|
26861
|
-
this.qLog.warn(
|
|
26862
|
-
// "security",
|
|
26863
|
-
`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}`);
|
|
26864
26910
|
res.status(403).end("Forbidden: Access Denied");
|
|
26865
26911
|
return next();
|
|
26866
26912
|
}
|
|
@@ -26874,15 +26920,20 @@ class XStatic {
|
|
|
26874
26920
|
if (!options.allowOutsideRoot &&
|
|
26875
26921
|
!options.unsafe &&
|
|
26876
26922
|
projectRoot) {
|
|
26877
|
-
|
|
26923
|
+
const relProject = this.sys.path.relative(projectRoot, rootDir);
|
|
26924
|
+
const isInsideProject = !relProject.startsWith("..") && !this.sys.path.isAbsolute(relProject);
|
|
26925
|
+
if (!isInsideProject && rootDir !== projectRoot) {
|
|
26878
26926
|
this.qLog.warn(`Blocked attempt to serve directory outside project root: ${rootDir}`);
|
|
26879
26927
|
res.status(403).end("Forbidden: Project Root Violation");
|
|
26880
26928
|
return next();
|
|
26881
26929
|
}
|
|
26882
26930
|
}
|
|
26883
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)
|
|
26884
26933
|
if (!options.allowOutsideDir && !options.unsafe) {
|
|
26885
|
-
|
|
26934
|
+
const relTarget = this.sys.path.relative(rootDir, resolvedPath);
|
|
26935
|
+
const isInsideTarget = !relTarget.startsWith("..") && !this.sys.path.isAbsolute(relTarget);
|
|
26936
|
+
if (!isInsideTarget && resolvedPath !== rootDir) {
|
|
26886
26937
|
this.qLog.warn(`Blocked attempt to access file outside static target directory: ${resolvedPath}`);
|
|
26887
26938
|
res.status(403).end("Forbidden: Sandbox Violation");
|
|
26888
26939
|
return next();
|
|
@@ -38635,7 +38686,7 @@ class MultiServerApp {
|
|
|
38635
38686
|
* ```
|
|
38636
38687
|
*
|
|
38637
38688
|
* @see {@link https://xypriss.nehonix.com/docs/getting-started} Getting Started Guide
|
|
38638
|
-
* @see {@link https://xypriss.nehonix.com/docs/
|
|
38689
|
+
* @see {@link https://xypriss.nehonix.com/docs/config/api} Configuration Reference
|
|
38639
38690
|
*/
|
|
38640
38691
|
function createServer(options = {}) {
|
|
38641
38692
|
// --- SECURITY: Internal Options Protection ---
|
|
@@ -38754,15 +38805,15 @@ class PluginAPI {
|
|
|
38754
38805
|
if (!sys || !sys.__root__) {
|
|
38755
38806
|
throw new Error("XyPriss Security Error: The provided system core instance is invalid or lacks an authorized project root association.");
|
|
38756
38807
|
}
|
|
38757
|
-
const manifestPath =
|
|
38758
|
-
if (!
|
|
38808
|
+
const manifestPath = path__default.join(sys.__root__, "package.json");
|
|
38809
|
+
if (!fs__default.existsSync(manifestPath)) {
|
|
38759
38810
|
throw new Error(`XyPriss I/O Error: Unable to access project manifest at "${manifestPath}". Verify that the file exists and is readable.`);
|
|
38760
38811
|
}
|
|
38761
38812
|
try {
|
|
38762
|
-
return
|
|
38813
|
+
return JSON.parse(fs__default.readFileSync(manifestPath, "utf-8"));
|
|
38763
38814
|
}
|
|
38764
38815
|
catch (err) {
|
|
38765
|
-
throw new Error(`XyPriss
|
|
38816
|
+
throw new Error(`XyPriss JSON Error: Failed to parse project manifest at "${manifestPath}": ${err.message}`);
|
|
38766
38817
|
}
|
|
38767
38818
|
}
|
|
38768
38819
|
/**
|