Merge pull request #12989 from overleaf/jpa-req-socket-null

[misc] add patches for gracefully handling missing req.socket/connection

GitOrigin-RevId: fd0b067d5a4b5a96857ac94a577460b82bba7672
This commit is contained in:
Jakob Ackermann 2023-05-09 11:28:13 +01:00 committed by Copybot
parent 5078f8ab43
commit f60e86a71d
6 changed files with 63 additions and 9 deletions

18
package-lock.json generated
View file

@ -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
}
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}
/**

View file

@ -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 || '';

View file

@ -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"
},