Skip to content

Bug: POST /tasks and POST /messages are registered twice with conflicting middleware — duplicate route registration #159

@anshul23102

Description

@anshul23102

Description

In both backend/routes/tasks.routes.js and backend/routes/chat.routes.js, mutation routes are registered twice - first with authenticateUser and again with only the validate* middleware. Express uses the first registered handler, making the second registration silently dead code. More critically, DELETE /tasks/:id is registered twice — once WITH authenticateUser and once WITHOUT:

// tasks.routes.js
router.post("/", authenticateUser, createTask);    // first registration (used)
router.delete("/:id", authenticateUser, deleteTask); // first registration (used)
// ...
router.post("/", validateTask, createTask);          // dead code
router.delete("/:id", deleteTask);                   // dead code (no auth!)

If the route registration order is ever changed by a future contributor, the DELETE /:id without authentication could become the active handler, allowing unauthenticated users to delete any task by ID.

To Reproduce

  1. Inspect the route file and verify the duplicate registrations.
  2. Swap the order of the two router.delete lines.
  3. Send DELETE /api/tasks/:id with no auth token.
  4. The task is deleted without authentication.

Expected Behavior

Each route should have exactly one registration that applies both middleware in the correct order:

router.get("/", authenticateUser, getTasks);
router.post("/", authenticateUser, validateTask, createTask);
router.patch("/:id", authenticateUser, validateTask, updateTaskStatus);
router.patch("/:id/edit", authenticateUser, validateTask, updateTask);
router.delete("/:id", authenticateUser, deleteTask);

Apply the same consolidation to chat.routes.js.

Actual Behavior

Duplicate route registrations exist. The second DELETE /:id registration has no authentication middleware and is one registration-order change away from being exploited.

Desktop

  • Backend: Node.js / Express
  • Files: backend/routes/tasks.routes.js, backend/routes/chat.routes.js

Additional context

Expected NSOC points: level2 (security - latent auth bypass risk from duplicate route registration)

Labels: bug, NSoC'26, level2

Checklist:

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions