Task Update Authorization#
taskUpdate enforces owner-only access: every call to PUT /tasks/update is silently scoped to the authenticated user's tasks. If the caller is not the task owner, the update is a no-op and an error is returned โ no data leaks and no modifications occur.
How It Works#
The access control spans two layers:
-
Controller โ
updateTaskoverwrites any client-supplieduserIdwithreq.user.id(the ID extracted from the JWT by thesecuremiddleware), preventing callers from spoofing ownership. -
Module โ
taskUpdatepasses bothidanduserIdin the Sequelizewhereclause:where: { id: taskParameters.id, userId: taskParameters.userId }Because
Model.updateresolves to[affectedCount](always a truthy array), a mismatcheduserIdsilently updates 0 rows. The explicit affectedCount check catches this case and returnsError('task_updated_failed').
This design is verified by the integration test "should not update or leak a task the caller does not own", which confirms that a second authenticated user cannot modify a task owned by a different user.
The Side-Effect Problem#
The userId guard runs before all downstream logic, so any call to taskUpdate that does not include the task owner's userId will fail โ even for legitimate contributor actions:
| Contributor Action | Triggered By |
|---|---|
| Submit a task offer | taskParameters.Offer branch |
| Confirm an assignment | taskParameters.assigned branch |
| Add/update a member | taskParameters.Members branch |
All three branches are reached only after the Task.update + affectedCount check passes . A contributor (non-owner) who calls PUT /tasks/update with an Offer, Members, or assigned payload will hit the gate and receive an error before any offer, assignment, or member record is created.
The task assignment tests in taskAssignment.test.ts use xdescribe/xit (disabled), indicating this flow is not currently passing โ consistent with the authorization gate blocking it .
Where to Look#
| File | Purpose |
|---|---|
src/modules/tasks/taskUpdate.ts | Core authorization gate and all downstream branching logic |
src/app/controllers/task.ts | Overwrites userId with req.user.id before calling taskUpdate |
test/api/task/taskCrud.test.ts | Active test covering the unauthorized-update case |
test/api/task/taskAssignment.test.ts | Disabled tests for offer/assignment flows that are broken by the gate |
Key Constraint#
If you need a non-owner to trigger downstream task actions (offers, assignments, member updates), those operations must be moved outside the taskUpdate path or the gate must be conditioned on the specific action type. The current implementation has no bypass for contributor actions โ the owner-only check is unconditional.