adminizer 4.3.0-build.136 → 4.3.0-build.138

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/index.d.ts CHANGED
@@ -29,3 +29,4 @@ export * from "./migrations";
29
29
  export * from "./system/bindNavigation";
30
30
  export * from "./lib/helper/jwt";
31
31
  export * from "./lib/notifications/AbstractNotificationService";
32
+ export * from "./lib/POWCaptcha";
package/index.js CHANGED
@@ -29,3 +29,4 @@ export * from "./migrations";
29
29
  export * from "./system/bindNavigation";
30
30
  export * from "./lib/helper/jwt";
31
31
  export * from "./lib/notifications/AbstractNotificationService";
32
+ export * from "./lib/POWCaptcha";
@@ -17,13 +17,25 @@ const inertiaExpressAdapter = function ({ version, html, flashMessages, enableRe
17
17
  secure: process.env.NODE_ENV === 'production' && process.env.CSRF_COOKIE_INSECURE !== '1',
18
18
  sameSite: 'lax',
19
19
  });
20
- // Check CSRF token for non-GET requests
20
+ // Проверяем CSRF только для не-GET запросов И не-API routes
21
21
  if (!['GET', 'HEAD', 'OPTIONS'].includes(req.method)) {
22
- const csrfCookie = req.cookies['XSRF-TOKEN'];
23
- const csrfHeader = req.headers[csrf.headerName || 'x-xsrf-token'];
24
- if (!csrfCookie || !csrfHeader || csrfCookie !== csrfHeader) {
25
- res.status(403).send({ message: 'Invalid CSRF token' });
26
- return;
22
+ // Определяем API route через adminizer config
23
+ const isApiRoute = isApiRequest(req);
24
+ if (!isApiRoute) {
25
+ const csrfCookie = req.cookies['XSRF-TOKEN'];
26
+ const csrfHeader = req.headers[csrf.headerName || 'x-xsrf-token'];
27
+ console.log('CSRF Check for non-API route:', {
28
+ path: req.path,
29
+ cookie: csrfCookie ? 'present' : 'missing',
30
+ header: csrfHeader ? 'present' : 'missing',
31
+ match: csrfCookie === csrfHeader
32
+ });
33
+ if (!csrfCookie || !csrfHeader || csrfCookie !== csrfHeader) {
34
+ return res.status(403).json({
35
+ message: 'Invalid CSRF token',
36
+ type: 'csrf_error'
37
+ });
38
+ }
27
39
  }
28
40
  }
29
41
  }
@@ -129,4 +141,17 @@ const inertiaExpressAdapter = function ({ version, html, flashMessages, enableRe
129
141
  return next();
130
142
  };
131
143
  };
144
+ // Вспомогательная функция для определения API routes
145
+ function isApiRequest(req) {
146
+ const adminizer = req.adminizer;
147
+ if (!adminizer?.config?.cors?.enabled) {
148
+ return false;
149
+ }
150
+ const corsConfig = adminizer.config.cors;
151
+ const routePrefix = adminizer.config.routePrefix || '';
152
+ // Создаем базовый путь для API
153
+ const apiBasePath = `${routePrefix}/${corsConfig.path?.replace('*', '')}`;
154
+ // Проверяем начинается ли путь с API base path
155
+ return req.path.startsWith(apiBasePath);
156
+ }
132
157
  export default inertiaExpressAdapter;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adminizer",
3
3
  "type": "module",
4
- "version": "4.3.0-build.136",
4
+ "version": "4.3.0-build.138",
5
5
  "main": "index.js",
6
6
  "exports": {
7
7
  ".": "./index.js",