Authentication and Permissions
Source: equa-server/modules/auth/src/
Authentication Methods
Equa supports three authentication methods, all resulting in a server-side session.1. Password Login
Source:equa-server/modules/auth/src/authentication.ts
- Password hashing:
bcryptjs(10 rounds) - Two-factor authentication: Supported via
twoFactorToken - Email verification: Required before login
- Temporary passwords: Supported via
checkTempPassword() - On success:
session.user = result.user.id(line 72)
2. Google OAuth
Source:equa-server/modules/auth/src/google-auth.ts, equa-server/modules/api/src/server.ts
- Supports both ID tokens and access tokens
- Validates email verification status
- Checks audience (
aud) matches client ID - Validates
g_csrf_tokencookie/body consistency in API middleware before Google auth endpoint execution - Auto-registration: Creates user if email not found (random password assigned)
- On success:
session.user = user.id(line 88)
3. Magic Links
Source:equa-server/modules/auth/src/magic-link.ts
Note:magic-link.tsis currently an untracked file in the equa-server repo. It imports aMagicLinksentity frompersistencethat has not yet been added toschema.ts. This feature is in development but not yet integrated into the database schema.
Functions:
sendMagicLink()— Creates magic link record and sends emailverifyMagicLink()— Validates token, checks expiry, marks as usedmagicLinkLogin()— Creates session after verificationcleanupExpiredMagicLinks()— Cleanup for expired links
Session Management
Source:equa-server/modules/auth/src/sessions.ts
Sessions are persisted in the
sessions table with columns: id, expires (indexed), user (indexed), json.
Authorization Model (RBAC)
Source:equa-server/modules/auth/src/authorization.ts, equa-server/docs/cascading-permission.puml
Entities
Permission Check Flow
- Endpoint declares
requires?: PermissionCheckproperty - vineyard-lawn calls the permission check function before the handler
- Check verifies:
- User is logged in (
requireLoggedInSync()) - User has required role/permission for the target organization
- User is logged in (
- If check fails, returns 403 Forbidden
Key Authorization Functions
Source:equa-server/modules/auth/src/authorization.ts
Cascading Permission Model
Source:equa-server/docs/cascading-permission.puml
The cascading permission model supports nested organizations with permission inheritance:
- Direct permissions: User has a role directly assigned in the organization
- Indirect permissions: User inherits permissions from a parent organization
- Union: For read operations, permissions from parent and child are combined
- Intersection: For write operations, only overlapping permissions apply
Role Tables
Permission Enumeration
Source: Confluence KnowledgeBase — Equa App Permissions (by Christopher Johnson)
Organization Permissions (15)
Site Permissions (2, for site admins only)
The authorization module maps these to endpoint-level checks:
requirePermissions()— generic permission checkcanWriteSite()/canReadSite()— site-level admin accesscanEditCapTable,canViewOrganization,canEditMembers,canEditOrganizationBilling, etc. — organization-level checks used in endpoint definitions
Security Notes
- No explicit rate limiting middleware found in the codebase
- Registration IP limit:
REGISTRATION_IP_LIMIT(default: 20; applied inmodules/referral/src/referral.ts) - Domain blacklist:
domain_blackliststable - Email blacklist:
email_blackliststable - Email verification required before login
- Two-factor authentication supported but optional