mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
feat(devices): hardware bans and alts need 3 matching IDs
A computer is taken for a banned one, and an account for an alt, only
when they share at least 3 hardware IDs (system, board, disk, the
client's own); one or two in common was too often someone else's.
Network card addresses still do not count. A hardware ban is refused
for an account with fewer than 3 IDs known, as it could match nobody.
MAC-only ("weak") alts no longer exist, so the flag is gone from the
panels.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
494f252c5b
commit
b22708a4ba
4 files changed
+61
-46
No files matched your search
+55
-40
@@ -19,11 +19,13 @@ const config = require("../config.js");
|
||||
// again with a secret of this server's (data/device-key), so what is kept
|
||||
// is of no use anywhere else.
|
||||
//
|
||||
// any one of them is a match: someone who edits /etc/machine-id or deletes
|
||||
// MachineGuid still has the same disks and the client's own id. the network
|
||||
// card's address alone (MAC_KIND) is a weak match: it is easily changed and
|
||||
// sometimes shared, so it bans nothing; it is written down for the
|
||||
// moderators instead. values every cheap board or VM has ("To be filled by
|
||||
// two computers are taken for one when they share at least MIN_MATCHING of
|
||||
// these (owner, 2026-10-23: one or two in common was too often someone
|
||||
// else's), for a ban and for an alt alike: someone who edits
|
||||
// /etc/machine-id or deletes MachineGuid still has the same board, disks
|
||||
// and the client's own id. the network card's address (MAC_KIND) does not
|
||||
// count towards them: it is easily changed and sometimes shared, so it bans
|
||||
// nothing; it is written down for the moderators instead. values every cheap board or VM has ("To be filled by
|
||||
// O.E.M.", all zeros) are left out here, so that no ban falls on everyone
|
||||
// who has one. what the client noticed was wrong (the system id missing, or
|
||||
// not shaped as it always is) comes as notes, and is written down too.
|
||||
@@ -56,6 +58,7 @@ const SCHEMA = `
|
||||
const KINDS = ["os", "board", "disk", "install", "mac"];
|
||||
const STRONG = ["os", "board", "disk", "install"];
|
||||
const MAC_KIND = "mac";
|
||||
const MIN_MATCHING = 3; // ids but a network card's two computers share to be taken for one
|
||||
const LISTS = ["disk", "mac"]; // sent as lists; the rest one each
|
||||
const MAX_IN_LIST = 8;
|
||||
const MAX_KEPT = 60; // ids an account keeps, the latest
|
||||
@@ -106,6 +109,7 @@ const idsOf = account => {
|
||||
return account.hwids;
|
||||
};
|
||||
const tag = entry => `${entry.kind}:${entry.id}`;
|
||||
const isStrong = id => STRONG.includes(id.split(":")[0]);
|
||||
|
||||
const banRow = row => ({id: row.id, ids: JSON.parse(row.ids), reason: row.reason, by: row.by, createdAt: row.created_at,
|
||||
accountId: row.account_id, username: row.username});
|
||||
@@ -161,27 +165,29 @@ const read = device => {
|
||||
return ids.some(entry => STRONG.includes(entry.kind)) ? {ids, notes} : null;
|
||||
};
|
||||
|
||||
// the ban that keeps this computer out, or null. a network card's address
|
||||
// alone keeps nobody out (see the top).
|
||||
const banOf = device => {
|
||||
for (const entry of device.ids) {
|
||||
if (STRONG.includes(entry.kind) && banned.has(tag(entry))) {
|
||||
return banned.get(tag(entry));
|
||||
// the ban that has at least MIN_MATCHING of these "kind:id" in it, or
|
||||
// null. network cards' addresses are not counted (see the top).
|
||||
const banMatching = ids => {
|
||||
const strong = new Set(ids.filter(isStrong));
|
||||
const looked = new Set();
|
||||
for (const id of strong) {
|
||||
const ban = banned.get(id);
|
||||
if (ban && !looked.has(ban.id)) {
|
||||
looked.add(ban.id);
|
||||
if (ban.ids.filter(one => strong.has(one)).length >= MIN_MATCHING) {
|
||||
return ban;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// the ban that keeps this computer out, or null.
|
||||
const banOf = device => banMatching(device.ids.map(tag));
|
||||
|
||||
// the ban on any computer the account signed in from lately, or null: for
|
||||
// the client asking why its game was stopped.
|
||||
const banOfAccount = account => {
|
||||
for (const entry of idsOf(account)) {
|
||||
if (STRONG.includes(entry.kind) && entry.last > now() - DAYS_KEPT * 86400 && banned.has(tag(entry))) {
|
||||
return banned.get(tag(entry));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
const banOfAccount = account => banMatching(idsOf(account).filter(entry => entry.last > now() - DAYS_KEPT * 86400).map(tag));
|
||||
|
||||
const alert = (account, kind, detail) => {
|
||||
const last = db().prepare("SELECT at FROM device_alerts WHERE account_id = ? AND kind = ? ORDER BY id DESC LIMIT 1").get(account.id, kind);
|
||||
@@ -223,38 +229,47 @@ const seen = (account, device, isBanned) => {
|
||||
if (nearBan) {
|
||||
alert(account, "near_ban", `same network card as a hardware ban (${banned.get(tag(nearBan)).username || "no account"})`);
|
||||
}
|
||||
const sharers = new Set();
|
||||
const shared = new Map(); // account id -> ids in common
|
||||
for (const entry of device.ids.filter(one => STRONG.includes(one.kind))) {
|
||||
for (const id of holders.get(tag(entry)) || []) {
|
||||
const other = id === account.id ? null : accounts.byId(id);
|
||||
if (other && isBanned(other)) {
|
||||
sharers.add(other.username);
|
||||
if (id !== account.id) {
|
||||
shared.set(id, (shared.get(id) || 0) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
const sharers = new Set();
|
||||
for (const [id, count] of shared) {
|
||||
const other = count >= MIN_MATCHING ? accounts.byId(id) : null;
|
||||
if (other && isBanned(other)) {
|
||||
sharers.add(other.username);
|
||||
}
|
||||
}
|
||||
if (sharers.size) {
|
||||
alert(account, "shares_banned", `same hardware as banned ${[...sharers].slice(0, 5).join(", ")}`);
|
||||
}
|
||||
};
|
||||
|
||||
// the other accounts that used any of this one's computers: [{username,
|
||||
// kinds: [kind], weak: true when only a network card}], most in common first.
|
||||
// the other accounts that used one of this one's computers, sharing at
|
||||
// least MIN_MATCHING of its ids: [{username, kinds: [kind]}], most in
|
||||
// common first.
|
||||
const alts = account => {
|
||||
const found = new Map(); // account id -> Set of kinds
|
||||
const found = new Map(); // account id -> {kinds: Set, strong: ids in common but network cards}
|
||||
for (const entry of idsOf(account)) {
|
||||
for (const id of holders.get(tag(entry)) || []) {
|
||||
if (id !== account.id) {
|
||||
if (!found.has(id)) {
|
||||
found.set(id, new Set());
|
||||
found.set(id, {kinds: new Set(), strong: 0});
|
||||
}
|
||||
found.get(id).add(entry.kind);
|
||||
found.get(id).kinds.add(entry.kind);
|
||||
found.get(id).strong += STRONG.includes(entry.kind) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return [...found].map(([id, kinds]) => ({account: accounts.byId(id), kinds: [...kinds]}))
|
||||
return [...found].filter(([, shared]) => shared.strong >= MIN_MATCHING)
|
||||
.map(([id, shared]) => ({account: accounts.byId(id), kinds: [...shared.kinds], strong: shared.strong}))
|
||||
.filter(entry => entry.account)
|
||||
.map(entry => ({username: entry.account.username, kinds: entry.kinds, weak: entry.kinds.every(kind => kind === MAC_KIND)}))
|
||||
.sort((one, other) => Number(one.weak) - Number(other.weak) || other.kinds.length - one.kinds.length || one.username.localeCompare(other.username));
|
||||
.sort((one, other) => other.strong - one.strong || other.kinds.length - one.kinds.length || one.account.username.localeCompare(other.account.username))
|
||||
.map(entry => ({username: entry.account.username, kinds: entry.kinds}));
|
||||
};
|
||||
|
||||
// how many computers' worth of ids an account has, for the panels.
|
||||
@@ -265,10 +280,10 @@ const knownFor = account => ({ids: idsOf(account).length, lastAt: idsOf(account)
|
||||
// one of them.
|
||||
const banAccount = (account, reason, by) => {
|
||||
const ids = [...new Set(idsOf(account).filter(entry => entry.last > now() - DAYS_KEPT * 86400).map(tag))];
|
||||
if (!ids.some(id => STRONG.includes(id.split(":")[0]))) {
|
||||
return {error: "No hardware IDs known for them."};
|
||||
if (ids.filter(isStrong).length < MIN_MATCHING) {
|
||||
return {error: `Fewer than ${MIN_MATCHING} hardware IDs known for them.`};
|
||||
}
|
||||
if (ids.filter(id => STRONG.includes(id.split(":")[0])).every(id => banned.has(id))) {
|
||||
if (ids.filter(isStrong).every(id => banned.has(id))) {
|
||||
return {error: "Their hardware is banned already."};
|
||||
}
|
||||
const text = clean(reason, MAX_REASON) || NO_REASON;
|
||||
@@ -281,16 +296,16 @@ const banAccount = (account, reason, by) => {
|
||||
return {ban};
|
||||
};
|
||||
|
||||
// the accounts playing from one of a ban's computers, by their latest ids.
|
||||
// the accounts playing from one of a ban's computers, by their latest ids:
|
||||
// those with at least MIN_MATCHING of its ids.
|
||||
const accountsUnder = ban => {
|
||||
const ids = new Set(ban.ids.filter(id => STRONG.includes(id.split(":")[0])));
|
||||
const found = new Set();
|
||||
for (const id of ids) {
|
||||
const found = new Map(); // account id -> ids in common
|
||||
for (const id of new Set(ban.ids.filter(isStrong))) {
|
||||
for (const accountId of holders.get(id) || []) {
|
||||
found.add(accountId);
|
||||
found.set(accountId, (found.get(accountId) || 0) + 1);
|
||||
}
|
||||
}
|
||||
return [...found].map(id => accounts.byId(id)).filter(Boolean);
|
||||
return [...found].filter(([, count]) => count >= MIN_MATCHING).map(([id]) => accounts.byId(id)).filter(Boolean);
|
||||
};
|
||||
|
||||
const unban = id => {
|
||||
|
||||
+4
-4
@@ -141,19 +141,19 @@ const byDevice = query => {
|
||||
|
||||
// other accounts the same person may have: those that used one of its
|
||||
// computers (lib/devices.js), and those that signed in from one of its
|
||||
// addresses in the last 90 days. [{username, devices: [kind], weak,
|
||||
// addresses in the last 90 days. [{username, devices: [kind],
|
||||
// addresses: count, online, banned}], the likeliest first. the addresses
|
||||
// themselves are not given: moderators do not see them.
|
||||
const altsOf = account => {
|
||||
const found = new Map();
|
||||
const entry = username => {
|
||||
if (!found.has(username)) {
|
||||
found.set(username, {username, devices: [], weak: false, addresses: 0});
|
||||
found.set(username, {username, devices: [], addresses: 0});
|
||||
}
|
||||
return found.get(username);
|
||||
};
|
||||
for (const alt of devices.alts(account)) {
|
||||
Object.assign(entry(alt.username), {devices: alt.kinds, weak: alt.weak});
|
||||
Object.assign(entry(alt.username), {devices: alt.kinds});
|
||||
}
|
||||
const mine = new Set(account.logins.filter(login => login.ok && login.address && !limits.isLoopback(login.address)).map(login => login.address));
|
||||
if (mine.size) {
|
||||
@@ -170,7 +170,7 @@ const altsOf = account => {
|
||||
const other = accounts.byName(alt.username);
|
||||
return {...alt, online: Boolean(world.findOnline(alt.username)), banned: other ? world.moderation.banRemaining(other) : 0,
|
||||
deviceBanned: other ? devices.bannedId(other) !== 0 : false};
|
||||
}).sort((one, other) => Number(other.devices.length > 0 && !other.weak) - Number(one.devices.length > 0 && !one.weak)
|
||||
}).sort((one, other) => Number(other.devices.length > 0) - Number(one.devices.length > 0)
|
||||
|| other.devices.length - one.devices.length || other.addresses - one.addresses || one.username.localeCompare(other.username)).slice(0, 100);
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user