Guide to the authentication and authorization system in Docklift.
Docklift uses a token-based authentication system (JWT) to secure the API and frontend.
backend/src/routes/auth.tsbackend/src/lib/authMiddleware.tsbackend/src/lib/originCheck.ts (CORS + WebSocket)frontend/src/components/AuthProvider.tsxfrontend/src/lib/auth.ts (getAuthHeaders, authFetch, fetchWithAuth)User (email, password hash, role, passwordChangedAt).Registration:
POST /api/auth/registerx-bootstrap-secret or body) — printed by install /
backend logs / data/.bootstrap-secret. Never returned by a public API.fs.rename of data/.bootstrap-secret → .claimed-<random>
(lib/bootstrap.ts). Only the winner may create the admin; losers get 403.recoverStaleBootstrapClaims() restores a leftover
.claimed-* back to .bootstrap-secret so setup is not bricked./register and /setup-token use a stricter limiter (10 / 15 min)
in addition to the general auth limiter.Login:
POST /api/auth/logintoken (7-day expiry) that includes a pwdv claim.express-rate-limit on all /api/auth routes (100 / 15 min general).Session Management:
localStorage key docklift_token.authFetch() for protected APIs — it attaches the Bearer header and on 401
clears storage + calls logout() (registered from AuthProvider). Prefer it over raw
fetch + getAuthHeaders().AuthProvider.tsx validates /api/auth/me on page load and clears invalid tokens.pwdv === passwordChangedAt.getTime().
Exact match (not iat comparison) — same-second reissue after password change works correctly.All routes except the following require JWT via authMiddleware:
/api/auth/register, /api/auth/login, /api/auth/status (public, rate limited)/api/github/webhook, /manifest/callback, /setup (GitHub App flow)
/api/github/callback OAuth token exchange is disabled (install-id redirect only)/api/backup/restore-upload with valid setup token (fresh install restore; token consumed only
after successful restore — see lib/setupRestoreAuth.ts)Routes /me, /profile, /change-password all use authMiddleware (not manual JWT decoding).
Server-Sent Events (logs) use short-lived tokens instead of long-lived JWTs in URLs:
POST /api/auth/sse-token → returns a 5-minute JWT with purpose: 'sse' (requires Bearer session JWT)?token=<sseToken>authMiddleware: Authorization: Bearer session JWT only — no query tokenssseAuthMiddleware: query ?token= with purpose === 'sse' onlyGET /api/system/logs/:serviceGET /api/logs/:projectId/stream/:containerNameLocated in backend/src/lib/authMiddleware.ts.
authMiddleware: Bearer session JWT; rejects SSE-purpose tokens; never reads ?token=;
rejects when pwdv is missing or does not match passwordChangedAt.sseAuthMiddleware: Query SSE token only; rejects tokens without purpose: 'sse'; same pwdv check.config.dataPath (never a hardcoded ./data).catch blocks in auth routes return generic messages (e.g., 'Login failed'), never error.message.index.ts (X-Content-Type-Options, X-Frame-Options, X-XSS-Protection, Referrer-Policy, Permissions-Policy, plus HSTS when the request arrived over HTTPS). Helmet is not used.isTrustedOrigin(), plus any
exact origins configured in CORS_ORIGIN. See the security_hardening skill for why hostname-only
matching is unsafe here./api/auth routes./api/system/upgrade, update-system, reboot, reset, purge) and deployment restore (POST /api/deployments/:projectId/rollback): session JWT plus requireStepUpPassword body password. Canceling the password dialog must not call these APIs.fetch + Authorization: Bearer header + blob download pattern — never put JWTs in URL query parameters (prevents token leakage in browser history, server logs, and referrer headers).bcrypt with 12 salt rounds.cd backend
bun run reset-password
localStorage.npx skills add SSujitX/Authentication System下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer