🔒 gate the whiteboard roster user lookup to admins
Browse files at this commitc087533acfcc30f0848284b0733c6f4fd95b4fe5Parent: d77e975- fix
- 🔒 gate the whiteboard roster user lookup to admins
1 changed file +22 -7
src/pages/whiteboard-page.tsxmodified+22 -7
| @@ -26,6 +26,7 @@ import { SidePanel } from "@/components/ui/side-panel"; | |||
| 26 | import { reassembleStrokes } from "@/lib/board-stroke-codec"; | 26 | import { reassembleStrokes } from "@/lib/board-stroke-codec"; |
| 27 | import { strokesBounds, type DrawScene } from "@/lib/draw-stroke"; | 27 | import { strokesBounds, type DrawScene } from "@/lib/draw-stroke"; |
| 28 | import { formatDateTime } from "@/lib/format"; | 28 | import { formatDateTime } from "@/lib/format"; |
| 29 | +import { hasMinRole } from "@/lib/roles"; | ||
| 29 | import { useAuth } from "@/stores/auth-context"; | 30 | import { useAuth } from "@/stores/auth-context"; |
| 30 | import { usePreferences, useT } from "@/stores/preferences-context"; | 31 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 31 | 32 | ||
| @@ -65,13 +66,21 @@ function WhiteboardContent() { | |||
| 65 | }, ""); | 66 | }, ""); |
| 66 | 67 | ||
| 67 | const [board] = createResource(id, (boardId) => getBoardById(boardId)); | 68 | const [board] = createResource(id, (boardId) => getBoardById(boardId)); |
| 68 | - const [users] = createResource(async () => { | 69 | + // `GET /users` is admin-only, so only an admin can resolve the roster's ids |
| 69 | - try { | 70 | + // to names — every other role would just 403 the moment this page mounts. |
| 70 | - return (await getUsers({ limit: 500 })).items; | 71 | + // Gate the call by role: below admin it is never sent, and names fall back to |
| 71 | - } catch { | 72 | + // the id (with the current user resolved from their own auth record below). |
| 72 | - return []; | 73 | + const isAdmin = () => hasMinRole(auth.user()?.role, "admin"); |
| 73 | - } | 74 | + const [users] = createResource( |
| 74 | - }); | 75 | + () => (isAdmin() ? "admin" : null), |
| 76 | + async () => { | ||
| 77 | + try { | ||
| 78 | + return (await getUsers({ limit: 500 })).items; | ||
| 79 | + } catch { | ||
| 80 | + return []; | ||
| 81 | + } | ||
| 82 | + }, | ||
| 83 | + ); | ||
| 75 | 84 | ||
| 76 | // Live board state, seeded from the REST read and updated by the room's socket. | 85 | // Live board state, seeded from the REST read and updated by the room's socket. |
| 77 | const [live, setLive] = createSignal<BoardLiveState>({}); | 86 | const [live, setLive] = createSignal<BoardLiveState>({}); |
| @@ -95,6 +104,12 @@ function WhiteboardContent() { | |||
| 95 | const closed = () => live().closed ?? false; | 104 | const closed = () => live().closed ?? false; |
| 96 | 105 | ||
| 97 | const nameOf = (userId: string) => { | 106 | const nameOf = (userId: string) => { |
| 107 | + // The current user is always resolvable from their own auth record, even | ||
| 108 | + // when the admin-only roster lookup didn't run. | ||
| 109 | + if (userId === meId()) { | ||
| 110 | + const me = auth.user(); | ||
| 111 | + if (me) return [me.name, me.surname].filter(Boolean).join(" ") || me.username; | ||
| 112 | + } | ||
| 98 | const u = (users() ?? []).find((x) => x.id === userId); | 113 | const u = (users() ?? []).find((x) => x.id === userId); |
| 99 | if (!u) return userId; | 114 | if (!u) return userId; |
| 100 | return [u.name, u.surname].filter(Boolean).join(" ") || u.username; | 115 | return [u.name, u.surname].filter(Boolean).join(" ") || u.username; |