Kimi K3.1 Pro · 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
- 5 of 9
- Comments published
- 12
- Comments matching a bug
- 5
- Comments not matching
- 7
- Cost of this PR
- $1.870
Published comments (12)
Non-constant-time webhook secret comparison enables timing attacks — The `!==` check lets response timing reveal matching secret prefixes, weakening protection for arbitrary credential writes. Compare equal-length buffers with `crypto.timingSafeEqual` and reject length mismatches before comparison.
App metadata lookup uses directory keys instead of metadata slugs — Valid sync requests return 404 because `appStoreMetadata` is keyed by directory names such as `googlecalendar`, while `app.slug` contains slugs such as `google-calendar`. Match each metadata value's `slug`, or reuse `getAppWithMetadata({ slug })`, instead of indexing with `app.slug`.
Concurrent webhook requests can create duplicate app credentials — Two concurrent requests can both observe no `appCredential` and execute `create`, leaving duplicate rows that later `findFirst` calls update inconsistently. Make lookup and creation atomic, or enforce uniqueness and handle the resulting conflict with an upsert.
Missing refresh tokens are replaced with a sentinel string — For Office 365, an omitted `refresh_token` becomes the literal `"refresh_token"`, which overwrites the real credential and makes a later direct refresh fail. Preserve the previous refresh token or leave the field absent instead of synthesizing a sentinel.
Refresh token update stores the safe-parse wrapper as credential JSON — `parseRefreshTokenResponse` returns a Zod safe-parse result, so the update stores `{ success, data }` and the next `googleCredentialSchema.parse(credential.key)` fails. Check `success`, throw on failure, and persist `data`, or make the parser return parsed data directly.
Bigin passes a credential ID as the user ID for OAuth token refresh — `credentialId` is serialized by `refreshOAuthTokens` as `calcomUserId`, letting Bigin request and use another user's token when a credential ID matches that user's ID. Thread `credential.userId` through `refreshAccessToken` and pass it instead of the credential row ID.
Zoom token refresh uses the wrong app slug — Using `zoomvideo` makes the sync service look up a nonexistent or different app, so Zoom token refresh fails. Send `zoom` to match `App.slug` and the metadata slug.
Returned connection still uses the expired pre-refresh token — The current operation still uses the pre-refresh `credentialKey.access_token` and `instance_url`, so it can fail with the expired token or refresh again despite the database update. Build the returned connection from `accessTokenParsed.data.access_token` and `accessTokenParsed.data.instance_url`.
Constructor unconditionally refreshes and persists Salesforce tokens — Constructing `SalesforceCalendarService` now blocks on a provider refresh and database update even for valid tokens, adding latency and rate-limit exposure to calendar operations. Gate refresh on token expiry and persist only when a refresh occurs.
Webhook updates an arbitrary credential when a user has multiple app accounts — OAuth setup can create multiple credentials for the same `userId` and `appId`, and the `Credential` schema does not make that pair unique, so `findFirst` can overwrite one account while leaving others stale. Include a credential or external-account identifier in the request and target it explicitly.
Salesforce refresh ignores `CALCOM_CREDENTIAL_SYNC_ENDPOINT` — Credential sharing is bypassed, so synced Salesforce credentials still require local consumer credentials and refresh outside the source-of-truth app store. Route this request through `refreshOAuthTokens` with the Salesforce slug and `credential.userId` to honor `CALCOM_CREDENTIAL_SYNC_ENDPOINT`.
Credential sync returns raw fetch responses instead of provider token data — Returning a raw fetch `Response` breaks sync-enabled callers: Google reads `res.data`, HubSpot expects an SDK token object, Zoho adapters read `tokenInfo.data`, and Lark/Webex need provider-specific bodies. Define a normalized token-result contract and adapt every caller to prevent exceptions and invalid persisted tokens. **Also found in:** - `packages/app-store/larkcalendar/lib/CalendarService.ts:67-84` - `packages/app-store/webex/lib/VideoApiAdapter.ts:62-80`