make ips less precise before storing

This commit is contained in:
evanpelle
2024-12-17 14:53:52 -08:00
parent 387fdcdef8
commit d26eddcf2d
4 changed files with 19 additions and 3 deletions
+1 -1
View File
@@ -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
+7
View File
@@ -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",
+2 -1
View File
@@ -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"
}
}
+9 -1
View File
@@ -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 {