Skip to content

fix: admin job routes use the same session checks as the other admin routes - #475

Merged
kikootwo merged 3 commits into
mainfrom
fix/admin-job-routes-auth
Oct 27, 2026
Merged

kikootwo merged 3 commits into
mainfrom
fix/admin-job-routes-auth

Conversation

@kikootwo

Copy link
Copy Markdown
Owner

What changed

  • The scheduled-job routes and the job-status route now go through requireAuth + requireAdmin (src/lib/middleware/auth.ts), the same pattern as the other admin routes:
    • src/app/api/admin/jobs/route.ts (GET, POST)
    • src/app/api/admin/jobs/[id]/route.ts (PUT, DELETE)
    • src/app/api/admin/jobs/[id]/trigger/route.ts (POST)
    • src/app/api/admin/job-status/[id]/route.ts (GET)
  • Each request must now come from an account that still exists, whose sessions were not revoked after the token was issued, and the session must be an admin session. API tokens are refused with 403: none of these routes is on the API-token allowlist (src/lib/constants/api-tokens.ts), which is unchanged.
  • Success responses, the 404 and the 500s are unchanged. The refusals use the standard bodies from the middleware ({ error: 'Unauthorized' | 'Forbidden', message }), and an invalid or expired token now gets 401 instead of 403, so the admin Jobs page refreshes an expired token and retries like the other admin pages.
  • Docs: documentation/backend/services/auth.md (one Fixed Issues line).

Why

These routes checked the token's signature and role themselves and did not look the account up, unlike the other admin routes.

Evidence

  • New tests/api/admin-job-routes.access.test.ts runs the real auth middleware against all six handlers: a deleted admin, a missing account row and a token issued before the sessions were revoked get 401; a signed-in non-admin and an API token get 403; no token gets 401; none of these reach the scheduler or job queue. A valid admin gets 200 with exactly the response the handler gave before, and the body and route id reach the service unchanged.
  • On main (b94297f) with this test file: 18 failed, 25 passed, all on an assertion (expected 200 to be 401: the 3 deleted/missing/revoked cases for each of the 6 handlers). On this branch: 43/43 pass.
  • tests/api/admin-jobs.routes.test.ts and tests/api/admin-job-status.routes.test.ts now mock the user lookup the middleware makes and read the 403 reason from message.

Checks

  • Unit tests for the changed code (vitest related on the 4 route files, which includes the new test file): PASS, 3 files, 65/65
  • Type check and lint: PASS (tsc --noEmit clean; ESLint on the 7 touched files: no new findings, the 23 pre-existing no-explicit-any in the two older test files are the same as on main)
  • Image build + smoke (npm run e2e -- --specs smoke, image rmab-e2e/t69:90a2080): PASS, 1/1; in that stack the admin session listed the scheduled jobs and triggered a scheduled job through these routes
  • Full unit suite: PR Tests (CI)

Risk and rollback

  • Each request to these routes now makes one user lookup, as every other admin route does.
  • The setup wizard calls these routes with the new setup admin's session, which exists and is not revoked, so it passes the same checks.
  • Clients that read the old 403 text Forbidden - Admin access required from error get Forbidden with the reason in message. No page reads error; the Jobs page now shows the reason from message.
  • Rollback: revert this PR. No data or schema changes.

Release note

  • Admin job routes use the same session checks as the other admin routes.

🤖 Generated with Claude Code

kikootwo and others added 3 commits October 27, 2026 03:22
The scheduled-job routes (list, create, update, delete, trigger) and the job-status route now go through requireAuth + requireAdmin like the other admin routes, so the account must still exist, its sessions must not be revoked, and it must be an admin. Success responses are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kikootwo
kikootwo merged commit d72326a into main Oct 27, 2026
1 check passed
@kikootwo
kikootwo deleted the fix/admin-job-routes-auth branch October 27, 2026 07:59
@kikootwo kikootwo mentioned this pull request Oct 27, 2026
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