Skip to content

Commit edbf360

Browse files
Merge pull request #1929 from moothz/main
Customizable Websockets Security
2 parents 8619e32 + d67eb32 commit edbf360

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ SQS_REGION=
9999
# Websocket - Environment variables
100100
WEBSOCKET_ENABLED=false
101101
WEBSOCKET_GLOBAL_EVENTS=false
102+
WEBSOCKET_ALLOWED_HOSTS=127.0.0.1,::1,::ffff:127.0.0.1
102103

103104
# Pusher - Environment variables
104105
PUSHER_ENABLED=false

src/api/integrations/event/websocket/websocket.controller.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ export class WebsocketController extends EventController implements EventControl
3131
const params = new URLSearchParams(url.search);
3232

3333
const { remoteAddress } = req.socket;
34-
const isLocalhost =
35-
remoteAddress === '127.0.0.1' || remoteAddress === '::1' || remoteAddress === '::ffff:127.0.0.1';
34+
const isAllowedHost = (process.env.WEBSOCKET_ALLOWED_HOSTS || '127.0.0.1,::1,::ffff:127.0.0.1')
35+
.split(',')
36+
.map((h) => h.trim())
37+
.includes(remoteAddress);
3638

37-
// Permite conexões internas do Socket.IO (EIO=4 é o Engine.IO v4)
38-
if (params.has('EIO') && isLocalhost) {
39+
if (params.has('EIO') && isAllowedHost) {
3940
return callback(null, true);
4041
}
4142

0 commit comments

Comments
 (0)