Skip to content

fix: return 400 for invalid Mongo ObjectId route params - #260

Merged
rkorszun merged 2 commits into
developfrom
cursor/objectid-validation-pipe-e4af
Oct 12, 2026
Merged

rkorszun merged 2 commits into
developfrom
cursor/objectid-validation-pipe-e4af

Conversation

@rkorszun

Copy link
Copy Markdown
Collaborator

Problem

Route params that are not valid Mongo ObjectIds (for example notanobjectid) were passed through to Mongoose findById. 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

  • Add a reusable ParseObjectIdPipe backed by a strict 24-character hex check (stricter than Types.ObjectId.isValid, which also accepts 12-character strings).
  • Apply the pipe to every :id route param, plus responseId on form reprocess. Left alone: taskId (UUID), hookId (UUID), provider, and variant key.
  • Public form endpoints (GET/POST /api/public/forms/:id) now return 400 for invalid ids.
  • isValidFormId shares the same helper so form-access checks stay consistent.

Tests

  • Unit: isValidObjectId and ParseObjectIdPipe.
  • HTTP (no Mongo): GET /api/public/forms/notanobjectid → 400; nonexistent valid ObjectId → 404.
  • e2e: same cases on the public forms suite.

Notes

Draft PR into develop as requested. Please do not merge or mark ready until review.

Open in Web Open in Cursor 

cursoragent and others added 2 commits October 12, 2026 10:01
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
rkorszun marked this pull request as ready for review October 12, 2026 10:07
@rkorszun
rkorszun merged commit 071b145 into develop Oct 12, 2026
4 checks passed
@rkorszun
rkorszun deleted the cursor/objectid-validation-pipe-e4af branch October 12, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants