GLM-5.3 · 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 Haiku 5.5.

Gold bugs found
4 of 9
Comments published
11
Comments matching a bug
4
Comments not matching
7
Cost of this PR
$1.277

Published comments (11)

highbugpackages/app-store/googlecalendar/lib/CalendarService.ts:97-100

refreshAccessToken persists zod SafeParseReturnType wrapper instead of parsed tokens — `googleCredentialSchema.parse` throws on the next `GoogleCalendarService` construction because the persisted key is the `{success, data}` wrapper, not the tokens — permanently disabling Google Calendar after each user's first token refresh. Unwrap with `.data` before persisting, e.g. `parseRefreshTokenResponse(...).data`.

highbugpackages/app-store/_utils/oauth/refreshOAuthTokens.ts:8-15

Credential-sync path returns raw fetch Response, breaking token-parsing callers — With `CALCOM_CREDENTIAL_SYNC_ENDPOINT` set, `refreshOAuthTokens` returns the raw `Response`: googlecalendar reads `res?.data` and silently keeps the expired token, hubspot persists the Response as the credential key, and zoho callers crash. Parse the endpoint's JSON into a normalized token object, or pass it through each app's parser.

highbugapps/web/pages/api/webhook/app-credential.ts:72-81

Updated credentials never reset the invalid flag, leaving app disabled — Fresh keys never revive a credential marked `invalid` — `getCalendarsEvents.ts` filters those out, so a user whose app was disabled stays broken despite the sync, defeating the app store as source of truth. Add `invalid: false` to the `prisma.credential.update` data payload.

highbugpackages/app-store/salesforce/lib/CalendarService.ts:86

Token refresh checks unreliable statusText instead of response.ok — `statusText` is empty for HTTP/2 fetch responses and varies across 2xx codes, so a valid refresh can throw `HttpError` 400 with an empty message, breaking every Salesforce operation. Check `response.ok` instead.

highperformancepackages/app-store/office365video/lib/VideoApiAdapter.ts:61-75

msteams refresh via sync endpoint marks token expired, causing refresh loop — The sync endpoint's response has no `expires_in`, so `expiry_date` becomes `Date.now()` and `getToken()` re-runs the sync POST plus a credential write on every Teams call, gradually overwriting the key's `refresh_token`. Map the endpoint's expiry into the `expires_in` offset the caller expects.

highbugpackages/app-store/salesforce/lib/CalendarService.ts:90-99

Sync-config-driven schema strips instance_url from Salesforce token response — On sync-enabled instances the saved key loses `instance_url`, so the next `getClient` builds `jsforce.Connection` with `instanceUrl: undefined` and every Salesforce call hits the wrong host. `parseRefreshTokenResponse` picks `minimumTokenResponseSchema` from the global sync config; since this response comes straight from Salesforce, use `salesforceTokenSchema` here.

highbugpackages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:5-11

Computed schema keys collapse to one literal key, stripping token response fields — Both computed keys collapse to the single literal `"[object Object]"` and `z.object` strips unknown keys, so callers persist only `access_token` plus the placeholder `refresh_token: "refresh_token"` — office365calendar overwrites users' real refresh tokens, zoomvideo stores a NaN expiry. Use `z.object({ access_token: z.string() }).passthrough()` and stop forcing the placeholder.

mediumperformancepackages/app-store/salesforce/lib/CalendarService.ts:75-99

Unconditional Salesforce token refresh + DB write on every getClient call — Services are constructed per operation via `getCalendar()`, so eager `getClient` adds a blocking `login.salesforce.com` round trip and DB write to each one — and the new token goes unused since `Connection` still gets stale `credentialKey.access_token`. Gate refresh on token expiry, or let jsforce's built-in lazy refresh handle it.

mediumsecurityapps/web/pages/api/webhook/app-credential.ts:24-29

Webhook secret compared with non-constant-time !==, leaking timing info — Plain `!==` leaks match-length timing on this Internet-reachable endpoint, where the secret is the only authorization for overwriting any user's credentials. Compare SHA-256 digests of both values with `crypto.timingSafeEqual`.

mediumbugpackages/app-store/zoho-bigin/lib/CalendarService.ts:85-94

refreshOAuthTokens called with credential row id instead of user id — Passing `credentialId` (the credential row id) as `refreshOAuthTokens`'s `userId` parameter makes the sync endpoint resolve the wrong user — Bigin refresh fails or returns another user's tokens; every other caller passes `credential.userId`. Do the same here.

mediumbugapps/web/pages/api/webhook/app-credential.ts:62-90

Race condition in webhook creates duplicate credentials without unique constraint — Two concurrent deliveries both see `findFirst` return null and both `create`, since `schema.prisma` has only `@@index` — no unique constraint — on `Credential(userId, appId)`; later syncs update just one row, leaving a stale duplicate. Add `@@unique([userId, appId])` or upsert semantics.

Gold bugs found (4)

mediumminimumTokenResponseSchema uses computed keys from z.string().toString(), which produce a literal key rather than a wildcard, so the sync-mode schema does not validate or keep expiry and other token fields as intended.
highGoogle Calendar persists the safeParse result object instead of its data as the credential key, corrupting the stored credential so later reads fail.
mediumSalesforce getClient now refreshes the OAuth token and writes the credential on every service construction, adding a network round trip and DB write even when the access token is valid.
highSalesforce checks response.statusText !== 'OK' instead of response.ok when refreshing the token, which can misclassify successful responses, and then ignores the refreshed token.

Gold bugs missed (5)

mediumThe webhook parses the body with zod .parse and decrypts/JSON-parses the keys without error handling, so invalid payloads produce 500 errors instead of 400 responses.
highparseRefreshTokenResponse writes the hardcoded string 'refresh_token' when the refresh response omits a refresh token, so the stored credential gets an invalid refresh token and later refreshes fail.
highThe new Salesforce token refresh uses prisma without importing it, so the code fails type checking and throws a ReferenceError at runtime.
highAfter refreshing the Salesforce token, jsforce.Connection is created with the stale access_token and instance_url instead of the newly refreshed values.
highThe app-credential webhook looks up appStoreMetadata by app.slug, but the map is keyed by dirName, so apps whose slug differs from their directory (e.g. google-calendar) always get a 404 and their credentials cannot be synced.