LiveBoard is a casual, real-time league-table simulator. Rooms, guesses, a live leaderboard among friends. It doesn't touch payment data, and the only sensitive-ish data it holds is a Google account's basic profile (name, email, avatar) and optional room passwords. The threat model is light accordingly. This isn't a bank's security doc, but real accounts and real passwords exist, so login and room passwords get treated seriously even though the rest of the stack is deliberately unhardened for a small deployment. For how identity/ownership/permissions actually work, see architecture_auth_and_permissions.md.
realtime/src/server.tssets CORS to a single configured origin (cors({ origin: CORS_ORIGIN, exposedHeaders: ["X-Room-Token"] }), both on the Express app and the Socket.io server), not a wildcard.exposedHeadersis needed only so browser JS can readX-Room-Tokenoff a cross-origin response.- Both
realtime(Express) andfrontend(Next.js) listen in plain HTTP. Neither app terminates TLS itself. There's nonginx/caddy/traefikconfig anywhere in this repo, anddocker-compose.ymlmaps ports straight to the containers (4000:4000,3000:3000) with no proxy in front. TLS is expected to terminate at a reverse proxy you run in front of the stack, which this repo does not ship (see the gaps and checklist below, anddocs/deployment.md).
- Google ID tokens are verified server-side via
google-auth-library'sOAuth2Client.verifyIdToken({ idToken, audience: GOOGLE_CLIENT_ID })(realtime/src/auth/googleVerify.ts). The audience check stops a token issued for some other Google client id from being accepted here. - Session tokens are a hand-rolled HMAC scheme, not a JWT library:
<base64url(userId.jti.expiresAt)>.<hmac-sha256 hex>, signed withAUTH_TOKEN_SECRET(realtime/src/auth/token.ts). Verification usestimingSafeEqualfor the signature comparison and checks expiry before trusting the payload. TTL is 24 hours. - Logout revokes a single token by its
jti:session_revoked:<jti>is written to Redis with a TTL equal to the token's remaining lifetime, andverifyAuthTokenchecks that key on every use. A logged-out token stops working immediately, rather than staying valid until its signature-checked expiry.
- Room passwords are hashed with salted scrypt, not stored or compared in plaintext (
realtime/src/rooms/password.ts):scryptSync(password, salt, 64), salt israndomBytes(16), stored as"<salt-hex>:<hash-hex>". Verification usestimingSafeEqual(after a length check, sincetimingSafeEqualthrows rather than returningfalseon mismatched buffer lengths). - Room tokens (
realtime/src/rooms/roomToken.ts) are the same HMAC-signed pattern as session tokens, but scoped toroomId + passwordVersionand signed with a separate secret (ROOM_TOKEN_SECRET). TTL is 12 hours, with sliding renewal on every authenticated request. BecausepasswordVersionis folded into the payload, changing a room's password immediately invalidates every token minted under the old password, not just after their own TTL expires. - Access to a password-protected room is checked in a fixed three-tier order (
checkPasswordAccessinrealtime/src/routes/rooms.ts, mirrored in the socketjoin-roomhandler): (1) the room's logged-in owner bypasses the password entirely; (2) a validX-Room-Tokenis accepted; (3) the rawX-Room-Passwordheader is checked against the scrypt hash. Guests never get the owner bypass, only a signed-inUser.idmatch does.
- Room admins can kick a live participant (
admin-kicksocket event,realtime/src/socket/index.ts), which force-disconnects their socket and also writesroom_ban:<roomId>:<identityKey>to Redis with a 7-day TTL (KICK_BAN_TTL_SECONDS). A futurejoin-roomfrom that same identity is rejected withjoin-error { reason: "banned" }before a participant record is even created. It's the only abuse-mitigation mechanism in the app today. Per-room and identity-scoped, not IP-based, and (see below) nothing stops repeated attempts at the things that matter more, like password guessing or login.
POST /reports takes free text from anyone, signed in or not, and writes it to Postgres. Four things limit the damage. reportLimiter allows 10 requests per hour per IP. validateReportBody caps every field (120 characters for the title, 4000 for the description) and rejects an unknown problem type. The route ignores any userId in the body and reads the user from the session token, so nobody can file a report under another account. The admin panel shows the text as plain text, not HTML. The email address is not verified, so a report proves nothing about who sent it.
- Guest ids are entirely client-generated (
crypto.randomUUID(), cached inlocalStorage) and never issued or stored server-side. The server's only check is a format guard,^[A-Za-z0-9-]{1,64}$(GUEST_ID_PATTERNinrealtime/src/auth/identity.ts), which exists purely to bound the value as a Redis-key/ownership-comparison input, not to establish any real trust. Anyone can claim any guest id that matches the pattern. The security boundary that actually matters (room ownership, admin rights) rests on a signed session token for logged-in users, and on "whoever happens to hold this guest id string" for guests. A deliberately weak tradeoff, and an accepted one, given this app's stakes.
These are honest gaps, not oversights hidden from the reader. Worth noting, low urgency for the current deployment scale:
- No rate limiting anywhere.
POST /auth/google, room password checks (GET /rooms/:id/statewithX-Room-Password), room creation, and every other route are completely unthrottled. Nothing stops scripted room-password brute-forcing or hammering the Google-token-verification endpoint today. Noexpress-rate-limit(or equivalent) dependency exists inrealtime/package.json. - No
helmet(or similar) security-headers middleware.realtime/package.jsonhas nohelmetdependency;server.tssets no security headers beyond what Express does by default, which is close to nothing: noX-Content-Type-Options, noStrict-Transport-Security, no CSP. - No HTTPS/TLS termination inside the app stack. Both apps serve plain HTTP; TLS has to be handled by a reverse proxy in front of the VPS. This repo ships no proxy config. See
docs/deployment.mdfor deployment specifics. - No DDoS protection layer. Nothing beyond whatever the hosting provider offers by default.
- Secrets silently fall back to a random per-restart value if unset, rather than failing loudly:
AUTH_TOKEN_SECRET: unset means a fresh random secret is generated on every process start, which silently invalidates every existing session token on every restart.docker-compose.yml(the production compose file) guards this one with Compose's:?required-variable syntax, so a production deploy without it set fails to start.docker-compose.dev.ymland running the server directly (npm start/tsx) have no such guard.ROOM_TOKEN_SECRET: same fallback behavior and same blast radius (a 12h room-access token, not a login session). It's now listed inrealtime/env.exampleand guarded by the same:?required-variable syntax indocker-compose.yml, matchingAUTH_TOKEN_SECRET. Running the server directly, ordocker-compose.dev.yml, still has no such guard, same asAUTH_TOKEN_SECRET.
- No consistent input-validation library. There's no
zod/joi/express-validator/yupanywhere inrealtime/. Request body validation is ad hoctypeof/length checks scattered acrossrealtime/src/routes/*.ts(e.g.rooms.ts'schampionshipName/password/displayNamechecks). It works, but there's no shared schema layer, so it's easy for a new route to skip validation it should have. - Guest identity is trivially spoofable/resettable. Clearing site data or switching browsers produces a new guest id, sidestepping room ownership and ban state. An accepted tradeoff for this app's stakes, not something planned to be fixed. See
docs/architecture_auth_and_permissions.md§8 "Known limitations" for the fuller list, including the related admin/ownership caveats.
Practical steps matched to the gaps above, roughly in priority order:
- Put a reverse proxy (nginx or Caddy) in front of both services, terminating TLS there and forwarding to
realtime:4000/frontend:3000over plain HTTP internally. Caddy in particular gets automatic Let's Encrypt certs with minimal config. This also gives you a natural place to add a global rate limit / connection cap before traffic even reaches the app. - Set
AUTH_TOKEN_SECRETandROOM_TOKEN_SECRETexplicitly in your production environment.docker-compose.ymlfails fast if either is missing, but that only helps if you're actually deploying through it. Runrealtimeany other way and it still falls back to a random per-restart secret silently. - Add
express-rate-limit(or equivalent) onPOST /auth/google(login-attempt throttling) and specifically on the room-password check path (GET /rooms/:id/statewithX-Room-Password, and the socketjoin-roomhandler's password branch) to make brute-forcing a room password impractical. - Add
helmettorealtime's Express app for baseline security headers. Cheap to add, no known downside for this app. - If traffic or abuse patterns justify it, put the whole stack behind a provider with basic DDoS protection (e.g. Cloudflare in front of the reverse proxy) rather than building anything custom.