functionissecure(req, trustProxy) { // socket is https server if (req.connection && req.connection.encrypted) { returntrue; }
// do not trust proxy if (trustProxy === false) { returnfalse; }
// no explicit trust; try req.secure from express if (trustProxy !== true) { return req.secure === true }
// read the proto from x-forwarded-proto header var header = req.headers['x-forwarded-proto'] || ''; var index = header.indexOf(','); var proto = index !== -1 ? header.substr(0, index).toLowerCase().trim() : header.toLowerCase().trim()
return proto === 'https'; }
onHeaders(res, function(){ if (!req.session) { debug('no session'); return; }
if (!shouldSetCookie(req)) { return; }
// only send secure cookies via https if (req.session.cookie.secure && !issecure(req, trustProxy)) { debug('not secured'); return; }