Claude Opus 5.5 · Heavy

oauth-credential-sync-and-app-integration-enhancements-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 Haiku 5.5.

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

Published comments (7)

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

Missing refresh_token is replaced with a placeholder that overwrites the stored token — Microsoft and sync-endpoint responses normally omit `refresh_token`, so Office365 spreads this placeholder over `o365AuthCredentials` and overwrites the real token, breaking every later refresh. Leave the field unset instead of writing the literal `"refresh_token"`.

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

Refresh-token parse result object saved as credential key instead of its data — Saving the whole `SafeParseReturnType` from `parseRefreshTokenResponse` as `credential.key` corrupts the Google credential, so `key.access_token` and `key.refresh_token` later read as undefined. Check `success` first, then save only `.data`.

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

Credential sync returns raw fetch Response instead of provider token shape — In sync mode, callers that read `res.data.access_token` or `zohoCrmTokenInfo.data` get undefined from a raw fetch `Response`, so the token refresh crashes. Return the same shape each provider's `refreshFunction` returns, or have callers parse the `Response` JSON. **Also found in:** - `packages/app-store/googlecalendar/lib/CalendarService.ts:86-96` - `packages/app-store/zoho-bigin/lib/CalendarService.ts:96-97` - `packages/app-store/zohocrm/lib/CalendarService.ts:204-217` - `packages/app-store/hubspot/lib/CalendarService.ts:177-191` - `packages/app-store/hubspot/lib/CalendarService.ts:177-189`

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

Credential ID passed to refreshOAuthTokens where a user ID is expected — With credential sharing on, the sync endpoint receives `credentialId` as `calcomUserId` and may return another user's tokens or none at all. Pass the credential's `userId` to `refreshOAuthTokens` instead.

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

Salesforce token refreshed and DB updated on every service construction — Every booking that touches Salesforce pays an extra network call and DB write, and can hit Salesforce rate limits. Have `getClient` refresh only when the token has expired, or let jsforce's built-in refresh handle it.

mediumbugpackages/app-store/salesforce/lib/CalendarService.ts:96-103

Connection is created with the stale access token instead of the refreshed one — `jsforce.Connection` still gets the pre-refresh `credentialKey.access_token`, so the new token is never used and the refresh round-trip is wasted. Pass `accessTokenParsed.data.access_token` and its `instance_url` to the connection.

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

Webhook secret check uses a non-constant-time comparison — An attacker can time the `!==` check to recover `CALCOM_WEBHOOK_SECRET` byte by byte, and that secret alone guards an endpoint that writes credentials for any `userId`. Ensure the header is a single string, then compare equal-length Buffers with `crypto.timingSafeEqual` (or compare hashes).

Gold bugs found (4)

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.
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.
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 (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.
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.
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.
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.