From bb764e40062b6b43827d2d787b9a5871af4536cc Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Mon, 22 Jan 2024 14:50:08 +0100 Subject: [PATCH] Prevent Null Point Error on null req.connection req.connection, an alias of req.socket can be null, causing a null pointer exception when reconstructing a request URL. --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 486f9e1..4584507 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -24,7 +24,7 @@ exports.originalURL = function(req, options) { var trustProxy = options.proxy; var proto = (req.headers['x-forwarded-proto'] || '').toLowerCase() - , tls = req.connection.encrypted || (trustProxy && 'https' == proto.split(/\s*,\s*/)[0]) + , tls = (req.connection && req.connection.encrypted) || (trustProxy && 'https' == proto.split(/\s*,\s*/)[0]) , host = (trustProxy && req.headers['x-forwarded-host']) || req.headers.host , protocol = tls ? 'https' : 'http' , path = req.url || '';