Registry / auth-security / express-ntlm

express-ntlm

JSON →
library2.7.0jsnpmunverified

Express middleware for NTLM authentication in Node.js. Current stable version 2.7.0. Maintained as of 2023. It provides NTLM authentication for Express apps, supporting both NTLMv1 and NTLMv2, with optional LDAP validation. Compared to alternatives like passport-ntlm, express-ntlm is simpler and does not require Passport.js. It handles NTLM negotiation, extracts user info (username, domain, workstation), and can validate against Active Directory via LDAP. Known issues with proxies and multiple users on same connection.

npm install express-ntlm
INSTALL
IMPORT
SIG · EXPRESS-NTLM
E
express-ntlm
auth-securityjavascriptv2.7.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const ntlm = require('express-ntlm');
The module exports a single function. Use with Express middleware.
default
import ntlm from 'express-ntlm';
import ntlm from 'express-ntlm'; // use with ES module imports (if your project uses type: module)
ESM import works if package.json has 'type': 'module' or using .mjs.
ntlm (as middleware)
app.use(ntlm({ domain: 'DOMAIN', domaincontroller: 'ldap://dc.example.com' }));
app.use(ntlm); // missing options
The middleware requires an options object. At minimum, domain and domaincontroller are required for validation.

Sets up an Express server with NTLM authentication middleware, requiring LDAP domain controller.

const express = require('express'); const ntlm = require('express-ntlm'); const app = express(); // NTLM authentication middleware app.use(ntlm({ debug: (...args) => console.log(...args), domain: 'MYDOMAIN', domaincontroller: 'ldap://myad.example', })); app.all('*', (req, res) => { res.end(JSON.stringify(req.ntlm)); }); app.listen(3000, () => console.log('Server running on port 3000'));
Debug
Known issues
breakingUpgrading from v1.0: The fields for username, domain and workstation have different names: `UserName`, `DomainName`, `Workstation`.
fix
Update property names in your code from req.ntlm.username to req.ntlm.UserName, etc.
affects: >=1.0.0 <2.0.0
gotchaNTLM authenticates the TCP connection, not HTTP session. Behind a reverse proxy, multiple users may share the same connection, causing user mixup.
fix
Use connection-pinning (e.g., nginx ip_hash) or custom reverse proxy with session sharing.
affects: >=1.0.0
gotchaWithout validation (no domaincontroller), the middleware will accept any NTLM response, including fake ones. Security risk.
fix
Always provide a domaincontroller for LDAP validation in production.
affects: >=1.0.0
deprecatedOld method for NTLM without proxy (NTLM_No_Proxy) is deprecated; use the standard options.
fix
Use the standard middleware options; NTLM_No_Proxy is removed.
affects: >=2.5.0
Errors
Common errors & fixes
TypeError: Cannot read property 'authenticate' of null
The module could not extract NTLM type 2 or type 3 messages; often due to malformed NTLM headers.
fix
Ensure the client sends proper NTLM authentication; verify network setup and proxy configuration.
Error: connect ECONNREFUSED <ldap-server>:389
LDAP connection refused; domaincontroller host/port unreachable.
fix
Check LDAP server availability, firewall rules, and domaincontroller URL.
Error: NTLM type 2 message generation failed
The module failed to create an NTLM type 2 challenge.
fix
Update to latest version (2.6.1+); if persists, check client NTLM version support.
Upgrade
Version history
2.7.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
express-ntlm — npm install express-ntlm · libregistry