SecureBananaLabs / SecureBananaLabs/bug-bounty
Error handler returns 500 for Zod validation failures instead of 400
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 297
- Forks
- 898
- PR merge metrics
- No merged PRs in 30d
Description
Parent Algora bounty: #743
Bug
errorHandler middleware returns 500 Unexpected server error for all unhandled errors, including ZodError thrown by schema.parse(). Controllers such as authController.register, authController.login, and jobController.postJob use schema.parse(req.body) without try/catch, so any Zod validation failure propagates to the error handler and returns 500 instead of 400 Bad Request.
Reproduction
- Send
POST /api/auth/registerwith body{ "email": "notanemail", "password": "short" }. - Response:
500 Unexpected server errorinstead of400with a validation message.
Expected behavior
errorHandler must detect ZodError instances and return 400 with the first error message from err.errors, matching the shared { success: false, message } shape.
Scope
Update apps/api/src/middleware/errorHandler.js only. Import ZodError from 'zod' and add a check before the generic 500 handler.
/attempt #743
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in apps/api/src/middleware/errorHandler.js and reproduce the POST /api/auth/register case described in the issue. Check that Zod validation failures are handled before the generic error path and that the response is 400 with the shared { success: false, message } shape.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100