Hardcap: auth middleware en /admin (token + tiempo constante) #21

Open
cayce wants to merge 0 commits from hardcap-admin-auth2 into main
Owner

Auth obligatoria en todas las rutas /admin: Bearer HARDCAP_ADMIN_TOKEN (o X-Admin-Token), timingSafeEqual sobre sha256 (sin leak de longitud). Fail-closed sin token (503). 401s logueados con IP (primera trazabilidad de acceso del admin API). 6 tests, todos verdes en la VPS. Token generado y almacenado solo en .env (nunca impreso).

Auth obligatoria en todas las rutas /admin: Bearer HARDCAP_ADMIN_TOKEN (o X-Admin-Token), timingSafeEqual sobre sha256 (sin leak de longitud). Fail-closed sin token (503). 401s logueados con IP (primera trazabilidad de acceso del admin API). 6 tests, todos verdes en la VPS. Token generado y almacenado solo en .env (nunca impreso).
cayce added 1 commit 2026-10-31 17:40:08 +00:00
hardcap: auth middleware en /admin — token obligatorio, comparación en tiempo constante
ci / lint-test-leaks (pull_request) Canceled after 0s
ci / lint-test-leaks (push) Canceled after 0s
88b2ad2980
- adminAuth: exige Authorization: Bearer <HARDCAP_ADMIN_TOKEN> (o
  X-Admin-Token). Comparación timingSafeEqual sobre sha256 de ambos
  valores (sin leak de longitud ni timing). Fail-closed: sin token
  configurado, TODAS las rutas admin responden 503.
- 401s ahora se loguean con método, ruta e IP (primera trazabilidad de
  acceso que tiene el admin API desde que existe).
- token generado (32 bytes hex) y almacenado SOLO en
  /srv/hardcap-backend/.env — nunca impreso ni versionado.
- test-admin-auth.mjs: 6 tests (sin token, incorrecto, vacío, correcto,
  header alternativo, misma-longitud-distinto) — todos pasan en la VPS.
- desplegado en src + dist; servicio reiniciado y activo.

Nota de contexto: el admin API carecía de auth desde su creación
(index.ts: \x27TODO: add auth middleware before production\x27) y estuvo
alcanzable sin credenciales en :3001 hasta la contención de hoy.
Some required checks failed
ci / lint-test-leaks (push) Canceled after 0s
ci / lint-test-leaks (pull_request) Canceled after 0s
This branch is already included in the target branch. There is nothing to merge.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin hardcap-admin-auth2:hardcap-admin-auth2
git checkout hardcap-admin-auth2
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: cayce/cayce-ops#21