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)

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

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.

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

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

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

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.

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

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.

mediumbugpackages/app-store/googlecalendar/lib/CalendarService.ts:97

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.

mediumsecuritypackages/app-store/zoho-bigin/lib/CalendarService.ts:93

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.

mediumbugpackages/app-store/zoomvideo/lib/VideoApiAdapter.ts:92

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.

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

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

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

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.

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

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.

mediumbugpackages/app-store/salesforce/lib/CalendarService.ts:75-90

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

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

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`

Gold bugs found (5)

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.
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 (4)

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.
highSalesforce checks response.statusText !== 'OK' instead of response.ok when refreshing the token, which can misclassify successful responses, and then ignores the refreshed token.