GWM : csrf additional conditions
This commit is contained in:
parent
4f5ecedb8f
commit
36e2c1f49b
20
server.js
20
server.js
@ -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);
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user