Improving localhost check

This commit is contained in:
Felipe Augusto Rieck 2025-08-04 18:14:33 -03:00
parent 4f043f9576
commit d4eb61f64d

View File

@ -28,11 +28,14 @@ export class WebsocketController extends EventController implements EventControl
allowRequest: async (req, callback) => { allowRequest: async (req, callback) => {
try { try {
const url = new URL(req.url || '', 'http://localhost'); const url = new URL(req.url || '', 'http://localhost');
const isInternalConnection = req.socket.remoteAddress === '127.0.0.1' || req.socket.remoteAddress === '::1';
const params = new URLSearchParams(url.search); const params = new URLSearchParams(url.search);
const remoteAddress = req.socket.remoteAddress;
const isLocalhost =
remoteAddress === '127.0.0.1' || remoteAddress === '::1' || remoteAddress === '::ffff:127.0.0.1';
// Permite conexões internas do Socket.IO (EIO=4 é o Engine.IO v4) // Permite conexões internas do Socket.IO (EIO=4 é o Engine.IO v4)
if (params.has('EIO') && isInternalConnection) { if (params.has('EIO') && isLocalhost) {
return callback(null, true); return callback(null, true);
} }