Amazon Ergo 1.0 · 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 Opus 5.5.

Gold bugs found
8 of 19
Comments published
9
Comments matching a bug
8
Comments not matching
1
Cost of this PR
$3.359

Published comments (9)

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

Credential-sharing mode returns raw fetch Response instead of parsed body — Provider callers break: `googlecalendar` dereferences `res.data.access_token`, `zoho-bigin`/`zohocrm` read `tokenInfo.data`, and `hubspot` persists the `Response`. Parse the sync response body into the shape each caller expects, or update every caller to consume its body.

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

Missing refresh tokens are replaced with an invalid placeholder — Sharing-mode responses omit `refresh_token`, so `office365calendar` and `zoom` overwrite the real token with an invalid placeholder and fail on the next refresh. Preserve the existing refresh token instead of inventing one.

highbugpackages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:5-11

Sharing-mode token schema strips expiry and provider fields — The computed keys in `minimumTokenResponseSchema` collide as ordinary string keys rather than forming a catchall, so Zod strips `expiry_date`, `expires_in`, `instance_url`, and other provider fields. Use `.passthrough()`/`.catchall()` or an explicit schema.

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

Bigin token refresh passes credential ID as Cal.com user ID — `refreshOAuthTokens` sends `credentialId` as `calcomUserId`, so the sync endpoint may refresh the wrong user's token or fail. Pass `credential.userId` instead.

highbugapps/web/pages/api/webhook/app-credential.ts:72-80

Credential sync leaves the invalid flag set after updating keys — The update writes `key` without clearing `credential.invalid`, so `getCalendarsEvents` keeps filtering out the credential and the app stays disabled. Set `invalid: false` when syncing valid `keys`.

highbugpackages/app-store/salesforce/lib/CalendarService.ts:96-103

Refreshed Salesforce token is not used for the connection — `getClient` builds the `jsforce.Connection` from pre-refresh `credentialKey.access_token` and `credentialKey.instance_url`, so the refreshed token is never used and expired-token failures persist. Build the connection from `accessTokenParsed.data`.

highsecuritypackages/app-store/_utils/oauth/refreshOAuthTokens.ts:8-13

Credential-sync request is unauthenticated — Anyone who can reach `CALCOM_CREDENTIAL_SYNC_ENDPOINT` can request third-party tokens for arbitrary `calcomUserId` values because the request has no authentication. Send a signed or authenticated request and verify it on the endpoint.

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

Credential sync uses incorrect Zoom app slug — The sync endpoint cannot match credentials stored under the registered `zoom` slug, so Zoom token refresh fails. Replace `zoomvideo` with `zoom` (see `packages/app-store/zoomvideo/_metadata.ts`).

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

Salesforce token refresh runs on every service instantiation — Gate the refresh on the stored token's expiry.

Gold bugs found (8)

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.
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.
highIn sync mode refreshOAuthTokens returns a raw fetch Response, but callers expect their provider-specific shapes (res.data, axios .data, HubspotToken), so token refresh breaks for Google, Zoho and HubSpot when credential sharing is on.
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.
mediumZoho Bigin passes the credential id instead of the user id to refreshOAuthTokens, so the sync endpoint receives the wrong calcomUserId.
highAfter refreshing the Salesforce token, jsforce.Connection is created with the stale access_token and instance_url instead of the newly refreshed values.
mediumThe webhook writes new keys without resetting the credential's invalid flag, so a credential previously marked invalid (e.g. after invalid_grant) remains excluded from calendar operations even after the source of truth pushes valid keys.
highZoom sends appSlug "zoomvideo" (the directory name) to the credential sync endpoint, but the app's slug and stored credentials use "zoom", so the sync service and the webhook (app lookup by slug) cannot resolve Zoom and token sync fails.

Gold bugs missed (11)

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.
mediumThe webhook's non-atomic findFirst-then-create lets concurrent deliveries for the same user and app insert duplicate credential rows.
highGoogle Calendar persists the safeParse result object instead of its data as the credential key, corrupting the stored credential so later reads fail.
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.
highWebex refresh is routed through refreshOAuthTokens but still validated with the strict webexRefreshedTokenSchema, so the minimal sync-endpoint response fails parsing and Webex refresh breaks for shared credentials.
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.
mediumFor MS Teams, a sync-endpoint response without expires_in makes the existing fallback set expiry_date to now and replace the stored key with only access_token/expiry_date, so every Teams call triggers another refresh and credential write and the refresh_token is lost.
highThe webhook updates the first credential matching userId+appId, but a user can have several credentials for the same app and the payload carries no credential identifier, so the wrong account's key can be overwritten while the intended one stays stale.
highSalesforce refreshes directly against Salesforce but parses the response with the minimum sync schema when credential sync is enabled, stripping instance_url and other fields from the stored key, so subsequent jsforce connections have no instance URL and the integration breaks.
mediumWith credential sync configured, parseRefreshTokenResponse always uses the minimum schema even when refreshOAuthTokens fell back to the provider (team credentials with userId null), so provider responses skip app-specific validation and transforms such as Office365's expires_in conversion.