Repository navigation
fix: return 400 for invalid Mongo ObjectId route params - #260
Merged
Merged
Conversation
Reject non-ObjectId :id values with ParseObjectIdPipe before Mongoose casts them, so public form and other :id routes return 400 instead of 500. A well-formed id that does not exist still returns 404. Co-authored-by: Rafal Korszun <rkorszun@users.noreply.github.com>
Co-authored-by: Rafal Korszun <rkorszun@users.noreply.github.com>
rkorszun
marked this pull request as ready for review
October 12, 2026 10:07
This was referenced Oct 12, 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.
Problem
Route params that are not valid Mongo
ObjectIds (for examplenotanobjectid) were passed through to MongoosefindById. That threw a cast error and the API responded with 500.A well-formed id that simply does not exist should still be 404.
Change
ParseObjectIdPipebacked by a strict 24-character hex check (stricter thanTypes.ObjectId.isValid, which also accepts 12-character strings).:idroute param, plusresponseIdon form reprocess. Left alone:taskId(UUID),hookId(UUID),provider, and variantkey.GET/POST /api/public/forms/:id) now return 400 for invalid ids.isValidFormIdshares the same helper so form-access checks stay consistent.Tests
isValidObjectIdandParseObjectIdPipe.GET /api/public/forms/notanobjectid→ 400; nonexistent valid ObjectId → 404.Notes
Draft PR into
developas requested. Please do not merge or mark ready until review.