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

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

smith/arm:smith/344-a-moderator-s-ban-over-live-is-refused-w → main 1 commit fork

  • Merged. smith/344-a-moderator-s-ban-over-live-is-refused-w was merged into main as 2b72f13.

Review

Sign in to review this change.
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.
467467 right-click a chat line).
468468 - Moderators (names the owner lists under `moderators` on `/admin`) can delete
469469 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
471473 of the owner's. They must be signed in through
472474 the forge: a guest who picked a listed name is not one. In the page, long-press
473475 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 {
171171 return Boolean(this.db.query("SELECT 1 FROM bans WHERE id = ? OR key = ? OR ip = ? LIMIT 1").get(id, name?.toLowerCase() ?? "\0", ip || "\0"));
172172 }
173173
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
174179 /** Bar a person: their account, their name, and the address and browser they were last seen with. */
175180 ban(who: Person, seen: Pick<Visitor, "ip" | "ua"> | null, by: string): Ban {
176181 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", () => {
488488 expect((await alice.next((m) => m.type === "error")).error).toBe("only the owner can do that");
489489 });
490490
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
491509 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 () => {
492510 const admin = new Admin();
493511 admin.set({ id: "u-owner", name: "trevato", owner: true }, { moderators: ["bob"] });
Software/so101/src/lobby.ts +2
@@ -420,6 +420,8 @@ export class Lobby {
420420 if (!person) return this.send(seat, { type: "error", error: "nobody here by that id" });
421421 if (person.owner) return this.send(seat, { type: "error", error: who.owner ? "the owner cannot be banned" : refused });
422422 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" });
423425 this.accounts.ban({ id: person.id, name: person.name, owner: false }, target?.from ?? null, who.name);
424426 this.turns.end(id); // their turn ends, or they leave the line
425427 this.broadcast({ type: "said", message: this.chat.system(`${person.name} was banned`) });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs