DeepSeek V4.1 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 Haiku 5.5.

Gold bugs found
6 of 9
Comments published
10
Comments matching a bug
6
Comments not matching
4
Cost of this PR
$0.176

Published comments (10)

highbugapps/web/pages/api/webhook/app-credential.ts:50-54

App metadata lookup uses public slug instead of metadata key, causing 404 — `appStoreMetadata` is keyed by directory name while `app.slug` holds the public slug, so most apps resolve to `undefined` and return 404, breaking credential sync. Look up the entry by `dirName` (selected alongside `slug`) instead.

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

Refresh response without refresh_token overwrites stored token with placeholder — When the response omits `refresh_token`, this writes the literal `"refresh_token"` over the stored credential; for Office 365 (optional `refresh_token` in `refreshTokenResponseSchema`) it is persisted and permanently breaks later refreshes with `invalid_grant`. Keep the caller's existing refresh token instead of injecting a placeholder.

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

Refresh token wrapper stored as credential key breaks Google auth — `parseRefreshTokenResponse` returns the `SafeParseSuccess` wrapper, so storing it as the credential key makes `googleCredentialSchema.parse` fail in `googleAuth` on the next read and breaks Google Calendar after the first refresh. Persist `key.data` instead.

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

Sync path returns raw fetch Response instead of parsed token JSON — Callers like `googlecalendar`, `hubspot`, `zoho-bigin`, and `zohocrm` expect provider-native token shapes, so returning the raw `Response` makes them no-op, crash, or overwrite the stored credential in shared mode. Return `await response.json()` or normalize each caller.

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

refreshOAuthTokens receives credentialId instead of owning user id — `refreshOAuthTokens` is passed `credentialId` as its `userId`, so the sync endpoint fetches another user's tokens or none and persists them onto this credential. Pass the credential's `userId` instead.

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

Connection is built with stale access token after refresh — The `jsforce.Connection` is built right after refresh from the pre-refresh `credentialKey.access_token`, so an expired token still fails despite the fresh one being saved. Use `accessTokenParsed.data.access_token` and the refreshed `instance_url` when constructing it.

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

Salesforce token refresh validates via statusText instead of response.ok — `statusText` is empty for HTTP/2 and for servers omitting a reason phrase, so a valid 200 response throws `HttpError` and every Salesforce calendar operation fails. Check `response.ok` and read the body for the error message.

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

Salesforce client creation always refreshes token regardless of expiry — `getClient` runs on every constructor call, so each booking and calendar fetch now triggers a Salesforce token round trip and a `prisma.credential.update` write. Only refresh when the stored token is actually expired.

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

Webhook secret compared with timing-unsafe string inequality — The strict inequality short-circuits on the first differing byte and leaks the secret prefix through timing on this unauthenticated endpoint. Compare with `crypto.timingSafeEqual` over equal-length buffers after confirming the header is a string.

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

Race condition can create duplicate app credentials — Without a transaction or a unique constraint on userId+appId, concurrent webhook deliveries both `create`, leaving duplicate credentials where `findFirst` returns an arbitrary stale row. Add a unique constraint and `upsert`, or wrap the check-and-write in a serializable transaction.

Gold bugs found (6)

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

Gold bugs missed (3)

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.