Security & Authentication#
Authentication and authorization are assembled declaratively by litestar-security in
app.domain.accounts.security.build_security_config.
Key Capabilities#
Fail-Closed Controllers: Protected routes subclass
SecureController; public routes explicitly subclassPublicControlleror opt in via@public. Audit every route with:uv run app security routesCookie Sessions & CSRF:
LocalAuth.sessionstores server-side sessions in PostgreSQL viaSQLAlchemyStoreonapp_storewithHttpOnly,SameSite=Laxcookies and HKDF-derived CSRF tokens (XSRF-TOKEN/X-XSRF-TOKEN).Step-Up TOTP MFA: Encrypted TOTP secrets (
AESGCMSecretProtector) and peppered recovery codes enforcerequire_at_login="enrolled"with single-use login challenges and step-up grants (totp-enroll,totp-remove,recovery-codes).WebAuthn Passkeys: Credential registration and assertion verification are stored in
auth_passkeyandauth_passkey_challenge.OAuth2: Optional GitHub OAuth2 enabled via
GITHUB_OAUTH2_CLIENT_ID/GITHUB_OAUTH2_CLIENT_SECRET, mounted under/api/auth/oauth/github/.... The callback must be served over HTTPS, soAPP_URLneeds anhttps://origin whenever GitHub sign-in is enabled.Personal API Keys: Self-service hashed keys under
/api/me/api-keyssupport Bearer authentication, rotation, revocation, and scoped access to/mcp.Password Policy: One
PasswordPolicy(PASSWORD_POLICYinapp.domain.accounts.services) decides every new password: sign-up, password reset, password change, admin user create and update, andapp users create-user. A password is 12 to 128 characters long and is not on the common-password list; no character classes are required. It also may not repeat the account’s email address, which password reset alone does not check. A rejected password answers400.Password Confirmation: Creating, rotating, or revoking an API key, changing the password, and deleting the account are admitted within five minutes of sign-in. After that the request must carry
currentPassword; without it the API answers403withcodeset toreauthentication_requiredand the SPA prompts for the password and retries.Application Access: Every account is created with the
Application Accessrole, which is required to use the application. A signed-in user who holds neither that role norSuperusergets403withcodeset toapplication_access_requiredon every route except sign-out.Error Responses: Errors are
application/problem+jsonwithstatus,title(the HTTP reason phrase),detail(the human-readable message), and, where relevant, a machine-readablecode. A request body that breaks a field rule answers400and lists each offending field underextraasmessage,key, andsource.Email Verification:
REGISTRATION_REQUIRE_VERIFICATION(defaulttrue) decides whether new password accounts must confirm their email address before signing in.Tenant & Role Guards: Team routes enforce
requires_team_role("member" | "admin" | "owner")and admin routes enforcerequires_role("superuser")viaAppAuthorizationResolver.