Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
client => cidr(`${client.remoteAddress}/24`) === cidrRemoteAddress,
);
private async handleHandshake(req, next): Promise {
const ip = req.socket.remoteAddress;
if (this.ipLastError[ip] && this.ipLastError[ip] > Date.now() - MINUTE_IN_MILLISECONDS) {
req.socket.destroy();
return;
}
const isBlocked = await this.rateLimiter.isBlocked(ip);
const isBlacklisted = (this.config.blacklist || []).includes(ip);
if (isBlocked || isBlacklisted) {
next(this.createError(SocketErrors.Forbidden, "Blocked due to rate limit or blacklisted."));
return;
}
const cidrRemoteAddress = cidr(`${ip}/24`);
const sameSubnetSockets = Object.values({ ...this.scServer.clients, ...this.scServer.pendingClients }).filter(
client => cidr(`${client.remoteAddress}/24`) === cidrRemoteAddress,
);
if (sameSubnetSockets.length > this.config.maxSameSubnetPeers) {
req.socket.destroy();
return;
}
next();
}
return this.getPeers().filter(peer => cidr(`${peer.ip}/24`) === cidr(`${ip}/24`));
}