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)
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.
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`.
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)`.
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.
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.
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`.
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`.
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.
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`.
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.
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`.
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.
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.
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`
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`.