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)
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`.
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.
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.
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.
`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"`.
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.
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`.
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.
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.
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.
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.
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.