express-ntlm返回错误的用户

时间:2019-01-28 14:51:18

标签: node.js express-ntlm

我正在使用express-ntlm在Intranet设置中获取当前用户的Windows ID。在大多数情况下,它都能正常工作,但有时会返回一个完全不同的人的ID。我猜想这可能与会话有关吗?

const ntlm = require('express-ntlm');

module.exports = app => {

  app.use(
    ntlm({
      debug: function() {
        var args = Array.prototype.slice.apply(arguments);
        console.log.apply(null, args);
      },
      domain: 'MS',
      domaincontroller: 'ldap://something.com'
    })
  );
app.post('/get-user-details/', (req, res) => {
console.log(req.ntlm.UserName); //Returns correct user most of the time, but sometimes it returns different person who open site at the same time
});

1 个答案:

答案 0 :(得分:1)

不幸的是,NTLM对连接(而不是会话)进行身份验证。过去这很好,但是不再有意义,因为浏览器倾向于一次打开多个连接以加快页面加载速度,而反向代理则共享与后端的连接。那就是问题所在:反向代理将重用到后端的已通过身份验证的连接,因此会混淆用户。为了缓解此问题,您必须确保反向代理启用了NTLM支持。

对于express-ntlm,仍然有一个open pull request,它添加了一个Keep-Alive属性,可以解决此问题,很遗憾,它尚未经过广泛测试,因此首先需要进行验证。