diff --git a/TODO.txt b/TODO.txt index 73b48e769..39a583d42 100644 --- a/TODO.txt +++ b/TODO.txt @@ -241,7 +241,7 @@ * store ips in bigquery table DONE 12/14/2024 * better error logging in server DONE 12/16/2024 * store and archive player cookies DONE 12/17/2024 -* make ips less precise +* make ips less precise for user safety DONE 12/17/2024 * send client logs back to server * seperate server config from client config * right click brings up player info menu diff --git a/package-lock.json b/package-lock.json index e9b6e5baa..390f306dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ "google-auth-library": "^9.14.0", "googleapis": "^143.0.0", "hammerjs": "^2.0.8", + "ip-anonymize": "^0.1.0", "jimp": "^0.22.12", "lit": "^3.2.1", "msgpack5": "^6.0.2", @@ -9185,6 +9186,12 @@ "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==", "license": "BSD-3-Clause" }, + "node_modules/ip-anonymize": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/ip-anonymize/-/ip-anonymize-0.1.0.tgz", + "integrity": "sha512-cZJu+N5JKKFGMK0eEQWNaQMn2EhCysciVM6eotCJwfqotj16BTfVchKsJCH6mQAT9N0GC7oWRcsZ6Lb8dDiwTA==", + "license": "MIT" + }, "node_modules/ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", diff --git a/package.json b/package.json index c136213c0..df0b0c8b7 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "google-auth-library": "^9.14.0", "googleapis": "^143.0.0", "hammerjs": "^2.0.8", + "ip-anonymize": "^0.1.0", "jimp": "^0.22.12", "lit": "^3.2.1", "msgpack5": "^6.0.2", @@ -94,4 +95,4 @@ "zod": "^3.23.8" }, "type": "module" -} \ No newline at end of file +} diff --git a/src/server/Archive.ts b/src/server/Archive.ts index ab404ef27..324d8c8d5 100644 --- a/src/server/Archive.ts +++ b/src/server/Archive.ts @@ -1,6 +1,10 @@ import { GameConfig, GameID, GameRecord, GameRecordSchema, Turn } from "../core/Schemas"; import { Storage } from '@google-cloud/storage'; import { BigQuery } from '@google-cloud/bigquery'; +// import { anonymize } from 'ip-anonymize'; +import anonymize from 'ip-anonymize'; + + const storage = new Storage(); const bigquery = new BigQuery(); @@ -20,7 +24,9 @@ export async function archive(gameRecord: GameRecord) { map: gameRecord.gameConfig.gameMap, players: gameRecord.players.map(p => ({ username: p.username, - ip: p.ip, + // Masks last couple of bits from ip for + // user privacy. + ip: anonymize(p.ip), persistentID: p.persistentID, clientID: p.clientID, })), @@ -34,6 +40,7 @@ export async function archive(gameRecord: GameRecord) { console.log(`wrote game metadata to BigQuery: ${gameRecord.id}`); if (gameRecord.turns.length > 0) { + console.log(`${gameRecord.id}: game has more than zero turns, attempting to write to gcs`) // Players may see this so make sure to clear PII gameRecord.players.forEach(p => { p.ip = "REDACTED" @@ -46,6 +53,7 @@ export async function archive(gameRecord: GameRecord) { await file.save(JSON.stringify(GameRecordSchema.parse(gameRecord)), { contentType: 'application/json' }); + console.log(`${gameRecord.id}: game record successfully writting to gcs`) } } catch (error) { try {