mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
Merge pull request #24592 from overleaf/td-socket-io-origins
Use updated socket.io with CORS origin check in real-time GitOrigin-RevId: a1a874ba298e145aa4c9dd55ef723d79843f8145
This commit is contained in:
@@ -83,6 +83,33 @@ io.configure(function () {
|
||||
io.set('match origin protocol', true)
|
||||
|
||||
io.set('transports', ['websocket', 'xhr-polling'])
|
||||
|
||||
if (Settings.allowedCorsOrigins) {
|
||||
// Create a regex for matching origins, allowing wildcard subdomains
|
||||
const allowedCorsOriginsRegex = new RegExp(
|
||||
`^${Settings.allowedCorsOrigins.replaceAll('.', '\\.').replace('://*', '://[^.]+')}(?::443)?$`
|
||||
)
|
||||
|
||||
io.set('origins', function (origin, req) {
|
||||
const normalizedOrigin = URL.parse(origin).origin
|
||||
const originIsValid = allowedCorsOriginsRegex.test(normalizedOrigin)
|
||||
|
||||
if (req.headers.origin) {
|
||||
return originIsValid
|
||||
}
|
||||
|
||||
if (!originIsValid) {
|
||||
// There is no Origin header and the Referrer does not satisfy the
|
||||
// constraints. We're going to pass this anyway for now but log it
|
||||
logger.warn(
|
||||
{ req, referer: req.headers.referer },
|
||||
'Referrer header does not match allowed origins'
|
||||
)
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// Serve socket.io.js client file from imported dist folder
|
||||
|
||||
@@ -173,6 +173,7 @@ const settings = {
|
||||
behindProxy: process.env.BEHIND_PROXY === 'true',
|
||||
trustedProxyIps: process.env.TRUSTED_PROXY_IPS,
|
||||
keepAliveTimeoutMs: parseInt(process.env.KEEPALIVE_TIMEOUT_MS ?? '5000', 10),
|
||||
allowedCorsOrigins: process.env.REAL_TIME_ALLOWED_CORS_ORIGINS,
|
||||
}
|
||||
|
||||
// console.log settings.redis
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
"lodash": "^4.17.21",
|
||||
"proxy-addr": "^2.0.7",
|
||||
"request": "^2.88.2",
|
||||
"socket.io": "github:overleaf/socket.io#0.9.19-overleaf-10",
|
||||
"socket.io": "github:overleaf/socket.io#0.9.19-overleaf-11",
|
||||
"socket.io-client": "github:overleaf/socket.io-client#0.9.17-overleaf-5"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user