Claude Opus 5.5 · 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
8 of 9
Comments published
12
Comments matching a bug
8
Comments not matching
4
Cost of this PR
$1.707

Published comments (12)

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

Sync-mode token refresh returns a raw `Response` that callers cannot use — Google reads `res.data`, HubSpot reads `expiresIn`/`accessToken`, and Zoho reads `tokenInfo.data`, so token refresh crashes or saves undefined values whenever `CALCOM_CREDENTIAL_SYNC_ENDPOINT` is set. Return parsed JSON in a shape every caller can use, or adapt each caller to parse the `Response`.

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

Google credential key saved as the zod safeParse result, not its data — Saving the whole `SafeParseReturn` from `parseRefreshTokenResponse` makes `googleCredentialSchema.parse(credential.key)` fail later, which breaks the Google credential. Check `key.success` and persist `key.data` instead.

highbugpackages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:25-27

Missing refresh_token replaced with placeholder that overwrites stored token — Office365 (spreading `tokenResponse.data`) and Zoom (assigning `key.refresh_token = newTokens.refresh_token`) save the placeholder over the real token, so the next refresh fails and the credential breaks permanently. Leave `refresh_token` unset and let callers keep the stored value.

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

Credential ID passed as userId to refreshOAuthTokens — In sync mode the endpoint receives `credentialId` as `calcomUserId` and returns tokens for the wrong user, or none. Pass the credential's `userId` to `refreshOAuthTokens` instead.

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

`prisma` is used in the Salesforce client without being imported — Building the Salesforce client fails with a ReferenceError or type error because `prisma` is never imported in this file. Add `import prisma from "@calcom/prisma"`.

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

Token refresh fails on success when `statusText` is not "OK" — On HTTP/2, `statusText` can be empty, and it can differ from "OK" on success, so the client throws even when the refresh worked. Check `response.ok` instead.

highbugpackages/app-store/salesforce/lib/CalendarService.ts:101-103

jsforce connection uses stale access token instead of refreshed one — The refresh has no effect because the connection still uses the old `credentialKey.access_token` and `instance_url`. Build it from `accessTokenParsed.data.access_token` and its `instance_url`.

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

Computed keys collapse to "[object Object]" so token fields are stripped — Because `[z.string().toString()]` evaluates to "[object Object]", `z.object` strips `expires_in`, `expiry_date` and other fields in sync mode, and Zoom computes a NaN `expiry_date`. Call `.passthrough()` on `z.object({ access_token: z.string() })` or define the expiry fields explicitly.

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

Salesforce token is refreshed and saved on every service construction — Each `SalesforceCalendarService` construction adds a Salesforce call and a DB write to every booking, even with a valid token, and can hit Salesforce rate limits. Refresh only when the token is expired, or rely on jsforce's built-in refresh.

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

Webhook secret compared with non-constant-time `!==` — A plain `!==` leaks timing information on an endpoint that can write any user's third-party credentials. Compare against `CALCOM_WEBHOOK_SECRET` with `crypto.timingSafeEqual` after checking the lengths match.

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

Malformed webhook body returns unhandled 500 instead of 400 — Because `appCredentialWebhookRequestBodySchema.parse` throws, a malformed request comes back as an unhandled 500. Use `safeParse` and return 400 when it fails.

mediumbugapps/web/pages/api/webhook/app-credential.ts:57-59

Unhandled decrypt/JSON.parse failure causes 500 instead of 400 — When decryption fails or the plaintext isn't valid JSON, `symmetricDecrypt` or `JSON.parse` throws uncaught and the webhook returns a 500 with no useful error. Wrap both in try/catch and return 400.

Gold bugs found (8)

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.
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.
highThe new Salesforce token refresh uses prisma without importing it, so the code fails type checking and throws a ReferenceError at runtime.
highSalesforce checks response.statusText !== 'OK' instead of response.ok when refreshing the token, which can misclassify successful responses, and then ignores the refreshed token.
highAfter refreshing the Salesforce token, jsforce.Connection is created with the stale access_token and instance_url instead of the newly refreshed values.

Gold bugs missed (1)

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.