Passport.js strategy for authentication by trusted HTTP headers, typically used when TLS is terminated at a front-end proxy (e.g., nginx). Version 1.1.0 is current, with no recent updates. Key differentiators: specifically for proxied setups, complements passport-client-cert for direct TLS. Security warning about proxy whitelisting is critical; alternatives include passport-client-cert.
npm install passport-trusted-headerVerified import paths — ran on the pinned version, not inferred.
Initializes passport-trusted-header strategy with custom headers and a verify callback; shows Express usage.
Configure your proxy (e.g., nginx) to set and only accept trusted headers from internal network; ensure no external traffic reaches the Node app directly.
Ensure the proxy forwards all required headers; maybe include optional headers by separate logic.
Access headers with bracket notation (e.g., requestHeaders['TLS_CLIENT_DN']) and handle missing keys.
When passReqToCallback: true, use callback signature (req, requestHeaders, done). Otherwise use (requestHeaders, done).
Implement additional security measures: use HTTPS between proxy and app, restrict network access, and validate proxy identity (e.g., shared secret).
Ensure the strategy is registered with the same name: passport.use('trusted-header', new Strategy(...)) or use passport.authenticate('trusted-header'). Default name might be 'trusted-header' if not specified.Check passReqToCallback setting: if true, first argument is req, second is headers; if false, first is headers. Access requestHeaders.TLS_CLIENT_DN only after checking it exists.
Add a headers array with at least one header name, e.g., { headers: ['X-Client-DN'] }.