SecureBananaLabs / SecureBananaLabs/bug-bounty

Error handler returns 500 for Zod validation failures instead of 400

Open Beginner friendly
#4,635 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Send POST /api/auth/register with body { "email": "notanemail", "password": "short" }.
  2. Response: 500 Unexpected server error instead of 400 with 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.