Skip to content

Commit ffe2bea

Browse files
committed
fix: security and quality improvements across tRPC routers
- fix(bookings): replace credentials: true with select to prevent credential.key exposure in booking middleware - fix(eventTypes): remove console.log statements that leaked private hashed link data to stdout - fix(schedule): replace console.log with structured logger.error in getScheduleByEventTypeSlug - refactor(eventTypes): replace Prisma include with select in getEventTypesFromGroup and duplicate handlers - fix(eventTypes): add missing scheduleId/groupId/memberId to hosts select in duplicate handler - fix(eventTypes): remove @ts-expect-error by typing reduce accumulator as Record<string, unknown>
1 parent 287cea3 commit ffe2bea

5 files changed

Lines changed: 36 additions & 11 deletions

File tree

packages/trpc/server/routers/viewer/availability/schedule/getScheduleByEventTypeSlug.handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logger from "@calcom/lib/logger";
12
import type { PrismaClient } from "@calcom/prisma";
23

34
import type { TrpcSessionUser } from "../../../../types";
@@ -57,7 +58,7 @@ export const getScheduleByEventSlugHandler = async ({ ctx, input }: GetOptions)
5758
},
5859
});
5960
} catch (e) {
60-
console.log(e);
61+
logger.error("Failed to retrieve schedule by event type slug", e);
6162
return {
6263
id: -1,
6364
name: "No schedules found",

packages/trpc/server/routers/viewer/bookings/util.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ export const bookingsProcedure = authedProcedure
3939
user: {
4040
include: {
4141
destinationCalendar: true,
42-
credentials: true,
42+
credentials: {
43+
select: {
44+
id: true,
45+
type: true,
46+
appId: true,
47+
},
48+
},
4349
profiles: {
4450
select: {
4551
organizationId: true,
@@ -114,7 +120,7 @@ export type BookingsProcedureContext = {
114120
user:
115121
| (User & {
116122
destinationCalendar: DestinationCalendar | null;
117-
credentials: Credential[];
123+
credentials: Pick<Credential, "id" | "type" | "appId">[];
118124
profiles: { organizationId: number }[];
119125
})
120126
| null;

packages/trpc/server/routers/viewer/eventTypes/getEventTypesFromGroup.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export const getEventTypesFromGroup = async ({
176176
accepted: true,
177177
role: "MEMBER",
178178
},
179-
include: {
179+
select: {
180180
team: {
181181
select: {
182182
isPrivate: true,

packages/trpc/server/routers/viewer/eventTypes/heavy/duplicate.handler.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,28 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
3838
id: true,
3939
},
4040
},
41-
hosts: true,
42-
team: true,
43-
webhooks: true,
41+
hosts: {
42+
select: {
43+
userId: true,
44+
isFixed: true,
45+
priority: true,
46+
weight: true,
47+
eventTypeId: true,
48+
scheduleId: true,
49+
groupId: true,
50+
memberId: true,
51+
},
52+
},
53+
team: {
54+
select: {
55+
id: true,
56+
},
57+
},
58+
webhooks: {
59+
select: {
60+
id: true,
61+
},
62+
},
4463
hashedLink: true,
4564
destinationCalendar: true,
4665
calVideoSettings: {

packages/trpc/server/routers/viewer/eventTypes/heavy/update.handler.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,11 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
608608
break;
609609
}
610610
}
611-
console.log("multiplePrivateLinks", multiplePrivateLinks);
611+
612612
// Handle multiple private links using the service
613613
const privateLinksRepo = HashedLinkRepository.create();
614614
const connectedLinks = await privateLinksRepo.findLinksByEventTypeId(input.id);
615-
console.log("connectedLinks", connectedLinks);
615+
616616
const connectedMultiplePrivateLinks = connectedLinks.map((link) => link.link);
617617

618618
const privateLinksService = new HashedLinkService();
@@ -724,9 +724,8 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
724724
});
725725
}
726726

727-
const updatedValues = Object.entries(data).reduce((acc, [key, value]) => {
727+
const updatedValues = Object.entries(data).reduce<Record<string, unknown>>((acc, [key, value]) => {
728728
if (value !== undefined) {
729-
// @ts-expect-error Element implicitly has any type
730729
acc[key] = value;
731730
}
732731
return acc;

0 commit comments

Comments
 (0)