Gemini 3.8 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
2 of 9
Comments published
5
Comments matching a bug
2
Comments not matching
3
Cost of this PR
$0.581

Published comments (5)

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

Zod safe-parse wrapper stored in credential key — Subsequent reads parsing `credential.key` with `googleCredentialSchema` will throw validation errors because the `{ success: true, data: ... }` wrapper is saved instead of the payload. Pass `key.data` instead of `key` to `prisma.credential.update`.

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

Credential ID passed to refreshOAuthTokens instead of user ID — The sync service associates token refreshes with the wrong account or fails resolution because `credentialId` is forwarded as `calcomUserId`. Pass `credential.userId` instead, or update `refreshAccessToken` to receive and forward the user ID.

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

Raw fetch Response breaks callers expecting Axios data or token payload — Callers accessing `.data` on the returned `Response` receive `undefined` and throw a `TypeError` when credential sync is enabled. Parse and return the JSON payload from `response` instead of returning the raw Fetch `Response`.

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

Case-sensitive header lookup and non-constant-time secret comparison — Node.js lowercases all `req.headers` keys, causing mixed-case lookups to fail, while `!==` leaves the secret vulnerable to timing attacks. Convert `CALCOM_WEBHOOK_HEADER_NAME` to lowercase before indexing and compare the secret using `crypto.timingSafeEqual`.

mediumbugpackages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:8-10

Using `z.string().toString()` produces `[object Object]` schema keys — This strips token response properties other than `access_token` and skips expiry validation because `z.string().toString()` evaluates to the literal key `"[object Object]"`. Replace the computed keys with `z.record()` or chain `.passthrough()` on the schema.

Gold bugs found (2)

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.

Gold bugs missed (7)

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