Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
A moderator's ban over /live is refused with 'that address is yours too' when the target shares the moderator's address, proven through the socket #350
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
smith/arm:smith/344-a-moderator-s-ban-over-live-is-refused-w → main 1 commit fork
4 files
changed +28
−1
Software/README.md +3 −1
| @@ -467,7 +467,9 @@ its live pose and the cameras. Driving needs a name and a turn. | ||
| 467 | 467 | right-click a chat line). |
| 468 | 468 | - Moderators (names the owner lists under `moderators` on `/admin`) can delete |
| 469 | 469 | chat lines, and mute and unmute people who are signed in and here now (never |
| 470 | the owner, another moderator, or anyone not connected), and do nothing else | |
| 470 | the owner, another moderator, or anyone not connected), ban and unban (a ban | |
| 471 | of someone on the moderator's own address is refused with "that address is | |
| 472 | yours too: the ban would bar you"), and do nothing else | |
| 471 | 473 | of the owner's. They must be signed in through |
| 472 | 474 | the forge: a guest who picked a listed name is not one. In the page, long-press |
| 473 | 475 | or right-click a chat line and choose **Delete message**. In the terminal, chat |
Software/so101/src/accounts.ts +5
| @@ -171,6 +171,11 @@ export class Accounts { | ||
| 171 | 171 | return Boolean(this.db.query("SELECT 1 FROM bans WHERE id = ? OR key = ? OR ip = ? LIMIT 1").get(id, name?.toLowerCase() ?? "\0", ip || "\0")); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | /** The address an account was last seen at, or null when it is unknown. */ | |
| 175 | addressOf(id: string): string | null { | |
| 176 | return this.db.query<{ ip: string }, [string]>("SELECT ip FROM users WHERE id = ?").get(id)?.ip || null; | |
| 177 | } | |
| 178 | ||
| 174 | 179 | /** Bar a person: their account, their name, and the address and browser they were last seen with. */ |
| 175 | 180 | ban(who: Person, seen: Pick<Visitor, "ip" | "ua"> | null, by: string): Ban { |
| 176 | 181 | const row = this.db.query<UserRow, [string]>("SELECT id, name, ip, ua FROM users WHERE id = ?").get(who.id); |
Software/so101/src/lobby.test.ts +18
| @@ -488,6 +488,24 @@ describe("lobby", () => { | ||
| 488 | 488 | expect((await alice.next((m) => m.type === "error")).error).toBe("only the owner can do that"); |
| 489 | 489 | }); |
| 490 | 490 | |
| 491 | test("a moderator's ban is refused when the target shares the moderator's address; another address still works", async () => { | |
| 492 | const admin = new Admin(); | |
| 493 | admin.set({ id: "u-owner", name: "trevato", owner: true }, { moderators: ["bob"] }); | |
| 494 | const port = await start(undefined, undefined, admin); | |
| 495 | const bob = await join(port, BOB); | |
| 496 | const alice = await join(port, ALICE); // same address as bob | |
| 497 | const carol = await join(port, { ...CAROL, "x-forwarded-for": "198.51.100.10" }); | |
| 498 | await bob.first((m) => m.type === "banned"); | |
| 499 | const logged = admin.log.length; | |
| 500 | bob.send({ type: "ban", id: "u-alice", on: true }); | |
| 501 | expect((await bob.next((m) => m.type === "error")).error).toBe("that address is yours too: the ban would bar you"); | |
| 502 | expect(admin.log.length).toBe(logged); | |
| 503 | bob.send({ type: "ban", id: "u-carol", on: true }); | |
| 504 | expect((await carol.next((m) => m.type === "hello")).banned).toBe(true); | |
| 505 | expect((await bob.next((m) => m.type === "banned")).banned).toEqual([expect.objectContaining({ id: "u-carol" })]); | |
| 506 | expect(alice.heard.some((m) => m.type === "hello" && m.banned)).toBe(false); | |
| 507 | }); | |
| 508 | ||
| 491 | 509 | test("report: a signed-in user reports a line; only they hear it, owner and moderators get the list, a guest and a banned user are refused", async () => { |
| 492 | 510 | const admin = new Admin(); |
| 493 | 511 | admin.set({ id: "u-owner", name: "trevato", owner: true }, { moderators: ["bob"] }); |
Software/so101/src/lobby.ts +2
| @@ -420,6 +420,8 @@ export class Lobby { | ||
| 420 | 420 | if (!person) return this.send(seat, { type: "error", error: "nobody here by that id" }); |
| 421 | 421 | if (person.owner) return this.send(seat, { type: "error", error: who.owner ? "the owner cannot be banned" : refused }); |
| 422 | 422 | if (!who.owner && this.admin.isModerator(person.name)) return this.send(seat, { type: "error", error: refused }); |
| 423 | const address = target?.from?.ip || this.accounts.addressOf(person.id); | |
| 424 | if (!who.owner && address && address === seat.from?.ip) return this.send(seat, { type: "error", error: "that address is yours too: the ban would bar you" }); | |
| 423 | 425 | this.accounts.ban({ id: person.id, name: person.name, owner: false }, target?.from ?? null, who.name); |
| 424 | 426 | this.turns.end(id); // their turn ends, or they leave the line |
| 425 | 427 | this.broadcast({ type: "said", message: this.chat.system(`${person.name} was banned`) }); |
new above
offline