Repository navigation
fix: admin job routes use the same session checks as the other admin routes - #475
Merged
Merged
Conversation
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>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
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)src/lib/constants/api-tokens.ts), which is unchanged.{ 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.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
tests/api/admin-job-routes.access.test.tsruns 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.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.tsandtests/api/admin-job-status.routes.test.tsnow mock the user lookup the middleware makes and read the 403 reason frommessage.Checks
vitest relatedon the 4 route files, which includes the new test file): PASS, 3 files, 65/65tsc --noEmitclean; ESLint on the 7 touched files: no new findings, the 23 pre-existingno-explicit-anyin the two older test files are the same as onmain)npm run e2e -- --specs smoke, imagermab-e2e/t69:90a2080): PASS, 1/1; in that stack the admin session listed the scheduled jobs and triggered a scheduled job through these routesRisk and rollback
Forbidden - Admin access requiredfromerrorgetForbiddenwith the reason inmessage. No page readserror; the Jobs page now shows the reason frommessage.Release note
🤖 Generated with Claude Code