SamDecrock / node-http-ntlm

Node.js module to authenticate using HTTP NTLM
MIT License
192 stars 89 forks source link

callback is not a function in ntlm.js:106 #48

Closed jackgeek closed 7 years ago

jackgeek commented 8 years ago

When using to connect to an application served by IIS, after an IISRESET it fails with the following exception the first few times I try to connect:

C:\TFS\Dev-UI\WebApp\Src\Web\Web\node_modules\httpntlm\ntlm.js:106
                return callback(new Error("Couldn't find NTLM in the message type2 comming from the server"));
                       ^

TypeError: callback is not a function
    at Object.parseType2Message (C:\TFS\Dev-UI\WebApp\Src\Web\Web\node_modules\httpntlm\ntlm.js:106:10)
    at sendType3Message (C:\TFS\Dev-UI\WebApp\Src\Web\Web\node_modules\httpntlm\httpntlm.js:66:23)
    at Immediate._onImmediate (C:\TFS\Dev-UI\WebApp\Src\Web\Web\node_modules\httpntlm\httpntlm.js:93:4)
    at processImmediate [as _immediateCallback] (timers.js:383:17)
amirgon commented 8 years ago

This is a real problem. It crashes node.js when it occurs. The problem is as following: On sendType3Message function, parseType2Message is called without the second parameter, which is the callback:

        // parse type2 message from server:
        var type2msg = ntlm.parseType2Message(res.headers['www-authenticate']);

while parseType2Message function is declared as:

function parseType2Message(rawmsg, callback){
    var match = rawmsg.match(/NTLM (.+)?/);
    if(!match || !match[1])
        return callback(new Error("Couldn't find NTLM in the message type2 comming from the server"));

and callback is called while it's undefined.

It's not clear to me how this error should be handled, but it definitely shouldn't crash the application as it does now.