GLM-5.3 Flash · Balanced
oauth-credential-sync-and-app-integration-enhancements-cal-com
cal.com · TypeScript · M · 100–299 lines · 6 files
The normal review, with one generalist agent. Judge: Claude Opus 5.5.
- Gold bugs found
- 7 of 19
- Comments published
- 9
- Comments matching a bug
- 7
- Comments not matching
- 2
- Cost of this PR
- $0.106
Published comments (9)
refreshOAuthTokens is passed credential.id instead of the cal.com userId — With credential sharing enabled, the sync endpoint is asked for another record's credentials, so the wrong user's tokens can be written into this credential. Pass `credential.userId` instead of `credentialId`.
Webhook header name not lowercased, causing constant 403 for mixed-case env values — Node lowercases incoming header names, so a mixed-case `CALCOM_WEBHOOK_HEADER_NAME` never matches and every request gets a 403. Normalize the env value with `toLowerCase()` before the lookup.
appStoreMetadata keyed by dirName, but app.slug is the DB slug, causing 404 — The keys of `appStoreMetadata` are directory names, not DB slugs, so the lookup misses for every app where the two differ and credential sync always 404s — including the OAuth apps this targets. Search for a matching `slug` instead of indexing.
Wrong app slug passed to refreshOAuthTokens: "zoomvideo" instead of "zoom" — The sync webhook resolves the app by DB slug, so `"zoomvideo"` never matches and zoom tokens can never sync — the webhook 404s. Pass `"zoom"`, like the other call sites.
Sync mode returns raw fetch Response instead of parsed token body — Callers expect the parsed token shape their `refreshFunction` returns, so the raw `Response` yields `TypeError`s and `NaN` expiries persisted into `credential.key`. Return `await response.json()` so both branches share one contract. **Also found in:** - `packages/app-store/googlecalendar/lib/CalendarService.ts:97-100`
Duplicate computed keys make minimumTokenResponseSchema drop all fields except access_token — Refreshed tokens lose `expires_in`, `expiry_date` and `refresh_token` because both computed keys collide and zod's strip mode keeps only `access_token`, so office365calendar re-refreshes on every call. Replace the object with `.passthrough()` or model the expiry explicitly.
Webhook secret compared with !== instead of timing-safe comparison — The plain comparison leaks timing information, and this secret authorizes overwriting OAuth credentials for any user — a direct path to credential takeover. Compare with `crypto.timingSafeEqual` over equal-length buffers of both values.
Racing webhook deliveries can create duplicate user+app credentials — Two concurrent deliveries can both pass the `findFirst` check and create duplicates, after which `findFirst` may return a stale row. Wrap the find-then-create in a transaction with retry, or add a unique `userId`+`appId` constraint to `Credential` in `schema.prisma`.
Eager token refresh on every instantiation is wasted work; dropped in favor of jsforce auto-refresh — The freshly fetched `access_token` is discarded — the `jsforce` connection is built from the stale `credentialKey.access_token`, so every operation pays a blocking token request plus a DB write for nothing. Drop the eager refresh and let jsforce handle expiry, or gate it behind credential sharing.