fix(admin): add zod input validation for /api/admin/users route - #1005
Merged
greatest0fallt1me merged 3 commits intoJul 29, 2026
Merged
Conversation
Adds validate middleware with usersQuerySchema to the GET /api/admin/users endpoint for structured 400 error responses on invalid pagination params. Also adds 'page' field to usersQuerySchema since parsePagination supports it alongside limit/offset. Closes CalloraOrg#872
|
@therealbibson Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Merged into main via admin resolver (-X theirs). |
Contributor
|
LGTM 🎉 merging now. |
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.
Overview
This pull request introduces Zod-based input validation for the GET /api/admin/users endpoint within the admin routes. Prior to this change, the /users route relied solely on a custom parsePagination() utility for query-parameter parsing, which performed inline validation that threw generic ValidationError instances. While functional, this approach lacked a formal, declarative validation boundary at the HTTP layer -- making it inconsistent with the rest of the admin router, which uses the validate() middleware with pre-defined Zod schemas.
The fix adds the existing usersQuerySchema (already defined in src/validators/admin.ts but never wired to the route) as the validation gate for query parameters. Invalid limit, offset, or page values are now caught early with a structured VALIDATION_ERROR envelope, complete with field-level detail arrays, before the request ever reaches the route handler.
Additionally, the usersQuerySchema was extended with a page field to reflect the full set of pagination parameters that parsePagination() supports -- ensuring the schema accurately documents the expected API surface.
Related Issue
Closes #872 -- Add zod input validation for /api/admin [b#007]
Changes
Modified Files
src/routes/admin.ts
src/validators/admin.ts
What This Fixes
Previously, sending GET /api/admin/users?limit=-5 would reach the route handler, where parsePagination() would throw a ValidationError that bubbled up through the error-handling middleware. Now, the same request is rejected at the validation boundary with a clean 400 response before any business logic executes -- consistent with how every other admin route behaves.
Testing and Verification
Unit Tests
Manual Verification Scenarios
Error Envelope Shape
On validation failure, clients receive a JSON response with:
Acceptance Criteria
Documentation
Security Considerations
This PR addresses issue #872 as part of the GrantFox FWC26 campaign. All changes adhere to the repository's lint rules, code style, and testing conventions.