【问题标题】:CSRF protection on GET methods using csurf module使用 csurf 模块对 GET 方法进行 CSRF 保护
【发布时间】:2017-02-22 02:26:11
【问题描述】:

我有这个 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();
    }
  })

我是这样称呼它的,但我只是在猜测

http://localhost:31337/api/sessioncount?csrf=qudszjrT-mQ5uu4qXrQXI7C_NJYlXXUIdKB0
http://localhost:31337/api/sessioncount?_csrf=qudszjrT-mQ5uu4qXrQXI7C_NJYlXXUIdKB0
http://localhost:31337/api/sessioncount?csrfToken=qudszjrT-mQ5uu4qXrQXI7C_NJYlXXUIdKB0

【问题讨论】:

    标签: node.js csrf csrf-protection


    【解决方案1】:

    我通过改变它让它工作了

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

    【讨论】:

      猜你喜欢
      • 2017-03-19
      • 2012-03-15
      • 2022-10-17
      • 1970-01-01
      • 1970-01-01
      • 2014-02-09
      • 2015-10-15
      • 2012-09-04
      • 2016-05-19
      相关资源
      最近更新 更多