Authentication & Security
OpenJam implements session-based authentication with several security measures.
Authentication Flow
- User registers with email, password, and display name
- Password is hashed with bcrypt (default cost)
- A 32-byte cryptographically random session token is generated
- Token is stored in PostgreSQL with an expiration (7 days)
- Token is returned to the client and stored in localStorage
- Subsequent requests include the token in the
Authorization: Bearerheader
Session Management
- Sessions are stored in PostgreSQL with automatic expiration
- Redis caching (when available) reduces database lookups
- Session cache TTL: 15 minutes (refreshed on access)
- Expired sessions are cleaned up hourly by a background routine
- Logout invalidates the session immediately
WebSocket Authentication
WebSocket connections are authenticated before upgrade:
- Client sends the session token as a query parameter
- Server validates the token against the session store
- Only authenticated connections are upgraded to WebSocket
Room Access Control
- Rooms are owned by the user who created them
- Room list only shows rooms owned by the current user
- Room deletion is restricted to the owner
Security Headers
- CORS is configured per environment (restrict
CORS_ORIGINSin production) - Credentials are included in CORS configuration
- Session cookies are set with
HttpOnlyflag
Best Practices for Production
- Change
SESSION_SECRET- Generate a random string:openssl rand -hex 32 - Restrict CORS origins - Set
CORS_ORIGINSto your actual domain(s) - Use HTTPS - Deploy behind a reverse proxy (nginx, Caddy) with TLS
- Change default credentials - Update MinIO and PostgreSQL passwords
- Enable Redis - For session caching and multi-server support
