Skip to content

Rebuild Architecture - #1

Merged
ZeroElemental merged 3 commits into
mainfrom
rebuild
Aug 26, 2026
Merged

ZeroElemental merged 3 commits into
mainfrom
rebuild

Conversation

@ZeroElemental

Copy link
Copy Markdown
Owner

Rebuilt the architecture and environment for

…stack

Access control now lives in Postgres RLS instead of hand-written controller
checks, which closes the whole class of holes the old server had:

- Socket.IO had no auth at all: any client could emit addUser/joinRoom with
  another user's id and receive their messages. Realtime channels are now
  private and authorized against realtime.messages RLS.
- Messages were broadcast by the sender's browser, so sender identity was
  spoofable. Rows are persisted first and fanned out by a database trigger;
  the insert policy pins sender_id to auth.uid().
- acceptFriendRequest never checked a request existed, so anyone could
  force-friend anyone. It is now an atomic function that verifies a pending
  row and raises otherwise.
- Auth middleware called next() when the user lookup returned null. Replaced
  by Supabase Auth with httpOnly cookie sessions and getClaims() in the proxy,
  so the 30-day localStorage JWT is gone.
- Presence replaces the in-process onlineUsers Map, which was wrong at more
  than one instance, and also carries typing state.
- Messages are paginated and unread counts come from last_read_at, so a
  message no longer gets dropped when its chat isn't open.
- Attachments moved from unbounded multer/Cloudinary to a private Storage
  bucket with a size limit and a MIME allowlist.

Verified against the live project: a non-member reads zero rows from every
table, cannot join a conversation channel, cannot mint a signed attachment
URL, and cannot forge a message as another user.
- Sentry wired for client, server and edge via instrumentation files, with
  onRequestError so Server Component and Server Action failures are reported.
  Verified end to end: a thrown route handler produced PIXELCHAT-1 in Sentry.
- supabase/tests/rls_test.sql asserts the isolation and integrity properties
  the old server got wrong: non-members read nothing, senders cannot be
  forged, stored messages cannot be edited or deleted, and a friend request
  cannot be accepted unless one is pending. Self-seeding and self-cleaning.
- CI runs typecheck, lint and build on pushes and pull requests.
- README documents the new stack and the access-control model, replacing the
  Render/Mongo/Cloudinary instructions which no longer apply.
Two problems the runtime check surfaced:

- `?next=` was passed straight into redirect() after sign-in, so
  /login?next=https://evil.com sent the user off-site with a fresh session.
  safeRedirectPath() now accepts only same-origin absolute paths, rejecting
  scheme-relative forms like //evil.com and /\evil.com that browsers resolve
  to another host.
- The login and signup pages rendered an empty shell: useSearchParams() in the
  form bailed the whole subtree out to client rendering. `next` now comes from
  the page's searchParams on the server and is passed down as a prop, so both
  pages server-render and the Suspense wrappers are gone.

Covered by src/lib/validation.test.ts, run with node --test and wired into CI.
@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pixel-chat Error Error Aug 26, 2026 2:36pm
pixel-chat-imp Error Error Aug 26, 2026 2:36pm

@ZeroElemental
ZeroElemental merged commit 6099206 into main Aug 26, 2026
3 of 5 checks passed

This branch had an error being deployed

2 failed deployments
Preview – pixel-chat — f8a78ce7 Deployed Aug 25, 2026 by vercel[bot]
Preview – pixel-chat-imp — f8a78ce7 Deployed Aug 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant