GLM-5.3 · Heavy
add-guest-management-functionality-to-existing-bookings-cal-com
cal.com · TypeScript · M · 100–299 lines · 6 files
The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.
- Gold bugs found
- 5 of 8
- Comments published
- 12
- Comments matching a bug
- 5
- Comments not matching
- 7
- Cost of this PR
- $2.159
Published comments (12)
EventManager uses caller's credentials instead of booking organizer's — The EventManager is constructed from `ctx.user` and `getUsersCredentials(ctx.user)` — the calling user's credentials — instead of the booking organizer's, even though the query already fetches `booking.user` with `credentials: true` (never used). When an attendee or team admin (both authorized by this handler's gate) adds guests, `updateAllCalendarEvents` finds no matching credential in `this.calendarCredentials` (EventManager.ts:846/872) and silently skips or soft-fails the update, so the organizer's calendar event never receives the new attendees.
Unhandled Prisma P2025 when booking.userId is null due to `|| 0` fallback — `prisma.user.findFirstOrThrow({ where: { id: booking.userId || 0 } })` throws an unhandled Prisma P2025 error when `booking.userId` is null (schema.prisma:554-555 defines `userId Int?`). The `|| 0` fallback converts null into a guaranteed not-found lookup, so any authorized caller on a user-less booking gets a raw INTERNAL_SERVER_ERROR (500) instead of a handled TRPC error.
isTeamAdmin && isTeamOwner restricts permission to owners only, excluding admins — The `isTeamAdminOrOwner` check combines `isTeamAdmin` and `isTeamOwner` with `&&`, but `isTeamAdmin` already returns true for both ADMIN and OWNER roles (packages/lib/server/queries/teams/index.ts:270), so the conjunction is satisfied only by owners. A team ADMIN who is neither the booking organizer nor an attendee is wrongly denied with FORBIDDEN when adding guests to a team booking, breaking the feature the variable name (`isTeamAdminOrOwner`) says it supports.
Case-sensitive email comparisons let blacklisted and duplicate guests bypass filters — The guest filter compares un-normalized guest emails against normalized values: `blacklistedGuestEmails` entries are `.toLowerCase()`d, but `blacklistedGuestEmails.includes(guest)` compares the raw guest string, so a blacklisted email submitted with any uppercase character (e.g. "Spam@X.com" vs blacklist "spam@x.com") bypasses the blacklist entirely. The sibling check `guest === attendee.email` is likewise case-sensitive, so a case-variant of an existing attendee's email passes the duplicate filter and is created as a second attendee record.
Unbounded guests array allows email-bombing and mass Attendee insertion — The `guests` array has no `.max()` bound, and the handler authorizes plain booking attendees (not just organizers) to call it. One mutation with thousands of emails inserts that many `Attendee` rows via `createMany` and fans out emails to the organizer plus every existing attendee plus every new guest (sendAddGuestsEmails, email-manager.ts:539-547), enabling email-bombing and unbounded DB growth by any booker.
Missing booking status check allows adding guests to pending/cancelled bookings — The permission gate checks user identity but never `booking.status`, so guests can be added to pending or cancelled bookings (the UI even renders the add_members action for past unconfirmed bookings via BookingListItem.tsx:553, and the API accepts any status directly). The new email templates hardcode ICS `status: "CONFIRMED"` (attendee-add-guests-email.ts:15, organizer-add-guests-email.ts:19), so attendees receive CONFIRMED calendar invites for events that are not accepted.
Team members never get add-guests email: caller builds event without team — The `if (calendarEvent.team?.members)` branch in `sendAddGuestsEmails` is unreachable: its only caller (`addGuestsHandler`) builds the `CalendarEvent` without a `team` property, and `formatCalEvent` only clones the event and strips `platformClientId`. Team members therefore never receive the add-guests notification email this branch is written to send, silently dropping the side effect for team bookings.
onSuccess fails to reset isInvalidEmail, leaving stale error banner — The mutation's `onSuccess` resets `multiEmailValue` and closes the dialog but never resets the `isInvalidEmail` flag (only the Cancel button does). After a failed validation is fixed and the add succeeds, reopening the dialog shows the stale `emails_must_be_unique_valid` error banner even though no invalid email is present.
Dead fallback: message is always truthy, so 'unable_to_add_guests' never shows — When `err.data` is missing the toast shows 'undefined: …' instead of the intended `unable_to_add_guests` message. Base the fallback on the actual message part (e.g. `err.message || t("unable_to_add_guests")`).
Case-sensitive duplicate guest check allows same-email attendees — The duplicate check `!booking.attendees.some((attendee) => guest === attendee.email)` compares emails case-sensitively, and attendee emails are stored as typed at booking time. Adding `john@x.com` to a booking that already has `John@x.com` creates a second `Attendee` row for the same person, producing duplicate invites and ICS attendees.
Pass uniqueGuests instead of raw guests to sendAddGuestsEmails — The handler passes the raw `guests` input to sendAddGuestsEmails, but email-manager's sendAddGuestsEmails assumes its `newGuests` parameter contains only the guests actually added (it uses newGuests.includes(attendee.email) to decide between the "You're scheduled" email and the "new guests added" email). The handler already computed `uniqueGuests` (filtered against existing attendees and the blacklist) for the DB write at lines 74–106; passing the unfiltered list means that when a user re-submits an email that is already an attendee (allowed by the client validation, which only checks uniqueness among entered emails), that existing attendee wrongly receives the full AttendeeScheduledEmail booking confirmation instead of the AttendeeAddGuestsEmail notification.
addGuests schema allows duplicate guest emails, causing duplicate rows or P2002 — The server schema omits the uniqueness refinement the dialog applies client-side (AddGuestsDialog refines z.array(z.string().email()) for uniqueness), and the handler's `uniqueGuests` filter (addGuests.handler.ts:74-78) only removes emails already on the booking or blacklisted — it never deduplicates within the input array. A direct mutation call with `guests: ["a@x.com","a@x.com"]` passes zod and reaches `createMany`, inserting duplicate Attendee rows for the same booking (or, if the DB enforces uniqueness on bookingId+email, throwing an unhandled P2002). **Also found in:** - `packages/trpc/server/routers/viewer/bookings/addGuests.handler.ts:74-106`