diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts index 60465df09..662edb9ec 100644 --- a/src/server/GameServer.ts +++ b/src/server/GameServer.ts @@ -1,3 +1,4 @@ +import ipAnonymize from "ip-anonymize"; import { Logger } from "winston"; import WebSocket from "ws"; import { @@ -114,7 +115,7 @@ export class GameServer { this.log.info("client (re)joining game", { clientID: client.clientID, persistentID: client.persistentID, - clientIP: client.ip, + clientIP: ipAnonymize(client.ip), isRejoin: lastTurn > 0, }); @@ -126,7 +127,7 @@ export class GameServer { ) { this.log.warn("cannot add client, already have 3 ips", { clientID: client.clientID, - clientIP: client.ip, + clientIP: ipAnonymize(client.ip), }); return; } @@ -139,9 +140,9 @@ export class GameServer { if (client.persistentID !== existing.persistentID) { this.log.error("persistent ids do not match", { clientID: client.clientID, - clientIP: client.ip, + clientIP: ipAnonymize(client.ip), clientPersistentID: client.persistentID, - existingIP: existing.ip, + existingIP: ipAnonymize(existing.ip), existingPersistentID: existing.persistentID, }); return; @@ -164,7 +165,7 @@ export class GameServer { try { clientMsg = ClientMessageSchema.parse(JSON.parse(message)); } catch (error) { - throw Error(`error parsing schema for ${client.ip}`); + throw Error(`error parsing schema for ${ipAnonymize(client.ip)}`); } if (clientMsg.type == "intent") { if (clientMsg.intent.clientID != client.clientID) { @@ -370,7 +371,7 @@ export class GameServer { const playerRecords: PlayerRecord[] = Array.from( this.allClients.values(), ).map((client) => ({ - ip: client.ip, + ip: ipAnonymize(client.ip), clientID: client.clientID, username: client.username, persistentID: client.persistentID, diff --git a/src/server/Worker.ts b/src/server/Worker.ts index 60ce1c8da..fe6d1fb72 100644 --- a/src/server/Worker.ts +++ b/src/server/Worker.ts @@ -1,6 +1,7 @@ import express, { NextFunction, Request, Response } from "express"; import rateLimit from "express-rate-limit"; import http from "http"; +import ipAnonymize from "ip-anonymize"; import path from "path"; import { fileURLToPath } from "url"; import { WebSocket, WebSocketServer } from "ws"; @@ -88,7 +89,7 @@ export function startWorker() { req.headers[config.adminHeader()] !== config.adminToken() ) { log.warn( - `cannot create public game ${id}, ip ${clientIP} incorrect admin token`, + `cannot create public game ${id}, ip ${ipAnonymize(clientIP)} incorrect admin token`, ); return res.status(400); } @@ -105,7 +106,7 @@ export function startWorker() { const game = gm.createGame(id, gc); log.info( - `Worker ${workerId}: IP ${clientIP} creating game ${game.isPublic() ? "Public" : "Private"} with id ${id}`, + `Worker ${workerId}: IP ${ipAnonymize(clientIP)} creating game ${game.isPublic() ? "Public" : "Private"} with id ${id}`, ); res.json(game.gameInfo()); }), @@ -123,7 +124,7 @@ export function startWorker() { if (game.isPublic()) { const clientIP = req.ip || req.socket.remoteAddress || "unknown"; log.info( - `cannot start public game ${game.id}, game is public, ip: ${clientIP}`, + `cannot start public game ${game.id}, game is public, ip: ${ipAnonymize(clientIP)}`, ); return; } @@ -147,7 +148,9 @@ export function startWorker() { } if (game.isPublic()) { const clientIP = req.ip || req.socket.remoteAddress || "unknown"; - log.warn(`cannot update public game ${game.id}, ip: ${clientIP}`); + log.warn( + `cannot update public game ${game.id}, ip: ${ipAnonymize(clientIP)}`, + ); return res.status(400); } if (game.hasStarted()) { @@ -325,7 +328,7 @@ export function startWorker() { // Handle other message types } catch (error) { log.warn( - `error handling websocket message for ${ip}: ${error}`.substring( + `error handling websocket message for ${ipAnonymize(ip)}: ${error}`.substring( 0, 250, ),