Jannis Braun 3c7bb02901 fix(dm): ownership transfer divergence after back-and-forth — canonicalize ownerHomeInstance + normalize authority checks
Manual ownership transfers between two federated instances diverged because
`dm_channels.ownerHomeInstance` was stored as a BARE host (`orbit.ddns.net`)
for federated owners — via `transferGroupDmOwnership` copying `users.homeInstance`
verbatim — while `sourceInstance` always arrives as a full URL on the wire.
`processOwnershipTransferEvent` and `processMemberRemoveEvent` then compared the
two with strict equality and rejected legitimate inbound events as
`unauthorized_source`, keeping ownership permanently divergent across peers.
Live DB inspection on the two test instances confirmed both rows (nova + orbit)
had a BARE `owner_home_instance`, matching the bug report exactly.

Three compounding fixes:

1. Receiver authority checks now compare via `normalizeOriginForCompare` so
   legacy bare-vs-full rows accept legitimate transfers (and kicks).
2. New `canonicalizeHomeInstance` helper in `federationAuth.ts`; every write
   site that persists `ownerHomeInstance` (`transferGroupDmOwnership`, group DM
   creation, lazy federation in member-add, `processMemberAddEvent` bootstrap,
   `processOwnershipTransferEvent` receiver storage) routes through it. Full URL
   is the canonical storage form, matching how `sourceInstance` arrives.
3. `dm_owner_updated` WS event extended with optional `newOwnerHomeUserId` and
   `newOwnerHomeInstance` fields. Client `updateDmOwner` writes them when
   present and leaves existing values untouched otherwise (legacy-server safe).
   Without this, `getOwnerInstanceForDm` returned the previous owner's home
   after a successful WS broadcast, routing the next owner-only op to the wrong
   instance.

Coverage: new `federation.ownershipTransfer.test.ts` (7 receiver tests including
the headline bare-vs-full regression and the dedup replay guard); new bare-vs-full
case in `federation.kick.test.ts`; two new client-side cases in
`groupDm.ownerRouting.test.ts` covering both the extended-payload write path and
the legacy-server passthrough. Tests: 1053 server + 364 web, all green.

Specs updated: `dm-system.md` historical bugs + frontend handler table + WS
state-change events table; `federation.md` `ownership_transfer` receiver flow;
`websocket.md` event-fields table.
2026-05-10 22:38:03 +02:00

Backspace

Open-source, self-hosted Discord alternative built with TypeScript.

Features

  • Real-time text messaging with WebSocket
  • Servers, channels, and role-based permission management
  • Voice and video chat via LiveKit
  • Screen sharing with configurable quality (VP9)
  • Direct messages (1-on-1 and group DMs up to 10)
  • DM voice/video calls with ringing
  • Friend system with requests
  • File uploads and image sharing
  • Markdown message formatting with syntax highlighting
  • Message reactions, replies, and editing
  • Typing indicators, presence status, and read states
  • Invite system with shareable codes
  • Instance-level admin panel (streaming limits)
  • Desktop app (Electron)
  • Mobile-responsive web UI
  • Docker deployment

Tech Stack

Layer Technology
Backend Fastify + TypeScript
Database SQLite (better-sqlite3) + Drizzle ORM
Auth JWT + bcrypt
Real-time WebSocket (ws)
Frontend React 18 + Tailwind CSS + Zustand
Voice/Video LiveKit
Desktop Electron
Build Vite + pnpm workspaces

Quick Start with Docker

# Clone the repository
git clone https://github.com/your-username/backspace.git
cd backspace

# Create environment file
cp .env.example .env

# Generate a JWT secret
echo "JWT_SECRET=$(openssl rand -hex 32)" >> .env

# Start Backspace
docker compose up -d

Open http://localhost:3000 in your browser. A default server "Backspace" is created automatically.

Default admin account: admin / admin123 (change this after first login).

Development Setup

Prerequisites

  • Node.js 20+
  • pnpm 8+

Install

pnpm install

Configure

cp .env.example .env
# Edit .env with your settings (generate a JWT_SECRET)

Run

# Start both server and web dev server
pnpm dev

# Or start individually
pnpm dev:server    # API server on :3005
pnpm dev:web       # Vite dev server on :5173

Build

pnpm build

This builds the shared types, server, and web frontend. The server serves the built frontend in production mode.

Project Structure

Backspace/
├── packages/
│   ├── shared/       # Shared TypeScript types & permissions
│   ├── server/       # Fastify API + WebSocket server
│   ├── web/          # React frontend (Vite + Tailwind)
│   └── desktop/      # Electron desktop app
├── data/             # SQLite DB + uploads (created at runtime)
├── Dockerfile
├── docker-compose.yml
└── .env.example

Voice & Video

Voice and video requires a LiveKit server. Set these in your .env:

LIVEKIT_URL=wss://your-livekit-server
LIVEKIT_API_KEY=your-api-key
LIVEKIT_API_SECRET=your-api-secret

Without LiveKit configured, text chat works fully but voice/video channels will not connect.

API

The server exposes a REST API and WebSocket endpoint:

  • REST API: http://localhost:3000/api/*
  • WebSocket: ws://localhost:3000/ws
  • Health check: GET /api/health

See CLAUDE.md for the full API reference.

Desktop App

The Electron desktop app wraps the web UI and adds system tray, notifications, and native window controls.

cd packages/desktop
pnpm build:ts    # Compile TypeScript
pnpm dev         # Run in development
pnpm build       # Package for distribution

License

MIT

S
Description
Fork proprio do Backspace — instancia chat.resenha.website
Readme AGPL-3.0
21 MiB
Languages
TypeScript 96.8%
HTML 1.3%
Shell 1.1%
JavaScript 0.4%
CSS 0.3%