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 +1 -0
- package/index.js +1 -0
- package/lib/inertia/inertiaAdapter.js +31 -6
- package/package.json +1 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -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
|
-
//
|
|
20
|
+
// Проверяем CSRF только для не-GET запросов И не-API routes
|
|
21
21
|
if (!['GET', 'HEAD', 'OPTIONS'].includes(req.method)) {
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
if (!
|
|
25
|
-
|
|
26
|
-
|
|
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;
|