Skip to content

feat(auth): optional password login for the UI#1

Merged
jodacame merged 1 commit into
mainfrom
feat/ui-auth
Jul 1, 2026
Merged

feat(auth): optional password login for the UI#1
jodacame merged 1 commit into
mainfrom
feat/ui-auth

Conversation

@jodacame

@jodacame jodacame commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Qué hace

Añade autenticación opcional por contraseña para el frontend. Está desactivada por defecto (deployments abiertos siguen igual) y se activa con FT_AUTH_PASSWORD.

Backend

  • Login de sesión: POST /api/login valida la contraseña (comparación en tiempo constante) y emite una cookie HttpOnly + SameSite firmada con HMAC (secreto aleatorio por arranque). Secure automático en HTTPS (respeta X-Forwarded-Proto). Duración vía FT_AUTH_SESSION_HOURS (default 7 días).
  • Rate-limit por IP en el login: 5 fallos → bloqueo de 5 min (429 + Retry-After).
  • GET /api/auth (estado) y POST /api/logout.
  • withAuth acepta cookie de sesión O el FT_API_TOKEN Bearer existente. Protege la UI + /api/*; deja abierto /stream y compat.
  • Mutaciones de compat protegidas (rem/set en /torrents, set en /settings); add/get/drop/list y streaming siguen abiertos → los reproductores (Kodi/Stremio/VLC) no se rompen.

Frontend

  • AuthGate resuelve el estado al cargar, muestra la pantalla de Login cuando hace falta y vuelve a login ante un 401 a mitad de sesión.
  • Cliente API: authStatus/login/logout + manejo global de 401.
  • Botón de logout en la barra; textos en en/es.

Docs

Tabla de env vars, subsección Authentication, notas de seguridad y ejemplo de docker-compose.

Verificación

  • Backend: go build + go vet + tests en verde (incluye auth_test.go: firma/expiración de token, lockout, cookie end-to-end).
  • Frontend: tsc + vite build OK.
  • Probado en vivo en contenedor: login/logout, cookie Secure sobre HTTPS, rem/set401 sin sesión y 200 con sesión, rate-limit → 429.

🤖 Generated with Claude Code

Add opt-in single-password authentication, off by default so existing open
deployments are unchanged. Enable it by setting FT_AUTH_PASSWORD.

Backend (internal/api/auth.go):
- Session login: POST /api/login verifies the password (constant-time) and
  issues an HMAC-signed, HttpOnly, SameSite cookie (Secure over HTTPS, honoring
  X-Forwarded-Proto). Lifetime via FT_AUTH_SESSION_HOURS (default 7 days).
- Per-IP login rate limiting (5 fails -> 5 min lockout) to resist brute force.
- GET /api/auth status + POST /api/logout.
- withAuth accepts either a session cookie or the existing FT_API_TOKEN bearer;
  gates the UI and /api/*, leaving /stream and player-compat routes open.
- Gate the mutating TorrServer-compat actions (rem/set on /torrents, set on
  /settings) behind auth; add/get/drop/list and streaming stay open so players
  keep working.

Frontend:
- AuthGate resolves auth state on load, renders the Login screen when required,
  and drops back to login on a mid-session 401.
- api client: authStatus/login/logout + global 401 handler.
- Logout button in the toolbar; en/es strings.

Docs: README env table, an Authentication subsection, security notes, and a
docker-compose example.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012bj3G2zzqEaALFa8ufbkDJ
@jodacame
jodacame merged commit c7736f5 into main Jul 1, 2026
2 checks passed
@jodacame
jodacame deleted the feat/ui-auth branch July 1, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant