feat: add Zod schema validation for API route inputs#199
Merged
Conversation
|
Thank you @kOaDT for contributing once again! 📊 PR overview
📝 Before reviewTo help maintainers review your changes efficiently, please ensure that:
✅ Continuous IntegrationTwo CI workflows will run automatically on this PR:
You can follow their progress in the Checks tab. 🤝 A note on collaborationWe value respectful and constructive interactions. Whether you are a contributor or a reviewer, please be patient, kind, and open to feedback. A maintainer will review your changes as soon as possible. If you have any questions, feel free to ask in this thread. |
88be6e8 to
b5bdaff
Compare
b5bdaff to
96834e4
Compare
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.
Description
Centralize API input validation using Zod. Adds
lib/validation/withparseBody,parseQuery, andparseParamshelpers returning a tagged union, plus per-domain schemas underlib/validation/schemas/(auth, cart, products, orders, wishlists, admin, gift-cards, coupons, user, support, monitoring, files, documents, tracking, flags, mcp, ai-assistant). Applied to ~30 of 54 API routes (JSON body and query params). Routes consumingmultipart/form-data(image upload) or raw XML are intentionally left untouched, as are GETs without inputs.Validation is structural only (presence + base type), with no regex/sanitization or restrictive
.min()/.max()on attacker-controlled fields, so every intentional vulnerability remains exploitable:products/search,orders/search,admin/reviews): rawz.string(), value flows untouched to$queryRawUnsafe.reviews,user/profile): rawz.string().auth/signup):.passthrough()+ optionalrole./api/files): no sanitization onfile/path.orders/[id],user/profile): theapplication/x-www-form-urlencodedbranch is left out of Zod; only the JSON branch is validated.supportscreenshotUrl,ai-assistantmcpServerUrl):z.string(), no URL format check.user/export): only structure validated, leaky error path preserved.auth/login): log statement runs against the validated value but unchanged.Adds
zod@^4to rootpackage.json.#82
Type of change
Testing done
npm run lint— 0 errors (only pre-existing warnings).npm run build— passes.npm run test:unit— 47/47 passing.npm run test:api) and Cypress E2E (npm run test:e2e) should be run before merging — they're the regression suite that asserts every vulnerability remains exploitable, which is the load-bearing check for this change.Checklist