adminizer 4.3.0-build.137 → 4.3.0-build.139
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.
|
@@ -17,13 +17,19 @@ 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
|
+
if (!csrfCookie || !csrfHeader || csrfCookie !== csrfHeader) {
|
|
28
|
+
return res.status(403).json({
|
|
29
|
+
message: 'Invalid CSRF token',
|
|
30
|
+
type: 'csrf_error'
|
|
31
|
+
});
|
|
32
|
+
}
|
|
27
33
|
}
|
|
28
34
|
}
|
|
29
35
|
}
|
|
@@ -129,4 +135,17 @@ const inertiaExpressAdapter = function ({ version, html, flashMessages, enableRe
|
|
|
129
135
|
return next();
|
|
130
136
|
};
|
|
131
137
|
};
|
|
138
|
+
// Вспомогательная функция для определения API routes
|
|
139
|
+
function isApiRequest(req) {
|
|
140
|
+
const adminizer = req.adminizer;
|
|
141
|
+
if (!adminizer?.config?.cors?.enabled) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
const corsConfig = adminizer.config.cors;
|
|
145
|
+
const routePrefix = adminizer.config.routePrefix || '';
|
|
146
|
+
// Создаем базовый путь для API
|
|
147
|
+
const apiBasePath = `${routePrefix}/${corsConfig.path?.replace('*', '')}`;
|
|
148
|
+
// Проверяем начинается ли путь с API base path
|
|
149
|
+
return req.path.startsWith(apiBasePath);
|
|
150
|
+
}
|
|
132
151
|
export default inertiaExpressAdapter;
|