Skip to content

TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.

fix: middlewares for sprint

Nikolai Gimand14398faaeb1
diff --git a/api/src/tv-modules/sprints/SprintsController.ts b/api/src/tv-modules/sprints/SprintsController.ts
index e26ea30..5d81f00 100644
--- a/api/src/tv-modules/sprints/SprintsController.ts
+++ b/api/src/tv-modules/sprints/SprintsController.ts
@@ -33,7 +33,9 @@ export default class SprintsController {
}
listForGoal = async (req: Request, res: Response) => {
- const data = SprintArkTypeListQuery({ ...req.params, ...req.query });
+ // Route params win over query: the goalId authorized by the middleware must
+ // be the one operated on (a query-supplied goalId must not override it).
+ const data = SprintArkTypeListQuery({ ...req.query, ...req.params });
if (data instanceof type.errors) return res.status(400).send(data.summary);
const statuses = data.status
@@ -56,7 +58,7 @@ export default class SprintsController {
};
update = async (req: Request, res: Response) => {
- const data = SprintArkTypeUpdate({ sprintId: Number(req.params.sprintId), ...req.body });
+ const data = SprintArkTypeUpdate({ ...req.body, sprintId: Number(req.params.sprintId) });
if (data instanceof type.errors) return res.status(400).send(data.summary);
return this.sendResult(res, await req.appUser.sprintsManager.updateSprint(data));
};
@@ -74,7 +76,7 @@ export default class SprintsController {
};
close = async (req: Request, res: Response) => {
- const data = SprintArkTypeClose({ sprintId: Number(req.params.sprintId), ...req.body });
+ const data = SprintArkTypeClose({ ...req.body, sprintId: Number(req.params.sprintId) });
if (data instanceof type.errors) return res.status(400).send(data.summary);
return this.sendResult(res, await req.appUser.sprintsManager.closeSprint(data));
};
@@ -98,7 +100,7 @@ export default class SprintsController {
};
saveRetro = async (req: Request, res: Response) => {
- const data = SprintArkTypeSaveRetro({ sprintId: Number(req.params.sprintId), ...req.body });
+ const data = SprintArkTypeSaveRetro({ ...req.body, sprintId: Number(req.params.sprintId) });
if (data instanceof type.errors) return res.status(400).send(data.summary);
return this.sendResult(res, await req.appUser.sprintsManager.saveRetro(data));
};
@@ -116,7 +118,7 @@ export default class SprintsController {
};
planning = async (req: Request, res: Response) => {
- const data = SprintArkTypePlanningQuery({ ...req.params, ...req.query });
+ const data = SprintArkTypePlanningQuery({ ...req.query, ...req.params });
if (data instanceof type.errors) return res.status(400).send(data.summary);
return res.tvJson(
await req.appUser.sprintsManager
@@ -131,7 +133,7 @@ export default class SprintsController {
};
velocity = async (req: Request, res: Response) => {
- const data = SprintArkTypeVelocityQuery({ ...req.params, ...req.query });
+ const data = SprintArkTypeVelocityQuery({ ...req.query, ...req.params });
if (data instanceof type.errors) return res.status(400).send(data.summary);
return res.tvJson(
await req.appUser.sprintsManager.getVelocity({ goalId: data.goalId, lastN: data.lastN ?? 6 }).catch(logError)
@@ -145,7 +147,7 @@ export default class SprintsController {
};
setCadence = async (req: Request, res: Response) => {
- const data = SprintArkTypeSetCadence({ goalId: Number(req.params.goalId), ...req.body });
+ const data = SprintArkTypeSetCadence({ ...req.body, goalId: Number(req.params.goalId) });
if (data instanceof type.errors) return res.status(400).send(data.summary);
return this.sendResult(res, await req.appUser.sprintsManager.setCadence(data));
};
diff --git a/api/src/tv-modules/sprints/SprintsRoutes.ts b/api/src/tv-modules/sprints/SprintsRoutes.ts
index dd0e92d..2ae994a 100644
--- a/api/src/tv-modules/sprints/SprintsRoutes.ts
+++ b/api/src/tv-modules/sprints/SprintsRoutes.ts
@@ -1,11 +1,11 @@
import { Router } from 'express';
import type { Routable } from '../../types/routable.type';
+import { GoalPermissions } from '../../types/auth.types';
import { IsLoggedIn } from '../auth/middlewares/is-logged-in';
import SprintsController from './SprintsController';
import { canAssignSprintTasks } from './middlewares/can-assign-sprint-tasks';
-import { canManageSprints } from './middlewares/can-manage-sprints';
-import { canViewSprintAnalytics } from './middlewares/can-view-sprint-analytics';
-import { canViewSprints } from './middlewares/can-view-sprints';
+import { requireSprintPermission } from './middlewares/require-sprint-permission';
+import { goalIdFromBody, goalIdFromParam, goalIdFromSprint } from './middlewares/goal-id-resolvers';
export default class SprintsRoutes implements Routable {
private readonly router: ReturnType<typeof Router>;
@@ -22,35 +22,35 @@ export default class SprintsRoutes implements Routable {
}
initRoutes() {
- // Create
- this.router.post('', [IsLoggedIn, canManageSprints], this.controller.create);
+ // Create — goal comes from the request body (the creation target).
+ this.router.post('', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_MANAGE, goalIdFromBody)], this.controller.create);
// Analytics
- this.router.get('/sprint/:sprintId/burndown', [IsLoggedIn, canViewSprintAnalytics], this.controller.burndown);
- this.router.get('/goal/:goalId/velocity', [IsLoggedIn, canViewSprintAnalytics], this.controller.velocity);
+ this.router.get('/sprint/:sprintId/burndown', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_VIEW_ANALYTICS, goalIdFromSprint)], this.controller.burndown);
+ this.router.get('/goal/:goalId/velocity', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_VIEW_ANALYTICS, goalIdFromParam)], this.controller.velocity);
- // Cadence: per-project auto-generation config (Linear-style)
- this.router.get('/goal/:goalId/cadence', [IsLoggedIn, canViewSprints], this.controller.getCadence);
- this.router.put('/goal/:goalId/cadence', [IsLoggedIn, canManageSprints], this.controller.setCadence);
+ // Cadence: per-project auto-generation config (Linear-style) — goal from the URL param.
+ this.router.get('/goal/:goalId/cadence', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_VIEW, goalIdFromParam)], this.controller.getCadence);
+ this.router.put('/goal/:goalId/cadence', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_MANAGE, goalIdFromParam)], this.controller.setCadence);
// Cursor-paginated planning task lists (?scope=backlog|sprint&cursor=&limit=)
- this.router.get('/sprint/:sprintId/planning', [IsLoggedIn, canViewSprints], this.controller.planning);
-
- // Single sprint detail + lifecycle
- this.router.get('/sprint/:sprintId', [IsLoggedIn, canViewSprints], this.controller.getOne);
- this.router.patch('/sprint/:sprintId', [IsLoggedIn, canManageSprints], this.controller.update);
- this.router.post('/sprint/:sprintId/activate', [IsLoggedIn, canManageSprints], this.controller.activate);
- this.router.post('/sprint/:sprintId/review', [IsLoggedIn, canManageSprints], this.controller.review);
- this.router.post('/sprint/:sprintId/close', [IsLoggedIn, canManageSprints], this.controller.close);
- this.router.post('/sprint/:sprintId/pause', [IsLoggedIn, canManageSprints], this.controller.pause);
- this.router.post('/sprint/:sprintId/resume', [IsLoggedIn, canManageSprints], this.controller.resume);
- this.router.delete('/sprint/:sprintId', [IsLoggedIn, canManageSprints], this.controller.remove);
- this.router.put('/sprint/:sprintId/retro', [IsLoggedIn, canManageSprints], this.controller.saveRetro);
-
- // Assign a task to / out of a sprint (business boundary lives here, not in tasks)
+ this.router.get('/sprint/:sprintId/planning', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_VIEW, goalIdFromSprint)], this.controller.planning);
+
+ // Single sprint detail + lifecycle — goal is always derived from the sprint.
+ this.router.get('/sprint/:sprintId', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_VIEW, goalIdFromSprint)], this.controller.getOne);
+ this.router.patch('/sprint/:sprintId', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_MANAGE, goalIdFromSprint)], this.controller.update);
+ this.router.post('/sprint/:sprintId/activate', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_MANAGE, goalIdFromSprint)], this.controller.activate);
+ this.router.post('/sprint/:sprintId/review', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_MANAGE, goalIdFromSprint)], this.controller.review);
+ this.router.post('/sprint/:sprintId/close', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_MANAGE, goalIdFromSprint)], this.controller.close);
+ this.router.post('/sprint/:sprintId/pause', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_MANAGE, goalIdFromSprint)], this.controller.pause);
+ this.router.post('/sprint/:sprintId/resume', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_MANAGE, goalIdFromSprint)], this.controller.resume);
+ this.router.delete('/sprint/:sprintId', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_MANAGE, goalIdFromSprint)], this.controller.remove);
+ this.router.put('/sprint/:sprintId/retro', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_MANAGE, goalIdFromSprint)], this.controller.saveRetro);
+
+ // Assign a task to / out of a sprint — authorized against the task's goal.
this.router.patch('/task/:taskId/sprint', [IsLoggedIn, canAssignSprintTasks], this.controller.setTaskSprint);
- // List sprints of a project (supports ?status=active,planned)
- this.router.get('/:goalId', [IsLoggedIn, canViewSprints], this.controller.listForGoal);
+ // List sprints of a project (supports ?status=active,planned) — goal from the URL param.
+ this.router.get('/:goalId', [IsLoggedIn, requireSprintPermission(GoalPermissions.SPRINT_CAN_VIEW, goalIdFromParam)], this.controller.listForGoal);
}
}
diff --git a/api/src/tv-modules/sprints/middlewares/can-manage-sprints.ts b/api/src/tv-modules/sprints/middlewares/can-manage-sprints.ts
deleted file mode 100644
index b9915e9..0000000
--- a/api/src/tv-modules/sprints/middlewares/can-manage-sprints.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import type { NextFunction, Request, Response } from 'express';
-import { GoalPermissionsFetcher } from '../../../core/GoalPermissionsFetcher';
-import { $logger } from '../../../modules/logget';
-import { GoalPermissions } from '../../../types/auth.types';
-import { logError } from '../../../utils/api';
-import { resolveGoalId } from './resolve-goal-id';
-
-export const canManageSprints = async (req: Request, res: Response, next: NextFunction) => {
- const goalId = await resolveGoalId(req);
- if (!goalId) return res.status(400).end();
-
- const permissions = await req.appUser.permissionsFetcher
- .getPermissionsForType(goalId, GoalPermissionsFetcher.PERMISSION_TYPE_FOR_GOAL)
- .catch(logError);
-
- if (!permissions) {
- $logger.error('Can not get permissions for canManageSprints middleware');
- return res.status(500).end();
- }
-
- if (permissions.hasPermissions(GoalPermissions.SPRINT_CAN_MANAGE)) return next();
- return res.status(403).end();
-};
diff --git a/api/src/tv-modules/sprints/middlewares/can-view-sprint-analytics.ts b/api/src/tv-modules/sprints/middlewares/can-view-sprint-analytics.ts
deleted file mode 100644
index 55eeae5..0000000
--- a/api/src/tv-modules/sprints/middlewares/can-view-sprint-analytics.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import type { NextFunction, Request, Response } from 'express';
-import { GoalPermissionsFetcher } from '../../../core/GoalPermissionsFetcher';
-import { $logger } from '../../../modules/logget';
-import { GoalPermissions } from '../../../types/auth.types';
-import { logError } from '../../../utils/api';
-import { resolveGoalId } from './resolve-goal-id';
-
-export const canViewSprintAnalytics = async (req: Request, res: Response, next: NextFunction) => {
- const goalId = await resolveGoalId(req);
- if (!goalId) return res.status(400).end();
-
- const permissions = await req.appUser.permissionsFetcher
- .getPermissionsForType(goalId, GoalPermissionsFetcher.PERMISSION_TYPE_FOR_GOAL)
- .catch(logError);
-
- if (!permissions) {
- $logger.error('Can not get permissions for canViewSprintAnalytics middleware');
- return res.status(500).end();
- }
-
- if (permissions.hasPermissions(GoalPermissions.SPRINT_CAN_VIEW_ANALYTICS)) return next();
- return res.status(403).end();
-};
diff --git a/api/src/tv-modules/sprints/middlewares/can-view-sprints.ts b/api/src/tv-modules/sprints/middlewares/can-view-sprints.ts
deleted file mode 100644
index 6e3b884..0000000
--- a/api/src/tv-modules/sprints/middlewares/can-view-sprints.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import type { NextFunction, Request, Response } from 'express';
-import { GoalPermissionsFetcher } from '../../../core/GoalPermissionsFetcher';
-import { $logger } from '../../../modules/logget';
-import { GoalPermissions } from '../../../types/auth.types';
-import { logError } from '../../../utils/api';
-import { resolveGoalId } from './resolve-goal-id';
-
-export const canViewSprints = async (req: Request, res: Response, next: NextFunction) => {
- const goalId = await resolveGoalId(req);
- if (!goalId) return res.status(400).end();
-
- const permissions = await req.appUser.permissionsFetcher
- .getPermissionsForType(goalId, GoalPermissionsFetcher.PERMISSION_TYPE_FOR_GOAL)
- .catch(logError);
-
- if (!permissions) {
- $logger.error('Can not get permissions for canViewSprints middleware');
- return res.status(500).end();
- }
-
- if (permissions.hasPermissions(GoalPermissions.SPRINT_CAN_VIEW)) return next();
- return res.status(403).end();
-};
diff --git a/api/src/tv-modules/sprints/middlewares/goal-id-resolvers.ts b/api/src/tv-modules/sprints/middlewares/goal-id-resolvers.ts
new file mode 100644
index 0000000..266ae45
--- /dev/null
+++ b/api/src/tv-modules/sprints/middlewares/goal-id-resolvers.ts
@@ -0,0 +1,17 @@
+import type { Request } from 'express';
+import { SprintsRepository } from '../SprintsRepository';
+
+export async function goalIdFromSprint(req: Request): Promise<number | null> {
+ const sprintId = req.params.sprintId;
+ if (sprintId == null) return null;
+ const sprint = await new SprintsRepository().getById(Number(sprintId));
+ return sprint?.goalId ?? null;
+}
+
+export function goalIdFromParam(req: Request): number | null {
+ return req.params.goalId != null ? Number(req.params.goalId) : null;
+}
+
+export function goalIdFromBody(req: Request): number | null {
+ return req.body?.goalId != null ? Number(req.body.goalId) : null;
+}
diff --git a/api/src/tv-modules/sprints/middlewares/require-sprint-permission.ts b/api/src/tv-modules/sprints/middlewares/require-sprint-permission.ts
new file mode 100644
index 0000000..a712d7d
--- /dev/null
+++ b/api/src/tv-modules/sprints/middlewares/require-sprint-permission.ts
@@ -0,0 +1,26 @@
+import type { NextFunction, Request, Response } from 'express';
+import { GoalPermissionsFetcher } from '../../../core/GoalPermissionsFetcher';
+import { $logger } from '../../../modules/logget';
+import type { GoalPermissionType } from '../../../types/auth.types';
+import { logError } from '../../../utils/api';
+
+type GoalIdResolver = (req: Request) => Promise<number | null> | number | null;
+
+export function requireSprintPermission(permission: GoalPermissionType, resolveGoalId: GoalIdResolver) {
+ return async (req: Request, res: Response, next: NextFunction) => {
+ const goalId = await resolveGoalId(req);
+ if (!goalId) return res.status(400).end();
+
+ const permissions = await req.appUser.permissionsFetcher
+ .getPermissionsForType(goalId, GoalPermissionsFetcher.PERMISSION_TYPE_FOR_GOAL)
+ .catch(logError);
+
+ if (!permissions) {
+ $logger.error('Can not resolve sprint permissions');
+ return res.status(500).end();
+ }
+
+ if (permissions.hasPermissions(permission)) return next();
+ return res.status(403).end();
+ };
+}
diff --git a/api/src/tv-modules/sprints/middlewares/resolve-goal-id.ts b/api/src/tv-modules/sprints/middlewares/resolve-goal-id.ts
deleted file mode 100644
index 40e446f..0000000
--- a/api/src/tv-modules/sprints/middlewares/resolve-goal-id.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import type { Request } from 'express';
-import { SprintsRepository } from '../SprintsRepository';
-
-/**
- * Resolves the goalId a sprint request operates on, from (in order):
- * a goalId param/body, or a sprintId param/body (looked up to its goal).
- */
-export async function resolveGoalId(req: Request): Promise<number | null> {
- const fromGoal = req.params.goalId ?? req.body?.goalId;
- if (fromGoal) return Number(fromGoal);
-
- const sprintId = req.params.sprintId ?? req.body?.sprintId;
- if (sprintId) {
- const sprint = await new SprintsRepository().getById(Number(sprintId));
- return sprint?.goalId ?? null;
- }
- return null;
-}
diff --git a/docs/2.features/7.webhooks.md b/docs/2.features/7.webhooks.md
index 361eccc..1e7bc2e 100644
--- a/docs/2.features/7.webhooks.md
+++ b/docs/2.features/7.webhooks.md
@@ -27,7 +27,7 @@ Webhooks let you receive HTTP POST requests when events happen in your projects.
| `sprint.completed` | A sprint is closed and marked completed |
| `sprint.paused` | An active sprint is paused |
| `sprint.resumed` | A paused sprint is resumed |
-| `sprint.deleted` | A draft or planned sprint is deleted |
+| `sprint.deleted` | A sprint is deleted (any status, including completed) |
| `task.assignedToSprint` | A task is added to, moved between, or removed from a sprint |
## Setup
diff --git a/taskview-packages/taskview-api/src/api/__tests__/sprints-security.test.ts b/taskview-packages/taskview-api/src/api/__tests__/sprints-security.test.ts
new file mode 100644
index 0000000..b8903e4
--- /dev/null
+++ b/taskview-packages/taskview-api/src/api/__tests__/sprints-security.test.ts
@@ -0,0 +1,303 @@
+import { TvApi } from '@/tv'
+import {
+ describe,
+ it,
+ expect,
+ beforeAll,
+ afterAll,
+} from 'vitest'
+import axios, { type AxiosInstance } from 'axios'
+import { initApi, API_URL, DEFAULT_USER_2, DEFAULT_PASSWORD } from './init-api'
+import { ymd } from './test-helpers'
+
+/**
+ * Cross-tenant (IDOR) tests for the sprints module.
+ *
+ * `owner` (user1) owns a project the `attacker` (user2) is NOT a member of.
+ * The attacker only manages their OWN project. Each test tries to read or
+ * mutate the victim's sprint data through an injection vector (body.goalId,
+ * body.sprintId, query goalId override) and asserts it is refused / has no
+ * effect. These assertions describe the SECURE behaviour — they fail against a
+ * server that still trusts a client-supplied goalId, and pass once the
+ * goal-id-resolver + controller param-precedence fixes are deployed.
+ */
+describe('Sprints — cross-tenant access (IDOR)', () => {
+ let owner: TvApi
+ let attacker: TvApi
+ let attackerRaw: AxiosInstance
+
+ let victimGoalId: number
+ let victimSprintId: number
+ let victimDeletableSprintId: number
+ let victimTaskId: number
+ let attackerGoalId: number
+ let attackerSprintId: number
+ let attackerTaskId: number
+
+ const VICTIM_SPRINT_NAME = 'Victim sprint'
+
+ beforeAll(async () => {
+ const { $tvApi, $tvApiForSecondUser } = await initApi()
+ owner = $tvApi
+ attacker = $tvApiForSecondUser
+
+ // Raw axios as the attacker — lets us send crafted payloads the typed client
+ // would never produce. validateStatus:true so we can assert on status codes.
+ const auth = await axios.post(`${API_URL}/module/auth/login`, {
+ login: DEFAULT_USER_2,
+ password: DEFAULT_PASSWORD,
+ })
+ attackerRaw = axios.create({
+ baseURL: API_URL,
+ headers: { Authorization: `Bearer ${auth.data.access}` },
+ validateStatus: () => true,
+ })
+
+ // Victim project + sprint (attacker is not a member).
+ const vGoal = await owner.goals.createGoal({ name: `Victim project-${Date.now()}` })
+ if (!vGoal) throw new Error('Failed to create victim goal')
+ victimGoalId = vGoal.id!
+ const vSprint = await owner.sprints.create({
+ goalId: victimGoalId, name: VICTIM_SPRINT_NAME, startDate: ymd(7), endDate: ymd(21),
+ })
+ if (!vSprint) throw new Error('Failed to create victim sprint')
+ victimSprintId = vSprint.id
+
+ // A task inside the victim sprint — used to detect planning-list leaks.
+ const vTask = await owner.tasks.createTask({ goalId: victimGoalId, description: `Victim task-${Date.now()}` })
+ if (!vTask) throw new Error('Failed to create victim task')
+ victimTaskId = vTask.id
+ await owner.sprints.setTaskSprint({ taskId: victimTaskId, sprintId: victimSprintId })
+
+ // A separate throwaway victim sprint for the destructive delete test, so a
+ // successful exploit there can't wipe the shared victim other tests rely on.
+ const vDeletable = await owner.sprints.create({
+ goalId: victimGoalId, name: 'Victim deletable', startDate: ymd(7), endDate: ymd(21),
+ })
+ if (!vDeletable) throw new Error('Failed to create deletable victim sprint')
+ victimDeletableSprintId = vDeletable.id
+
+ // Attacker's own project + sprint (attacker manages it).
+ const aGoal = await attacker.goals.createGoal({ name: `Attacker project-${Date.now()}` })
+ if (!aGoal) throw new Error('Failed to create attacker goal')
+ attackerGoalId = aGoal.id!
+ const aSprint = await attacker.sprints.create({
+ goalId: attackerGoalId, name: 'Attacker sprint', startDate: ymd(7), endDate: ymd(21),
+ })
+ if (!aSprint) throw new Error('Failed to create attacker sprint')
+ attackerSprintId = aSprint.id
+
+ // A task the attacker owns — used to probe the setTaskSprint goal boundary.
+ const aTask = await attacker.tasks.createTask({ goalId: attackerGoalId, description: `Attacker task-${Date.now()}` })
+ if (!aTask) throw new Error('Failed to create attacker task')
+ attackerTaskId = aTask.id
+ })
+
+ afterAll(async () => {
+ await owner.goals.deleteGoal(victimGoalId).catch(() => {})
+ await attacker.goals.deleteGoal(attackerGoalId).catch(() => {})
+ })
+
+ it('denies reading another project\'s sprint directly', async () => {
+ const res = await attackerRaw.get(`/module/sprints/sprint/${victimSprintId}`)
+ expect(res.status).toBe(403)
+ })
+
+ it('denies updating another project\'s sprint via injected body.goalId', async () => {
+ const res = await attackerRaw.patch(`/module/sprints/sprint/${victimSprintId}`, {
+ goalId: attackerGoalId, // attacker's own goal — a vulnerable server authorizes against this
+ name: 'HACKED',
+ })
+ expect(res.status).toBe(403)
+
+ const victim = await owner.sprints.getById(victimSprintId)
+ expect(victim?.name).toBe(VICTIM_SPRINT_NAME)
+ })
+
+ it('denies deleting another project\'s sprint via injected body.goalId', async () => {
+ const res = await attackerRaw.delete(`/module/sprints/sprint/${victimDeletableSprintId}`, {
+ data: { goalId: attackerGoalId },
+ })
+ expect(res.status).toBe(403)
+
+ const victim = await owner.sprints.getById(victimDeletableSprintId)
+ expect(victim).not.toBeNull()
+ })
+
+ it('denies activating another project\'s sprint via injected body.goalId', async () => {
+ const res = await attackerRaw.post(`/module/sprints/sprint/${victimSprintId}/activate`, {
+ goalId: attackerGoalId,
+ })
+ expect(res.status).toBe(403)
+
+ const victim = await owner.sprints.getById(victimSprintId)
+ expect(victim?.status).toBe('planned')
+ })
+
+ it('does not let body.sprintId redirect an update onto another project\'s sprint', async () => {
+ // Attacker legitimately updates their OWN sprint, but injects the victim id.
+ await attackerRaw.patch(`/module/sprints/sprint/${attackerSprintId}`, {
+ sprintId: victimSprintId, // a vulnerable controller lets the body override the URL id
+ name: 'REDIRECTED',
+ })
+
+ const victim = await owner.sprints.getById(victimSprintId)
+ expect(victim?.name).toBe(VICTIM_SPRINT_NAME)
+ })
+
+ it('does not leak another project\'s sprints via a query goalId override', async () => {
+ const res = await attackerRaw.get(`/module/sprints/${attackerGoalId}`, {
+ params: { goalId: victimGoalId }, // try to redirect the listing to the victim project
+ })
+ expect(res.status).toBe(200)
+
+ const sprints = (res.data?.response ?? []) as Array<{ id: number }>
+ const ids = sprints.map((s) => s.id)
+ expect(ids).not.toContain(victimSprintId)
+ expect(ids).toContain(attackerSprintId)
+ })
+
+ it('does not leak another project\'s planning tasks via a query sprintId override', async () => {
+ const res = await attackerRaw.get(`/module/sprints/sprint/${attackerSprintId}/planning`, {
+ params: { sprintId: victimSprintId, scope: 'sprint' }, // try to redirect to the victim sprint
+ })
+ expect(res.status).toBe(200)
+
+ // Must be scoped to the attacker's own (empty) sprint — never expose the victim's task.
+ const tasks = (res.data?.response?.tasks ?? []) as Array<{ id: number }>
+ expect(tasks.map((t) => t.id)).not.toContain(victimTaskId)
+ })
+
+ it('does not let setCadence write to another project via body.goalId', async () => {
+ // Attacker legitimately configures cadence on their OWN goal but injects the
+ // victim goal in the body. The URL param must win: cadence lands on the
+ // attacker's goal, the victim's stays untouched.
+ const res = await attackerRaw.put(`/module/sprints/goal/${attackerGoalId}/cadence`, {
+ goalId: victimGoalId,
+ enabled: true,
+ lengthDays: 7,
+ startDate: ymd(0),
+ })
+ expect(res.status).toBe(200)
+
+ const victimCadence = await owner.sprints.getCadence(victimGoalId)
+ expect(victimCadence).toBeNull()
+
+ const attackerCadence = await attacker.sprints.getCadence(attackerGoalId)
+ expect(attackerCadence?.enabled).toBe(true)
+ })
+
+ it('denies closing another project\'s sprint via injected body.goalId', async () => {
+ const res = await attackerRaw.post(`/module/sprints/sprint/${victimSprintId}/close`, {
+ goalId: attackerGoalId,
+ outcomes: [],
+ goalAchieved: false,
+ })
+ expect(res.status).toBe(403)
+
+ const victim = await owner.sprints.getById(victimSprintId)
+ expect(victim?.status).toBe('planned')
+ })
+
+ it('denies overwriting another project\'s sprint retro via injected body.goalId', async () => {
+ const res = await attackerRaw.put(`/module/sprints/sprint/${victimSprintId}/retro`, {
+ goalId: attackerGoalId,
+ wentWell: 'HACKED',
+ })
+ expect(res.status).toBe(403)
+
+ const victim = await owner.sprints.getById(victimSprintId)
+ expect(victim?.retro?.wentWell ?? null).toBeNull()
+ })
+
+ it('denies review/pause/resume on another project\'s sprint', async () => {
+ for (const action of ['review', 'pause', 'resume']) {
+ const res = await attackerRaw.post(`/module/sprints/sprint/${victimSprintId}/${action}`, {
+ goalId: attackerGoalId,
+ })
+ expect(res.status).toBe(403)
+ }
+ const victim = await owner.sprints.getById(victimSprintId)
+ expect(victim?.status).toBe('planned')
+ })
+
+ it('denies reading another project\'s burndown, velocity and cadence', async () => {
+ const burndown = await attackerRaw.get(`/module/sprints/sprint/${victimSprintId}/burndown`)
+ expect(burndown.status).toBe(403)
+
+ const velocity = await attackerRaw.get(`/module/sprints/goal/${victimGoalId}/velocity`)
+ expect(velocity.status).toBe(403)
+
+ const cadence = await attackerRaw.get(`/module/sprints/goal/${victimGoalId}/cadence`)
+ expect(cadence.status).toBe(403)
+ })
+
+ describe('setTaskSprint goal boundary', () => {
+ it('denies pulling another project\'s task into the attacker\'s sprint', async () => {
+ const res = await attackerRaw.patch(`/module/sprints/task/${victimTaskId}/sprint`, {
+ sprintId: attackerSprintId,
+ })
+ expect(res.status).toBe(403)
+
+ // The victim task stays in the victim sprint.
+ const page = await owner.sprints.getPlanningTasks({ sprintId: victimSprintId, scope: 'sprint' })
+ expect(page?.tasks.map((t) => t.id)).toContain(victimTaskId)
+ })
+
+ it('denies pushing the attacker\'s task into another project\'s sprint (manager goal-match)', async () => {
+ // canAssignSprintTasks authorizes on the task's (attacker's) goal, so the
+ // middleware passes — only the manager's task.goalId === sprint.goalId check
+ // can stop this. It must reject.
+ const res = await attackerRaw.patch(`/module/sprints/task/${attackerTaskId}/sprint`, {
+ sprintId: victimSprintId,
+ })
+ expect(res.status).toBe(403)
+
+ // The attacker's task must NOT appear in the victim sprint.
+ const page = await owner.sprints.getPlanningTasks({ sprintId: victimSprintId, scope: 'sprint' })
+ expect(page?.tasks.map((t) => t.id)).not.toContain(attackerTaskId)
+ })
+ })
+
+ describe('positive control — the owner is not over-blocked', () => {
+ // Proves the fixes deny attackers without breaking legitimate access: if a
+ // future over-broad fix 403'd everyone, the IDOR tests above would still pass
+ // but these would fail.
+ let scratchSprintId: number
+
+ beforeAll(async () => {
+ const s = await attacker.sprints.create({
+ goalId: attackerGoalId, name: 'Owner scratch', startDate: ymd(7), endDate: ymd(21),
+ })
+ if (!s) throw new Error('Failed to create scratch sprint')
+ scratchSprintId = s.id
+ })
+
+ it('can read and update its own sprint', async () => {
+ const fetched = await attacker.sprints.getById(scratchSprintId)
+ expect(fetched?.id).toBe(scratchSprintId)
+
+ const updated = await attacker.sprints.update({ sprintId: scratchSprintId, name: 'Renamed by owner' })
+ expect(updated?.name).toBe('Renamed by owner')
+ })
+
+ it('can run its own sprint through the lifecycle', async () => {
+ const activated = await attacker.sprints.activate(scratchSprintId)
+ expect(activated?.status).toBe('active')
+
+ const paused = await attacker.sprints.pause(scratchSprintId)
+ expect(paused?.pausedAt).toBeTruthy()
+
+ const resumed = await attacker.sprints.resume(scratchSprintId)
+ expect(resumed?.pausedAt).toBeNull()
+ })
+
+ it('can read its own analytics', async () => {
+ const burndown = await attacker.sprints.getBurndown(scratchSprintId)
+ expect(burndown).toBeDefined()
+
+ const velocity = await attacker.sprints.getVelocity({ goalId: attackerGoalId })
+ expect(Array.isArray(velocity)).toBe(true)
+ })
+ })
+})