xypriss 9.15.0 → 9.15.2
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 +210 -12
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +210 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +48 -2
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1167,7 +1167,7 @@ const DEFAULT_OPTIONS = {
|
|
|
1167
1167
|
enabled: false,
|
|
1168
1168
|
},
|
|
1169
1169
|
cluster: {
|
|
1170
|
-
enabled:
|
|
1170
|
+
enabled: true, // Disabled by default for single-process mode
|
|
1171
1171
|
workers: "auto",
|
|
1172
1172
|
autoRespawn: true,
|
|
1173
1173
|
mode: "synapx-dispatcher",
|
|
@@ -1933,6 +1933,8 @@ function canonicalizePath(filePath) {
|
|
|
1933
1933
|
function isEngineCorePath(filePath) {
|
|
1934
1934
|
if (!filePath || !ENGINE_CORE_DIR)
|
|
1935
1935
|
return false;
|
|
1936
|
+
if (filePath === "<engine-core>")
|
|
1937
|
+
return true;
|
|
1936
1938
|
const canonical = canonicalizePath(filePath);
|
|
1937
1939
|
// Canonical match for ENGINE_CORE_DIR itself (with or without trailing slash)
|
|
1938
1940
|
const normCore = canonicalizePath(ENGINE_CORE_DIR);
|
|
@@ -7407,7 +7409,9 @@ class FSBase extends PathApi {
|
|
|
7407
7409
|
const baseRoot = runnerRoot || this.assignedRoot;
|
|
7408
7410
|
const caller = getVerifiedCallerInfo();
|
|
7409
7411
|
// If the verified application caller is genuine engine core, allow direct access
|
|
7410
|
-
if (caller.callerFile &&
|
|
7412
|
+
if (caller.callerFile &&
|
|
7413
|
+
(caller.callerFile === "<engine-core>" ||
|
|
7414
|
+
isEngineCorePath(caller.callerFile))) {
|
|
7411
7415
|
if (path.isAbsolute(targetPath)) {
|
|
7412
7416
|
return path.resolve(targetPath);
|
|
7413
7417
|
}
|
|
@@ -18404,6 +18408,181 @@ if (typeof globalThis !== "undefined") {
|
|
|
18404
18408
|
/** Global singleton instance of the system. */
|
|
18405
18409
|
const __sys__$1 = globalThis.__sys__;
|
|
18406
18410
|
|
|
18411
|
+
/**
|
|
18412
|
+
* XyPriss ProtoShield — Anti-Prototype Pollution Protection Engine
|
|
18413
|
+
*
|
|
18414
|
+
* Fortifies the V8 / JavaScriptCore runtime environment against Prototype Pollution attacks:
|
|
18415
|
+
* 1. Blocks unauthorized additions and mutations to `Object.prototype`, `Array.prototype`, and `Function.prototype`.
|
|
18416
|
+
* 2. Neutralizes mutable `__proto__` accessors exploited by recursive merge/patch vectors.
|
|
18417
|
+
* 3. Enforces strict boot-time configuration schema validation for `xypriss.config.json(c)`.
|
|
18418
|
+
*
|
|
18419
|
+
* @module server/utils/ProtoShield
|
|
18420
|
+
* @see https://xypriss.nehonix.com/docs/security/protoshield
|
|
18421
|
+
*/
|
|
18422
|
+
class ProtoShield {
|
|
18423
|
+
static isInitialized = false;
|
|
18424
|
+
static activeConfig = null;
|
|
18425
|
+
/**
|
|
18426
|
+
* Validates raw JSON configuration from `xypriss.config.json(c)` at boot time.
|
|
18427
|
+
* Throws an explicit, descriptive error if any property is invalid.
|
|
18428
|
+
*/
|
|
18429
|
+
static validateConfig(raw) {
|
|
18430
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
18431
|
+
throw new Error(`[XyPriss Validation Error] '$protoShield' must be a valid JSON object in xypriss.config.json(c). Received: ${typeof raw}`);
|
|
18432
|
+
}
|
|
18433
|
+
const allowedKeys = new Set([
|
|
18434
|
+
"enabled",
|
|
18435
|
+
"mode",
|
|
18436
|
+
"neutralizeProto",
|
|
18437
|
+
"freezePrototypes",
|
|
18438
|
+
"allowedProperties",
|
|
18439
|
+
]);
|
|
18440
|
+
for (const key of Object.keys(raw)) {
|
|
18441
|
+
if (!allowedKeys.has(key)) {
|
|
18442
|
+
throw new Error(`[XyPriss Validation Error] Unknown property '$protoShield.${key}' in xypriss.config.json(c). Allowed properties: ${[...allowedKeys].map((k) => `'${k}'`).join(", ")}`);
|
|
18443
|
+
}
|
|
18444
|
+
}
|
|
18445
|
+
if (raw.enabled !== undefined && typeof raw.enabled !== "boolean") {
|
|
18446
|
+
throw new Error(`[XyPriss Validation Error] '$protoShield.enabled' must be a boolean. Received: ${typeof raw.enabled} (${JSON.stringify(raw.enabled)})`);
|
|
18447
|
+
}
|
|
18448
|
+
if (raw.mode !== undefined) {
|
|
18449
|
+
const acceptedModes = ["block", "warn", "freeze"];
|
|
18450
|
+
if (!acceptedModes.includes(raw.mode)) {
|
|
18451
|
+
throw new Error(`[XyPriss Validation Error] Invalid '$protoShield.mode': ${JSON.stringify(raw.mode)}. Accepted values are: 'block', 'warn', 'freeze'.`);
|
|
18452
|
+
}
|
|
18453
|
+
}
|
|
18454
|
+
if (raw.neutralizeProto !== undefined &&
|
|
18455
|
+
typeof raw.neutralizeProto !== "boolean") {
|
|
18456
|
+
throw new Error(`[XyPriss Validation Error] '$protoShield.neutralizeProto' must be a boolean. Received: ${typeof raw.neutralizeProto}`);
|
|
18457
|
+
}
|
|
18458
|
+
if (raw.freezePrototypes !== undefined &&
|
|
18459
|
+
typeof raw.freezePrototypes !== "boolean") {
|
|
18460
|
+
throw new Error(`[XyPriss Validation Error] '$protoShield.freezePrototypes' must be a boolean. Received: ${typeof raw.freezePrototypes}`);
|
|
18461
|
+
}
|
|
18462
|
+
if (raw.allowedProperties !== undefined) {
|
|
18463
|
+
if (!Array.isArray(raw.allowedProperties)) {
|
|
18464
|
+
throw new Error(`[XyPriss Validation Error] '$protoShield.allowedProperties' must be an array of strings. Received: ${typeof raw.allowedProperties}`);
|
|
18465
|
+
}
|
|
18466
|
+
for (let i = 0; i < raw.allowedProperties.length; i++) {
|
|
18467
|
+
const item = raw.allowedProperties[i];
|
|
18468
|
+
if (typeof item !== "string" || !item.trim()) {
|
|
18469
|
+
throw new Error(`[XyPriss Validation Error] '$protoShield.allowedProperties[${i}]' must be a non-empty string. Received: ${JSON.stringify(item)}`);
|
|
18470
|
+
}
|
|
18471
|
+
}
|
|
18472
|
+
}
|
|
18473
|
+
return {
|
|
18474
|
+
enabled: raw.enabled !== undefined ? raw.enabled : true,
|
|
18475
|
+
mode: raw.mode || "block",
|
|
18476
|
+
neutralizeProto: raw.neutralizeProto !== undefined ? raw.neutralizeProto : true,
|
|
18477
|
+
freezePrototypes: raw.freezePrototypes !== undefined
|
|
18478
|
+
? raw.freezePrototypes
|
|
18479
|
+
: false,
|
|
18480
|
+
allowedProperties: Array.isArray(raw.allowedProperties)
|
|
18481
|
+
? [...raw.allowedProperties]
|
|
18482
|
+
: [],
|
|
18483
|
+
};
|
|
18484
|
+
}
|
|
18485
|
+
/**
|
|
18486
|
+
* Bootstraps the ProtoShield defense according to the validated configuration.
|
|
18487
|
+
*/
|
|
18488
|
+
static initialize(rawConfig) {
|
|
18489
|
+
if (this.isInitialized)
|
|
18490
|
+
return;
|
|
18491
|
+
const config = this.validateConfig(rawConfig);
|
|
18492
|
+
this.activeConfig = config;
|
|
18493
|
+
if (!config.enabled) {
|
|
18494
|
+
this.isInitialized = true;
|
|
18495
|
+
return;
|
|
18496
|
+
}
|
|
18497
|
+
const allowedSet = new Set([...config.allowedProperties, "__proto__"]);
|
|
18498
|
+
// 1. Neutralize mutable __proto__ accessor if enabled (done before strict interception)
|
|
18499
|
+
if (config.neutralizeProto) {
|
|
18500
|
+
this.applyNeutralizeProto(config.mode);
|
|
18501
|
+
}
|
|
18502
|
+
// 2. Intercept explicit property definitions on core prototypes
|
|
18503
|
+
this.applyPropertyInterception(allowedSet, config.mode);
|
|
18504
|
+
// 3. Prevent dynamic property expansion or enforce total immutability
|
|
18505
|
+
if (config.mode === "freeze" || config.freezePrototypes) {
|
|
18506
|
+
try {
|
|
18507
|
+
Object.freeze(Object.prototype);
|
|
18508
|
+
Object.freeze(Array.prototype);
|
|
18509
|
+
Object.freeze(Function.prototype);
|
|
18510
|
+
}
|
|
18511
|
+
catch { }
|
|
18512
|
+
}
|
|
18513
|
+
else if (config.mode === "block") {
|
|
18514
|
+
try {
|
|
18515
|
+
Object.preventExtensions(Object.prototype);
|
|
18516
|
+
}
|
|
18517
|
+
catch { }
|
|
18518
|
+
}
|
|
18519
|
+
this.isInitialized = true;
|
|
18520
|
+
}
|
|
18521
|
+
/**
|
|
18522
|
+
* Intercepts `Object.defineProperty` on base prototypes to thwart unauthorized extension.
|
|
18523
|
+
*/
|
|
18524
|
+
static applyPropertyInterception(allowed, mode) {
|
|
18525
|
+
const origDefineProperty = Object.defineProperty;
|
|
18526
|
+
const targetPrototypes = [
|
|
18527
|
+
Object.prototype,
|
|
18528
|
+
Array.prototype,
|
|
18529
|
+
Function.prototype,
|
|
18530
|
+
];
|
|
18531
|
+
Object.defineProperty = function (target, propertyKey, attributes) {
|
|
18532
|
+
if (targetPrototypes.includes(target)) {
|
|
18533
|
+
const propStr = String(propertyKey);
|
|
18534
|
+
if (!allowed.has(propStr)) {
|
|
18535
|
+
const message = `[XyPriss ProtoShield] Blocked Prototype Pollution attempt! Unauthorized property '${propStr}' on ${target?.constructor?.name || "Object"}.prototype`;
|
|
18536
|
+
if (mode === "warn") {
|
|
18537
|
+
console.warn(`\x1b[33m${message}\x1b[0m\n` +
|
|
18538
|
+
(new Error().stack || ""));
|
|
18539
|
+
}
|
|
18540
|
+
else {
|
|
18541
|
+
const err = new TypeError(message);
|
|
18542
|
+
console.error(`\x1b[31m${message}\x1b[0m\n` + (err.stack || ""));
|
|
18543
|
+
throw err;
|
|
18544
|
+
}
|
|
18545
|
+
}
|
|
18546
|
+
}
|
|
18547
|
+
return origDefineProperty.call(Object, target, propertyKey, attributes);
|
|
18548
|
+
};
|
|
18549
|
+
}
|
|
18550
|
+
/**
|
|
18551
|
+
* Intercepts and neutralizes the mutable `__proto__` setter on `Object.prototype`.
|
|
18552
|
+
*/
|
|
18553
|
+
static applyNeutralizeProto(mode) {
|
|
18554
|
+
try {
|
|
18555
|
+
const origDesc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__");
|
|
18556
|
+
if (origDesc && origDesc.set) {
|
|
18557
|
+
Object.defineProperty(Object.prototype, "__proto__", {
|
|
18558
|
+
get() {
|
|
18559
|
+
return Object.getPrototypeOf(this);
|
|
18560
|
+
},
|
|
18561
|
+
set(_newProto) {
|
|
18562
|
+
const message = `[XyPriss ProtoShield] Blocked Prototype Mutation attempt via '__proto__'!`;
|
|
18563
|
+
if (mode === "warn") {
|
|
18564
|
+
console.warn(`\x1b[33m${message}\x1b[0m\n` +
|
|
18565
|
+
(new Error().stack || ""));
|
|
18566
|
+
}
|
|
18567
|
+
else {
|
|
18568
|
+
const err = new TypeError(message);
|
|
18569
|
+
console.error(`\x1b[31m${message}\x1b[0m\n` +
|
|
18570
|
+
(err.stack || ""));
|
|
18571
|
+
throw err;
|
|
18572
|
+
}
|
|
18573
|
+
},
|
|
18574
|
+
configurable: false,
|
|
18575
|
+
enumerable: false,
|
|
18576
|
+
});
|
|
18577
|
+
}
|
|
18578
|
+
}
|
|
18579
|
+
catch { }
|
|
18580
|
+
}
|
|
18581
|
+
static getActiveConfig() {
|
|
18582
|
+
return this.activeConfig;
|
|
18583
|
+
}
|
|
18584
|
+
}
|
|
18585
|
+
|
|
18407
18586
|
/**
|
|
18408
18587
|
* XyPriss Meta Configuration Runner
|
|
18409
18588
|
*
|
|
@@ -18444,7 +18623,10 @@ class MetaConfigRunner {
|
|
|
18444
18623
|
*/
|
|
18445
18624
|
executeMetaConfig(searchDir) {
|
|
18446
18625
|
const sys = getSysApi$1();
|
|
18447
|
-
|
|
18626
|
+
let root = searchDir || getCallerProjectRoot();
|
|
18627
|
+
if (!root || root === ENGINE_CORE_DIR) {
|
|
18628
|
+
root = getPrimaryProjectRoot() || __sys__$1.__root__;
|
|
18629
|
+
}
|
|
18448
18630
|
const metaFiles = searchDir
|
|
18449
18631
|
? [
|
|
18450
18632
|
sys.path.join(root, "+xypriss.meta.ts"),
|
|
@@ -18497,7 +18679,10 @@ class ConfigLoader {
|
|
|
18497
18679
|
* Load all xypriss.config.json files found in the project and apply configurations
|
|
18498
18680
|
*/
|
|
18499
18681
|
loadAndApplySysConfig(targetRoot) {
|
|
18500
|
-
|
|
18682
|
+
let root = targetRoot || getCallerProjectRoot();
|
|
18683
|
+
if (!root || root === ENGINE_CORE_DIR) {
|
|
18684
|
+
root = getPrimaryProjectRoot() || __sys__$1.__root__;
|
|
18685
|
+
}
|
|
18501
18686
|
if (!root || this.appliedRoots.has(root))
|
|
18502
18687
|
return;
|
|
18503
18688
|
this.appliedRoots.add(root);
|
|
@@ -18569,6 +18754,13 @@ class ConfigLoader {
|
|
|
18569
18754
|
__sys__$1.vars.update(config.$vars);
|
|
18570
18755
|
}
|
|
18571
18756
|
}
|
|
18757
|
+
// Initialize and enforce ProtoShield protection if declared ($protoShield or protoShield)
|
|
18758
|
+
const protoConfig = config?.$protoShield !== undefined
|
|
18759
|
+
? config.$protoShield
|
|
18760
|
+
: config?.protoShield;
|
|
18761
|
+
if (protoConfig !== undefined) {
|
|
18762
|
+
ProtoShield.initialize(protoConfig);
|
|
18763
|
+
}
|
|
18572
18764
|
// Apply ServerOptions sections to Configs (centralized configuration management)
|
|
18573
18765
|
const recognizedServerOptionKeys = [
|
|
18574
18766
|
"server",
|
|
@@ -18625,8 +18817,7 @@ class ConfigLoader {
|
|
|
18625
18817
|
if (config.__xfs__ && config.__xfs__.path) {
|
|
18626
18818
|
const rawPath = config.__xfs__.path;
|
|
18627
18819
|
const resolvedFsPath = this.resolvePath(rawPath, projectRoot, configDir);
|
|
18628
|
-
if (resolvedFsPath &&
|
|
18629
|
-
this.sys.fs.exist(resolvedFsPath)) {
|
|
18820
|
+
if (resolvedFsPath && this.sys.fs.exist(resolvedFsPath)) {
|
|
18630
18821
|
const specializedFS = new XyPrissFS({
|
|
18631
18822
|
__root__: resolvedFsPath,
|
|
18632
18823
|
__mode__: __sys__$1.__env__.mode,
|
|
@@ -29498,8 +29689,12 @@ class LogProcessor {
|
|
|
29498
29689
|
}
|
|
29499
29690
|
}
|
|
29500
29691
|
|
|
29692
|
+
// S = Ox53 (dec: 5*16 + 3 = 83)
|
|
29693
|
+
// N = Ox4E (dec: 4*16 + 14 = 78)
|
|
29694
|
+
// P = Ox50 (dec: 5*16 + 0 = 80)
|
|
29695
|
+
// X = Ox58 (dec: 5*16 + 8 = 88)
|
|
29501
29696
|
const MAGIC_HEADER = Buffer.from([0x53, 0x4e, 0x50, 0x58]); // "SNPX"
|
|
29502
|
-
const CURRENT_VERSION = 0x0100;
|
|
29697
|
+
const CURRENT_VERSION = 0x0100; // 1
|
|
29503
29698
|
const NONCE_SIZE = 12;
|
|
29504
29699
|
const HEADER_SIZE = 8;
|
|
29505
29700
|
/**
|
|
@@ -29572,12 +29767,14 @@ class EngineManager {
|
|
|
29572
29767
|
uniquePluginPaths.length > 0
|
|
29573
29768
|
? ["--plugins", uniquePluginPaths.join(",")]
|
|
29574
29769
|
: [];
|
|
29575
|
-
//
|
|
29770
|
+
// Strict authoritative project root resolution (Fail-Closed)
|
|
29576
29771
|
const sys = getSysApi$1();
|
|
29577
|
-
const
|
|
29578
|
-
|
|
29579
|
-
|
|
29580
|
-
|
|
29772
|
+
const sysRoot = sys?.__root__;
|
|
29773
|
+
const projectRoot = getPrimaryProjectRoot() ||
|
|
29774
|
+
(sysRoot && sysRoot !== ENGINE_CORE_DIR ? sysRoot : "");
|
|
29775
|
+
if (!projectRoot || !isProjectRoot(projectRoot)) {
|
|
29776
|
+
throw new Error(`[XyPriss Security] Fail-Closed: Cannot resolve an authoritative project root for XHSC engine.`);
|
|
29777
|
+
}
|
|
29581
29778
|
const entryPoint = process.argv[1] ||
|
|
29582
29779
|
appConfigs?.cluster?.entryPoint ||
|
|
29583
29780
|
path.join(projectRoot, "src", "server.ts");
|
|
@@ -41593,6 +41790,7 @@ exports.FLA = FileUploadAPI;
|
|
|
41593
41790
|
exports.FileUploadAPI = FileUploadAPI;
|
|
41594
41791
|
exports.Plugin = Plugin;
|
|
41595
41792
|
exports.PluginHookIds = PluginHookIds;
|
|
41793
|
+
exports.ProtoShield = ProtoShield;
|
|
41596
41794
|
exports.Router = Router;
|
|
41597
41795
|
exports.SecurityMiddleware = SecurityMiddleware;
|
|
41598
41796
|
exports.Send = Send;
|