使用Lusca的hackathon-starter – 在哪里计算/存储csrf值?

我对Node很新,所以请原谅我,如果这是一个简单的问题。 我试图在github上使用转换这个项目来使用ejs的意见,但努力了解他们是如何创buildcsrf令牌。

我正在使用的种子项目 – https://github.com/sahat/hackathon-starter

使用lusca生成csrf https://github.com/krakenjs/lusca

我在他们的种子项目中看到的代码(至less我认为是相关的)

var csrf = require('lusca').csrf(); /** * CSRF whitelist. */ //app.js var csrfExclude = ['/url1', '/url2']; //original project uses jade app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); //i'm going to change this to ejs, but don't know where to get the csrf value(below) from app.use(function(req, res, next) { // CSRF protection. if (_.contains(csrfExclude, req.path)) return next(); csrf(req, res, next); }); app.use(function(req, res, next) { // Make user object available in templates. res.locals.user = req.user; next(); }); app.use(function(req, res, next) { // Remember original destination before login. var path = req.path.split('/')[1]; if (/auth|login|logout|signup|fonts|favicon/i.test(path)) { return next(); } req.session.returnTo = req.path; next(); }); //route controllers app.get('/', homeController.index); //in separate controller file - home.js exports.index = function(req, res) { res.render('home', { title: 'Home' }); }; //inside their jade file - this is converted to html tag --- <meta name="csrf-token" content="cRcgih7Vl1Ms2Xz0zgIeAyWwQm6s4kp3/8OS4="> meta(name='csrf-token', content=_csrf) //so value _csrf is converted to cRcgih7Vl1Ms2Xz0zgIeAyWwQm6s4kp3/8OS4= 

我的困惑是_csrf标签被从哪里拉出来? 我试图通过所有的文件grep的关键工作,并没有真正看到它设置任何地方(可能会丢失的东西?)。 我正在查看我的检查员,并能够看到一个会话variables被设置为req.session._csrfSecret = nLzJqL3YIAJVzA ==,但是这看起来不像上面使用的那样。 基于/ 8OS4,我认为这个值实际上是连接在一起的。

我的问题是 – 在玉石模板中,这个_csrf值是从哪里来的? 我没有看到玉在哪里从js代码抓住它(我没有看到_csrf设置在任何地方的响应)。

或者使用lusca创build和保存csrf值的正常方法是什么?

谢谢你的帮助!

我正在准备回答这个问题,但看起来有人打我: https : //groups.google.com/forum/# ! topic/nodejs/Zwnw4wOAtxw 。 只要发布这个以防其他人需要帮助。