Well i am building simple nodejs cms. My question is simple how can i make automatic CSRF protection? Because i think its dangerous and i can miss this protection in form or route. Is there any way how to automatize this proccess?
At this moment i am using this.
Routes.js
// CSRF
var csrfProtection = csrf({
cookie: true
})
var parseForm = bodyParser.urlencoded({
extended: false
})
// Register
router.get("/register", csrfProtection, shouldNotBeAuthenticated, function (req, res) {
res.render("../modules/users/views/register", {
title: 'Register',
csrfToken: req.csrfToken
});
});
router.post("/register", parseForm, csrfProtection, authController.user_reigster);
Form
<form method="post" action="/users/register">
<input type="hidden" name="_csrf" value="{{csrfToken}}">
package CSURF.
Thank for any advice.