fix(flashcard): add ObjectId validation to reviewFlashcard and deleteFlashcard (#1197) - #1528
Open
suhaniiz wants to merge 1 commit into
Open
fix(flashcard): add ObjectId validation to reviewFlashcard and deleteFlashcard (#1197)#1528suhaniiz wants to merge 1 commit into
suhaniiz wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe flashcard controller now validates IDs before review and delete queries. Invalid IDs return HTTP 400. Stats calculation preserves the current timestamp while deriving the start-of-day value. ChangesFlashcard controller updates
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
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.
📝 Pull Request Description
Related Issue
Closes #1197
Summary
Passing a malformed or non-24-character hexadecimal string as an
:idparameter inPUT /api/flashcards/:id/revieworDELETE /api/flashcards/:idcaused Mongoose to throw an unhandledCastError. This was caught by the genericcatchblock, returning a500 Internal Server Errorinstead of a user-facing validation error.This PR adds early
mongoose.Types.ObjectId.isValid(id)validation checks to bothreviewFlashcardanddeleteFlashcardcontrollers, returning a400 Bad Requestwith{"success": false, "message": "Invalid flashcard ID format"}when an invalid ID is provided.Type of Change
How Has This Been Tested?
Describe the testing steps performed.
PUT /api/flashcards/invalid-id-123/reviewwith a valid body and confirmed it returns HTTP400withInvalid flashcard ID format.DELETE /api/flashcards/invalid-id-123and confirmed it returns HTTP400withInvalid flashcard ID format.Screenshots (if applicable)
N/A (Backend API response status fix)
Checklist
Adds ObjectId validation for flashcard review and deletion endpoints. Invalid IDs now return HTTP 400 with
Invalid flashcard ID formatinstead of causing HTTP 500 errors.