[misc] use overleaf/socket.io and overleaf/socket.io-client forks

This commit is contained in:
Jakob Ackermann 2020-07-08 15:07:19 +01:00
parent 383f7a1e2e
commit ca4168ce90
4 changed files with 7 additions and 96 deletions

View file

@ -23,8 +23,6 @@ const CookieParser = require('cookie-parser')
const DrainManager = require('./app/js/DrainManager')
const HealthCheckManager = require('./app/js/HealthCheckManager')
// work around frame handler bug in socket.io v0.9.16
require('./socket.io.patch.js')
// Set up socket.io server
const app = express()

View file

@ -4530,14 +4530,13 @@
}
},
"socket.io": {
"version": "0.9.19",
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-0.9.19.tgz",
"integrity": "sha512-UPdVIGPBPmCibzIP2rAjXuiPTI2gPs6kiu4P7njH6WAK7wiOlozNG62ohohCNOycx+Dztd4vRNXxq8alIOEtfA==",
"version": "https://github.com/overleaf/socket.io/archive/0.9.19-overleaf-2.tar.gz",
"integrity": "sha512-BVxF8Wz4FTj2hxiBtujKQUAihdVzxjSaJ++k/wr7pJfAt30kmyOXLkfyvFDzZISQ9SyDa2B4nBYJP3+MKBpaAg==",
"requires": {
"base64id": "0.1.0",
"policyfile": "0.0.4",
"redis": "0.7.3",
"socket.io-client": "0.9.16"
"socket.io-client": "https://github.com/overleaf/socket.io-client/archive/0.9.17-overleaf-1.tar.gz"
},
"dependencies": {
"redis": {
@ -4545,24 +4544,12 @@
"resolved": "https://registry.npmjs.org/redis/-/redis-0.7.3.tgz",
"integrity": "sha512-0Pgb0jOLfn6eREtEIRn/ifyZJjl2H+wUY4F/Pe7T4UhmoSrZ/1HU5ZqiBpDk8I8Wbyv2N5DpXKzbEtMj3drprg==",
"optional": true
},
"socket.io-client": {
"version": "0.9.16",
"resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-0.9.16.tgz",
"integrity": "sha512-wSM7PKJkzpGqUAo6d6SAn+ph4xeQJ6nzyDULRJAX1G7e6Xm0wNuMh2RpNvwXrHMzoV9Or5hti7LINiQAm1H2yA==",
"requires": {
"active-x-obfuscator": "0.0.1",
"uglify-js": "1.2.5",
"ws": "0.4.x",
"xmlhttprequest": "1.4.2"
}
}
}
},
"socket.io-client": {
"version": "0.9.17",
"resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-0.9.17.tgz",
"integrity": "sha512-gKV451FUZPLeJmA8vPfvqRZctAzWNOlaB0C06MeDFmrGquDNMllnpXp+1+4QS2NaZvcycoJHVt72R5uNaLCIBg==",
"version": "https://github.com/overleaf/socket.io-client/archive/0.9.17-overleaf-1.tar.gz",
"integrity": "sha512-MchfS0GCu0BVbJXRk+HfHme5jHPWMDrNifbOhXZHJBtF03dLfCJcMPLYMQBtBGWQrrZsqXI0O9P3BO3hu0cPLA==",
"requires": {
"active-x-obfuscator": "0.0.1",
"uglify-js": "1.2.5",

View file

@ -32,8 +32,8 @@
"redis-sharelatex": "^1.0.12",
"request": "^2.88.2",
"settings-sharelatex": "^1.1.0",
"socket.io": "0.9.19",
"socket.io-client": "^0.9.16"
"socket.io": "https://github.com/overleaf/socket.io/archive/0.9.19-overleaf-2.tar.gz",
"socket.io-client": "https://github.com/overleaf/socket.io-client/archive/0.9.17-overleaf-1.tar.gz"
},
"devDependencies": {
"bunyan": "~0.22.3",

View file

@ -1,74 +0,0 @@
// EventEmitter has been removed from process in node >= 7
// https://github.com/nodejs/node/commit/62b544290a075fe38e233887a06c408ba25a1c71
/*
A socket.io dependency expects the EventEmitter to be available at
`process.EventEmitter`.
See this trace:
---
/app/node_modules/policyfile/lib/server.js:254
Object.keys(process.EventEmitter.prototype).forEach(function proxy (key){
^
TypeError: Cannot read property 'prototype' of undefined
at Object.<anonymous> (/app/node_modules/policyfile/lib/server.js:254:34)
*/
if (process.versions.node.split('.')[0] >= 7) {
// eslint-disable-next-line node/no-deprecated-api
process.EventEmitter = require('events')
}
var io = require('socket.io')
const logger = require('logger-sharelatex')
if (io.version === '0.9.16' || io.version === '0.9.19') {
logger.warn('patching socket.io hybi-16 transport frame prototype')
var transports = require('socket.io/lib/transports/websocket/hybi-16.js')
transports.prototype.frame = patchedFrameHandler
// file hybi-07-12 has the same problem but no browsers are using that protocol now
}
function patchedFrameHandler(opcode, str) {
var dataBuffer = Buffer.from(str)
var dataLength = dataBuffer.length
var startOffset = 2
var secondByte = dataLength
if (dataLength === 65536) {
logger.log('fixing invalid frame length in socket.io')
}
if (dataLength > 65535) {
// original code had > 65536
startOffset = 10
secondByte = 127
} else if (dataLength > 125) {
startOffset = 4
secondByte = 126
}
var outputBuffer = Buffer.alloc(dataLength + startOffset)
outputBuffer[0] = opcode
outputBuffer[1] = secondByte
dataBuffer.copy(outputBuffer, startOffset)
switch (secondByte) {
case 126:
outputBuffer[2] = dataLength >>> 8
outputBuffer[3] = dataLength % 256
break
case 127:
var l = dataLength
for (var i = 1; i <= 8; ++i) {
outputBuffer[startOffset - i] = l & 0xff
l >>>= 8
}
}
return outputBuffer
}
const parser = require('socket.io/lib/parser')
const decodePacket = parser.decodePacket
parser.decodePacket = function (data) {
if (typeof data !== 'string') return {}
const firstColon = data.indexOf(':')
if (firstColon === -1) return {}
if (data.indexOf(':', firstColon + 1) === -1) return {}
return decodePacket(data)
}