Claude Sonnet 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
3 of 9
Comments published
7
Comments matching a bug
3
Comments not matching
4
Cost of this PR
$0.923

Published comments (7)

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

Safe-parse result stored as credential key instead of parsed data — Saving the whole safe-parse result makes the stored key `{ success, data }`, so later `googleCredentialSchema.parse(credential.key)` fails and the credential breaks. Store `parseRefreshTokenResponse(...).data` as `key`.

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

Sync-mode refreshOAuthTokens returns raw Response instead of token data — Callers read `res.data` or `.accessToken`/`.expiresIn`, which are undefined on a `Response`, so Google's TypeError is swallowed and Hubspot computes a NaN expiry. Parse the JSON in `refreshOAuthTokens` and adapt it to each caller's shape, or have callers call `response.json()`.

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

Credential id passed as userId to refreshOAuthTokens — The sync endpoint receives a credential id as `calcomUserId`, so it refreshes tokens for the wrong user or none. Pass `credential.userId` through `biginAuth` and `refreshAccessToken` instead of `credentialId`.

highbugpackages/app-store/salesforce/lib/CalendarService.ts:75-94

Salesforce token refresh bypasses refreshOAuthTokens and credential sync — Calling Salesforce directly bypasses `refreshOAuthTokens`, so for synced credentials `parseRefreshTokenResponse` can store the placeholder refresh token, Salesforce rejects it, and no connection is created. Wrap the fetch in `refreshOAuthTokens(..., "salesforce", credential.userId)` and skip the local refresh when synced.

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

Salesforce connection built with stale access token after refresh — The fresh token is saved, but the `jsforce.Connection` still uses the old `credentialKey.access_token`, so calls can fail with an expired session. Use `accessTokenParsed.data.access_token` and its instance URL, and route the refresh through `refreshOAuthTokens`.

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

Salesforce token refresh and DB write run on every service instantiation — `getClient` runs in the constructor, so every instantiation adds a blocking token refresh and a DB write, risking Salesforce rate limits. Refresh only when the stored token is expired or a call fails with an auth error.

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

Webhook secret compared with non-constant-time !== operator — Comparing with `!==` leaks timing information, letting an attacker recover the secret and overwrite any user's app credentials. Use `crypto.timingSafeEqual` on equal-length buffers and handle a missing header value explicitly.

Gold bugs found (3)

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 (6)

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