Node.js 使用csurf模块的GET方法上的CSRF保护

Node.js 使用csurf模块的GET方法上的CSRF保护,node.js,csrf,csrf-protection,Node.js,Csrf,Csrf Protection,我有这个GET端点,但我不知道如何调用它。我总是得到无效的csrf令牌。我的POST端点工作得很好。我没有任何问题。我只对GET端点有问题 const csrf = require('csurf'); router.route('/sessioncount') .get(csrf({ ignoreMethods: [] }), (req, res, next) => { sess = req.session; if (sess.authenticated) {

我有这个GET端点,但我不知道如何调用它。我总是得到无效的csrf令牌。我的POST端点工作得很好。我没有任何问题。我只对GET端点有问题

const csrf = require('csurf');

router.route('/sessioncount')
  .get(csrf({ ignoreMethods: [] }), (req, res, next) => {
    sess = req.session;
    if (sess.authenticated) {
      if (sess.views) {
        sess.views++;
        res.setHeader('Content-Type', 'text/html');
        res.write('<p>Session views: ' + sess.views + '</p>');
        res.end();
      } else {
        sess.views = 1;
        res.end('Welcome, you are logged in!');
      }
    } else {
      res.setHeader('Content-Type', 'text/html');
      res.write('<p>You are not allowed to view this page. Please <a href="/api/form">log in</a></p>');
      res.end();
    }
  })

我通过改变这个使它工作

// const csrfProtection = csrf({ cookie: true });
const csrfProtection = csrf();
// const csrfProtection = csrf({ cookie: true });
const csrfProtection = csrf();