Skip to content

Commit 5de8a67

Browse files
carhartlewisclaude
andcommitted
fix(controls): dedupe policyIds/taskIds before validating length
validatePolicyIds / validateTaskIds compared findMany row count to the raw input length. Duplicate ids in the request (e.g. [p1, p1, p2]) made the input longer than the set of rows returned, so a legitimate request with repeated ids was rejected as invalid. Dedupe via Set before the findMany lookup and length check. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d296e2a commit 5de8a67

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

apps/api/src/controls/controls.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,12 @@ export class ControlsService {
299299
organizationId: string,
300300
): Promise<string[]> {
301301
if (!policyIds || policyIds.length === 0) return [];
302+
const uniqueIds = Array.from(new Set(policyIds));
302303
const policies = await db.policy.findMany({
303-
where: { id: { in: policyIds }, organizationId },
304+
where: { id: { in: uniqueIds }, organizationId },
304305
select: { id: true },
305306
});
306-
if (policies.length !== policyIds.length) {
307+
if (policies.length !== uniqueIds.length) {
307308
throw new BadRequestException('One or more policies are invalid');
308309
}
309310
return policies.map((p) => p.id);
@@ -314,11 +315,12 @@ export class ControlsService {
314315
organizationId: string,
315316
): Promise<string[]> {
316317
if (!taskIds || taskIds.length === 0) return [];
318+
const uniqueIds = Array.from(new Set(taskIds));
317319
const tasks = await db.task.findMany({
318-
where: { id: { in: taskIds }, organizationId },
320+
where: { id: { in: uniqueIds }, organizationId },
319321
select: { id: true },
320322
});
321-
if (tasks.length !== taskIds.length) {
323+
if (tasks.length !== uniqueIds.length) {
322324
throw new BadRequestException('One or more tasks are invalid');
323325
}
324326
return tasks.map((t) => t.id);

0 commit comments

Comments
 (0)