qumra-engine 2.0.161 → 2.0.163

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.
@@ -86,8 +86,13 @@ const startEngine = async ({ renderApi, mode, getRender, setRender, port = 3000,
86
86
  // app.use("/api", devRouter);
87
87
  }
88
88
  app.use((req, res, next) => {
89
- if (!(0, isPathAllowedToRender_1.isPathAllowedToRender)(res.locals.parsedUrl?.pathname || req.path)) {
90
- return res.status(404).end();
89
+ const path = res.locals.parsedUrl?.pathname || req.path;
90
+ const result = (0, isPathAllowedToRender_1.validatePathForRender)(path);
91
+ if (!result.allowed) {
92
+ return res.status(result.status).json({
93
+ success: false,
94
+ message: result.reason,
95
+ });
91
96
  }
92
97
  next();
93
98
  });
@@ -1 +1,9 @@
1
- export declare const isPathAllowedToRender: (filePath: string) => boolean;
1
+ export declare const validatePathForRender: (filePath: string) => {
2
+ allowed: boolean;
3
+ status: number;
4
+ reason: string;
5
+ } | {
6
+ allowed: boolean;
7
+ status: number;
8
+ reason?: undefined;
9
+ };
@@ -1,39 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPathAllowedToRender = void 0;
4
- const isPathAllowedToRender = (filePath) => {
5
- const lower = filePath.toLowerCase();
6
- // ممنوع أي امتداد (html/js/php/…)
7
- if (/\.[a-z0-9]+$/i.test(lower))
8
- return false;
9
- // امتدادات خطيرة للبوتات والهكر
10
- if (/\.(php|php5|php7|phtml|phar)$/i.test(lower))
11
- return false;
12
- // ❌ مسارات مشهورة للهجمات
13
- const blockedPaths = [
14
- "wp-admin",
15
- "wp-login",
16
- "xmlrpc",
17
- ".env",
18
- "config",
19
- "config.php",
20
- "adminer",
21
- "vendor",
22
- "composer.json",
23
- "composer.lock",
24
- "shell",
25
- "id_rsa",
26
- "login",
27
- "phpinfo",
28
- "server-status",
29
- "cgi-bin",
30
- "backup",
31
- "backups",
32
- "dump",
33
- "database",
34
- ];
35
- if (blockedPaths.some(p => lower.includes(p)))
36
- return false;
37
- return true;
3
+ exports.validatePathForRender = void 0;
4
+ const validatePathForRender = (filePath) => {
5
+ // نشيل أي query string
6
+ const path = filePath.split("?")[0].toLowerCase();
7
+ // whitelist بدون لمس الـ query
8
+ const whitelistRegex = /^\/($|collections$|collection$|collection\/[^\/]+$|latest$|product\/[^\/]+$|blog\/[^\/]+$|cart$|search$)/;
9
+ if (!whitelistRegex.test(path)) {
10
+ return {
11
+ allowed: false,
12
+ status: 404,
13
+ reason: "Path not allowed",
14
+ };
15
+ }
16
+ // ✔ مسموح + query مسموح
17
+ return {
18
+ allowed: true,
19
+ status: 200,
20
+ };
38
21
  };
39
- exports.isPathAllowedToRender = isPathAllowedToRender;
22
+ exports.validatePathForRender = validatePathForRender;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qumra-engine",
3
- "version": "2.0.161",
3
+ "version": "2.0.163",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {