Amazon Ergo 1.0 · 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 Opus 5.5.

Gold bugs found
10 of 18
Comments published
15
Comments matching a bug
10
Comments not matching
5
Cost of this PR
$2.674

Published comments (15)

highbugpackages/trpc/server/routers/viewer/bookings/addGuests.handler.ts:92-106

Guests can be added to inactive or past bookings — Guests added to `CANCELLED`, `REJECTED`, or past bookings create attendee rows, calendar updates, and emails for bookings that should be immutable. Reject the update unless `booking.status` is `CONFIRMED` or `PENDING` and `booking.endTime` is still in the future.

highbugpackages/trpc/server/routers/viewer/bookings/addGuests.handler.ts:92-106

Guests added to seated bookings are created without BookingSeat records — These guests have no seat, can exceed `seatsPerTimeSlot`, and are mishandled by seat reschedule and cancellation flows. Reject seated bookings here or create `BookingSeat` records instead of bare `Attendee` rows, following `handleSeats/create/createNewSeat.ts`.

highbugpackages/trpc/server/routers/viewer/bookings/addGuests.handler.ts:158-165

Add-guests calendar update uses caller's credentials instead of organizer's — Organizer calendar events are skipped or updated through the wrong credential when an attendee or team admin adds guests. Build `EventManager` from `booking.user` and `booking.user.credentials`, already loaded by the booking query, instead of `getUsersCredentials(ctx.user)`.

highbugpackages/trpc/server/routers/viewer/bookings/addGuests.handler.ts:158-171

Calendar sync error after attendee commit causes misleading failure — If `updateCalendarAttendees` throws after attendees are committed, the mutation reports total failure even though the guests exist; retrying then fails uniqueness and leaves the calendar out of sync. Catch and handle the calendar error separately, or record a pending-sync state.

highbugpackages/trpc/server/routers/viewer/bookings/addGuests.handler.ts:46-48

Team admins rejected: isTeamAdminOrOwner uses && instead of || — `isTeamAdminOrOwner` is true only for owners, so team admins receive `FORBIDDEN` despite the canonical `OWNER || ADMIN` check in `get.handler.ts`. Replace `&&` with `||` or use the shared `isUserTeamAdminOrOwner` helper.

highsecuritypackages/trpc/server/routers/viewer/bookings/addGuests.handler.ts:70-78

Guest email blacklist can be bypassed with case variations — A blocked address can still be added by changing its case because `blacklistedGuestEmails.includes(guest)` never normalizes the candidate. Compare `guest.toLowerCase()` against the lowercased list, as in `checkIfBookerEmailIsBlocked.ts`.

mediumbugpackages/trpc/server/routers/viewer/bookings/addGuests.handler.ts:124-147

Calendar event omits team data, so team hosts are not notified — Team hosts are silently skipped because `sendAddGuestsEmails` reads `calendarEvent.team?.members`, and team-event email fallbacks use the wrong name. Populate `evt.team`, including `members`, when building the `CalendarEvent`.

mediumbugapps/web/components/dialog/AddGuestsDialog.tsx:35-46

Stale email validation error persists after successfully adding guests — A previously triggered validation error reappears after a successful submission because `onSuccess` leaves `isInvalidEmail` set while the dialog remains mounted. Reset it with `setIsInvalidEmail` on success or when the dialog opens.

mediumperformancepackages/trpc/server/routers/viewer/bookings/addGuests.schema.ts:5

Unbounded guests array allows resource and email abuse — One request can insert unlimited attendee rows and trigger unlimited guest and attendee emails, enabling resource exhaustion and email abuse. Add a reasonable `.max(...)` bound to `guests` in `ZAddGuestsInputSchema`.

mediumbugapps/web/components/dialog/AddGuestsDialog.tsx:42-45

Error toast shows undefined code and bypasses the fallback — Network and aborted-request errors without a TRPC code display `undefined: ...`, and the always non-empty template literal makes the `unable_to_add_guests` fallback unreachable. Build the message conditionally, including `err.data?.code` only when it exists.

mediumbugpackages/trpc/server/routers/viewer/bookings/addGuests.handler.ts:74-106

Check-then-act race allows duplicate guest attendees on concurrent requests — Concurrent requests can both observe the same email as absent and insert it, creating duplicate attendee rows and invitation emails. Enforce a unique constraint on `bookingId` and `email`, or serialize the check-and-insert per booking with `prisma.$transaction`.

mediumbugpackages/emails/templates/organizer-add-guests-email.ts:28

Email subject can use an arbitrary or newly added attendee's name — The subject can be empty or name a new guest because `this.calEvent.attendees[0].name` indexes attendees built without `orderBy` in `addGuests.handler.ts`. Select the original booker explicitly or order the attendees before indexing.

mediumsecuritypackages/trpc/server/routers/viewer/bookings/addGuests.handler.ts:74-77

Guest uniqueness check can be bypassed with email case variations — Duplicate attendee rows and invitation emails result when `Alice@example.com` bypasses the exact `guest === attendee.email` comparison for an existing `alice@example.com`. Normalize both addresses with `toLowerCase()` before comparing.

mediumbugpackages/trpc/server/routers/viewer/bookings/addGuests.schema.ts:3-6

Server schema accepts duplicate guest emails — Direct API calls can submit the same address twice because `uniqueGuests` only filters existing attendees and blacklist entries, leading to duplicate attendee rows or a constraint failure plus duplicate emails. Add the client's uniqueness refinement to `guests` in `ZAddGuestsInputSchema`, or dedupe in the handler. **Also found in:** - `packages/trpc/server/routers/viewer/bookings/addGuests.handler.ts:74-81`

mediumbugpackages/trpc/server/routers/viewer/bookings/addGuests.handler.ts:168

Existing attendees are emailed as newly added guests — Passing raw `guests` to `sendAddGuestsEmails` marks existing attendees as new, sending them a fresh booking confirmation and ICS invite. Pass `uniqueGuests`, which contains only addresses actually added, matching the `newGuests` contract in `packages/emails/email-manager.ts`.

Gold bugs found (10)

highisTeamAdminOrOwner combines isTeamAdmin and isTeamOwner with &&, so only team owners pass; team admins who are not organizer or attendee are wrongly rejected with FORBIDDEN.
highThe guest blacklist is lowercased but incoming guest emails are compared without normalization, so a blacklisted address submitted with different casing bypasses BLACKLISTED_GUEST_EMAILS and is added and emailed.
mediumThe server never deduplicates the guests array, so a request with the same email twice inserts duplicate attendee rows for the booking.
highAttendee authorization and existing-attendee dedup compare emails case-sensitively, so an attendee with differently-cased stored email is FORBIDDEN and a case-variant of an existing attendee is added again.
mediumThe handler passes the unfiltered guests list to sendAddGuestsEmails, which uses it to pick who gets AttendeeScheduledEmail, so existing attendees included in the request receive a new-booking confirmation instead of the add-guests email.
highEventManager is created with the requesting user's credentials, so when a non-organizer adds guests the organizer's calendar event is not updated (or the wrong account is used) for references without a credentialId.
highClaims a failing calendar update at addGuests.handler.ts:165 aborts the mutation after guests are persisted; the calendar update path already swallows provider errors.
mediumThe guests array has no server-side size limit, so any authorized caller, including an attendee, can add thousands of guests and trigger an unbounded batch of inserts and emails.
mediumAfter a validation failure followed by a successful add, isInvalidEmail stays true, so the stale emails_must_be_unique_valid error shows the next time the dialog is opened.
highaddGuests does not check the booking status, so guests can be added to cancelled or rejected bookings, which updates calendars and emails invitations for events that no longer exist.

Gold bugs missed (8)

mediumsendAddGuestsEmails ignores the event type's disableStandardEmails settings, so hosts and attendees receive add-guests emails even when standard emails are disabled.
mediumThe add-guests handler omits booking.iCalUID from the CalendarEvent, so the add-guests emails' .ics attachments use booking.uid as UID and recipients' calendars treat them as a new event rather than an update of the original booking invite.
highGuest email uniqueness is checked case-sensitively, so case variants of the same address are accepted as distinct guests (and slip past the lowercased blacklist).
lowThe addGuests FORBIDDEN error uses the translation key you_do_not_have_permission, which is missing from the locale files, so the dialog shows the raw key to users.
mediumaddGuestsHandler fetches the organizer with findFirstOrThrow on booking.userId || 0; bookings with a null userId make the lookup throw an unhandled Prisma error, returned as a 500 instead of a handled TRPCError.
mediumsendAddGuestsEmails builds attendee emails without showAttendees, so for seated events the email hides other attendees even when seatsShowAttendees is enabled.
mediumClaimed: different errors for unknown vs unauthorized booking ids let any authenticated user enumerate valid booking ids.
mediumThe add-guests action and handler ignore eventType.disableGuests and seatsPerTimeSlot, so guests can be added to events where guests are disabled and to seated events without a seat record.