[mirotalksfu] - improve host protection

هذا الالتزام موجود في:
Miroslav Pejic
2022-02-10 08:30:06 +01:00
الأصل f45d41a5e9
التزام 11790210a2
2 ملفات معدلة مع 17 إضافات و0 حذوفات

عرض الملف

@@ -12,4 +12,7 @@ module.exports = class Host {
isAuthorized(ip) { isAuthorized(ip) {
return this.auth.has(ip); return this.auth.has(ip);
} }
deleteIP(ip) {
return this.auth.delete(ip);
}
}; };

عرض الملف

@@ -600,6 +600,8 @@ io.on('connection', (socket) => {
} }
roomList.get(socket.room_id).broadCast(socket.id, 'removeMe', removeMeData()); roomList.get(socket.room_id).broadCast(socket.id, 'removeMe', removeMeData());
removeIP(socket);
}); });
socket.on('exitRoom', async (_, callback) => { socket.on('exitRoom', async (_, callback) => {
@@ -622,6 +624,8 @@ io.on('connection', (socket) => {
socket.room_id = null; socket.room_id = null;
removeIP(socket);
callback('Successfully exited room'); callback('Successfully exited room');
}); });
@@ -661,3 +665,13 @@ function getIP(req) {
function allowedIP(ip) { function allowedIP(ip) {
return authHost != null && authHost.isAuthorized(ip); return authHost != null && authHost.isAuthorized(ip);
} }
function removeIP(socket) {
if (hostCfg.protected == true) {
let ip = socket.handshake.address;
if (ip && allowedIP(ip)) {
authHost.deleteIP(ip);
hostCfg.authenticated = false;
log.debug('Remove IP from auth', { ip: ip });
}
}
}