GWM : csrf additional conditions

This commit is contained in:
Gowtham M 2025-12-19 12:18:13 +05:30
parent 4f5ecedb8f
commit 36e2c1f49b

View File

@ -213,9 +213,29 @@ app.get("/api/csrf-token", csrfProtection, (req, res) => {
* =========================
*/
app.use((req, res, next) => {
// Allow safe methods
if (["GET", "HEAD", "OPTIONS"].includes(req.method)) {
return next();
}
// Only protect API routes
if (!req.path.startsWith("/api")) {
return next();
}
// Skip auth & public endpoints
const csrfExcludedPaths = [
"/api/auth/login",
"/api/forgot-password/request-otp",
"/api/forgot-password/verify-otp",
"/api/csrf-token",
];
if (csrfExcludedPaths.includes(req.path)) {
return next();
}
// 🔒 Enforce CSRF
return csrfProtection(req, res, next);
});