Repository navigation
Conversation
- Parse dates with new Date() and check isValid() before querying; return 400 on invalid date strings instead of Mongoose CastError 500 - Add allow-list for sortBy field names to prevent arbitrary sort keys - Add allow-list for sortOrder values (asc/desc) with safe defaults
|
@Kirtan-pc is attempting to deploy a commit to the Nitya Gosain's projects Team on Vercel. A member of the Team first needs to authorize it. |
Nitya-003
approved these changes
Aug 18, 2026
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.
Summary
This PR fixes Issue #1237:
getAllBatchesinbatchController.jsparses start/end dates with barenew Date(start)and passes the raw client value straight into.sort({...}). Invalid dates produce a Mongoose CastError → 500, and unvalidated sort keys let a client request arbitrary/malformed sort fields.Changes
backend/controllers/batchController.js:350-368): Dates are now parsed into temporary variables and validated withisNaN(parsedDate.getTime())before being used in the query. Invalid dates return a 400 response with a descriptive error message instead of triggering a Mongoose CastError 500.backend/controllers/batchController.js:378-403): AddedALLOWED_SORT_FIELDScontaining only safe, indexed fields (createdAt,updatedAt,batchId,farmerName,cropType,quantity,harvestDate,currentStage,status,origin). ThesortByparameter is validated against this list and falls back tocreatedAtif an unsupported field is provided.ALLOWED_SORT_ORDERSrestricts values to"asc"/"desc"with"desc"as the safe default.Fixes #1237
Copilot Review Feedback
Other suggestions were evaluated but intentionally left unchanged because they are pre-existing issues outside the scope of Issue #1237: