How do I generate CSRF tokens in Express?

后端 未结 4 1296
北海茫月
北海茫月 2021-02-03 13:25

newbie. I\'m using ExpressJS/Node. Here\'s my config stuff:

var express = require(\'express\'),
app = express.createServer(),
jade=require(\'jade\');
// Configu         


        
4条回答
  •  花落未央
    2021-02-03 13:51

    Add the token to dynamic helpers.

    app.dynamicHelpers({
      token: function(req, res) {
        return req.session._csrf;
      }
    });
    

    Reference it in your jade template.

    input(type='hidden', value=token)
    

    Source: http://senchalabs.github.com/connect/middleware-csrf.html

提交回复
热议问题