From f60e86a71d72c559f7cd493608b01e81c34876cb Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 9 May 2023 11:28:13 +0100 Subject: [PATCH] Merge pull request #12989 from overleaf/jpa-req-socket-null [misc] add patches for gracefully handling missing req.socket/connection GitOrigin-RevId: fd0b067d5a4b5a96857ac94a577460b82bba7672 --- package-lock.json | 18 ++++++++++-------- patches/express++finalhandler+1.2.0.patch | 13 +++++++++++++ patches/finalhandler+1.1.2.patch | 13 +++++++++++++ patches/forwarded+0.2.0.patch | 13 +++++++++++++ patches/passport-oauth2+1.6.1.patch | 13 +++++++++++++ services/real-time/package.json | 2 +- 6 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 patches/express++finalhandler+1.2.0.patch create mode 100644 patches/finalhandler+1.1.2.patch create mode 100644 patches/forwarded+0.2.0.patch create mode 100644 patches/passport-oauth2+1.6.1.patch diff --git a/package-lock.json b/package-lock.json index 70f8885ff3..8725ae6fe2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29506,8 +29506,9 @@ } }, "node_modules/socket.io": { - "version": "0.9.19-overleaf-9", - "resolved": "git+ssh://git@github.com/overleaf/socket.io.git#98413354b8319f84c50268acfb67c46c30fce365", + "version": "0.9.19-overleaf-10", + "resolved": "git+ssh://git@github.com/overleaf/socket.io.git#00d3d7149e5eeacf6647d6080485cb00bb50fceb", + "integrity": "sha512-0Ax6ZXGJtdJx9FgTk6bPKn5a7G5fO8vQCcbcmbK/HmFZx/NtGWiGDP+xHoKmvFrDfHPsUh9vGXtSWfUGIGebFw==", "dependencies": { "base64id": "0.1.0", "policyfile": "0.0.4" @@ -29570,7 +29571,7 @@ "node_modules/socket.io/node_modules/redis": { "version": "0.7.3", "resolved": "https://registry.npmjs.org/redis/-/redis-0.7.3.tgz", - "integrity": "sha1-7le3pE0l7BWU5ENl2BZfp9HUgRo=", + "integrity": "sha512-0Pgb0jOLfn6eREtEIRn/ifyZJjl2H+wUY4F/Pe7T4UhmoSrZ/1HU5ZqiBpDk8I8Wbyv2N5DpXKzbEtMj3drprg==", "optional": true, "engines": { "node": "*" @@ -34619,7 +34620,7 @@ "express-session": "^1.17.1", "proxy-addr": "^2.0.7", "request": "^2.88.2", - "socket.io": "github:overleaf/socket.io#0.9.19-overleaf-9", + "socket.io": "github:overleaf/socket.io#0.9.19-overleaf-10", "socket.io-client": "github:overleaf/socket.io-client#0.9.17-overleaf-5", "underscore": "1.13.1" }, @@ -44387,7 +44388,7 @@ "request": "^2.88.2", "sandboxed-module": "~0.3.0", "sinon": "^9.2.4", - "socket.io": "github:overleaf/socket.io#0.9.19-overleaf-9", + "socket.io": "github:overleaf/socket.io#0.9.19-overleaf-10", "socket.io-client": "github:overleaf/socket.io-client#0.9.17-overleaf-5", "timekeeper": "0.0.4", "uid-safe": "^2.1.5", @@ -64187,8 +64188,9 @@ "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==" }, "socket.io": { - "version": "git+ssh://git@github.com/overleaf/socket.io.git#98413354b8319f84c50268acfb67c46c30fce365", - "from": "socket.io@github:overleaf/socket.io#0.9.19-overleaf-9", + "version": "git+ssh://git@github.com/overleaf/socket.io.git#00d3d7149e5eeacf6647d6080485cb00bb50fceb", + "integrity": "sha512-0Ax6ZXGJtdJx9FgTk6bPKn5a7G5fO8vQCcbcmbK/HmFZx/NtGWiGDP+xHoKmvFrDfHPsUh9vGXtSWfUGIGebFw==", + "from": "socket.io@github:overleaf/socket.io#0.9.19-overleaf-10", "requires": { "base64id": "0.1.0", "policyfile": "0.0.4", @@ -64198,7 +64200,7 @@ "redis": { "version": "0.7.3", "resolved": "https://registry.npmjs.org/redis/-/redis-0.7.3.tgz", - "integrity": "sha1-7le3pE0l7BWU5ENl2BZfp9HUgRo=", + "integrity": "sha512-0Pgb0jOLfn6eREtEIRn/ifyZJjl2H+wUY4F/Pe7T4UhmoSrZ/1HU5ZqiBpDk8I8Wbyv2N5DpXKzbEtMj3drprg==", "optional": true } } diff --git a/patches/express++finalhandler+1.2.0.patch b/patches/express++finalhandler+1.2.0.patch new file mode 100644 index 0000000000..a7e0db2c9f --- /dev/null +++ b/patches/express++finalhandler+1.2.0.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/express/node_modules/finalhandler/index.js b/node_modules/express/node_modules/finalhandler/index.js +index f628e42..72f17d6 100644 +--- a/node_modules/express/node_modules/finalhandler/index.js ++++ b/node_modules/express/node_modules/finalhandler/index.js +@@ -125,7 +125,7 @@ function finalhandler (req, res, options) { + // cannot actually respond + if (headersSent(res)) { + debug('cannot %d after headers sent', status) +- req.socket.destroy() ++ if (req.socket) req.socket.destroy() + return + } + diff --git a/patches/finalhandler+1.1.2.patch b/patches/finalhandler+1.1.2.patch new file mode 100644 index 0000000000..74f746194d --- /dev/null +++ b/patches/finalhandler+1.1.2.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/finalhandler/index.js b/node_modules/finalhandler/index.js +index 5673507..40f4684 100644 +--- a/node_modules/finalhandler/index.js ++++ b/node_modules/finalhandler/index.js +@@ -125,7 +125,7 @@ function finalhandler (req, res, options) { + // cannot actually respond + if (headersSent(res)) { + debug('cannot %d after headers sent', status) +- req.socket.destroy() ++ if (req.socket) req.socket.destroy() + return + } + diff --git a/patches/forwarded+0.2.0.patch b/patches/forwarded+0.2.0.patch new file mode 100644 index 0000000000..7c13376899 --- /dev/null +++ b/patches/forwarded+0.2.0.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/forwarded/index.js b/node_modules/forwarded/index.js +index b2b6bdd..75e6254 100644 +--- a/node_modules/forwarded/index.js ++++ b/node_modules/forwarded/index.js +@@ -46,7 +46,7 @@ function forwarded (req) { + function getSocketAddr (req) { + return req.socket + ? req.socket.remoteAddress +- : req.connection.remoteAddress ++ : req.connection && req.connection.remoteAddress + } + + /** diff --git a/patches/passport-oauth2+1.6.1.patch b/patches/passport-oauth2+1.6.1.patch new file mode 100644 index 0000000000..25a571b449 --- /dev/null +++ b/patches/passport-oauth2+1.6.1.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/passport-oauth2/lib/utils.js b/node_modules/passport-oauth2/lib/utils.js +index 486f9e1..4584507 100644 +--- a/node_modules/passport-oauth2/lib/utils.js ++++ b/node_modules/passport-oauth2/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 || ''; diff --git a/services/real-time/package.json b/services/real-time/package.json index 7521fae4ce..bc005b0cd3 100644 --- a/services/real-time/package.json +++ b/services/real-time/package.json @@ -32,7 +32,7 @@ "express-session": "^1.17.1", "proxy-addr": "^2.0.7", "request": "^2.88.2", - "socket.io": "github:overleaf/socket.io#0.9.19-overleaf-9", + "socket.io": "github:overleaf/socket.io#0.9.19-overleaf-10", "socket.io-client": "github:overleaf/socket.io-client#0.9.17-overleaf-5", "underscore": "1.13.1" },