GLM-5.3 Flash · Heavy

oauth-credential-sync-and-app-integration-enhancements-cal-com

cal.com · TypeScript · M · 100–299 lines · 6 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.

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

Published comments (10)

highbugpackages/app-store/webex/lib/VideoApiAdapter.ts:62-78

Sync-mode refresh responses rejected by strict webexRefreshedTokenSchema — Sync-mode responses only carry an access token and expiry, but `webexRefreshedTokenSchema` demands literal `scope`, `token_type`, and `refresh_token` fields, so every webex refresh rejects and no token is ever persisted. Validate the response with `parseRefreshTokenResponse` like the other adapters do.

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

Credential key stores parseRefreshTokenResponse wrapper instead of parsed token — `parseRefreshTokenResponse` returns the `{ success, data }` safeParse wrapper, so the credential key becomes that wrapper instead of the token, and Google Calendar breaks on the next call after its first refresh. Store `parsedToken.data` as the key, matching the other consumers.

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

Broken computed keys make token schema strip expiry_date and real refresh_token — The computed keys evaluate to the literal key `[object Object]`, so `z.object` strips `expiry_date` and the real `refresh_token`, and persisting the result wipes the user's stored refresh token. Use a passthrough schema that captures the numeric expiry and never write a placeholder `refresh_token`. **Also found in:** - `packages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:25-27`

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

refreshOAuthTokens is passed credential id instead of the user id, risking cross-user token sync — Passing `credentialId` as the `userId` argument makes the sync endpoint return another user's OAuth tokens, which would be persisted into this user's credential — a cross-user leak. Pass `credential.userId`, as the other integrations do.

highbugpackages/app-store/salesforce/lib/CalendarService.ts:86

Token refresh success check relies on environment-dependent statusText — `statusText` is empty for HTTP/2 and in runtimes that drop the reason phrase, so a valid 200 response fails this check and the whole refresh rejects. Test `response.ok` (or `response.status === 200`) instead.

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

Non-atomic find-then-create can create duplicate credentials for same user+app — Concurrent webhooks can both pass `findFirst` and each run `create`, leaving duplicate `Credential` rows — `schema.prisma` has no unique constraint on (`userId`, `appId`). Use a transaction with SELECT ... FOR UPDATE, or add a unique constraint and upsert with a `P2002` fallback.

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

getClient performs blocking token refresh and DB write on every service construction — `SalesforceCalendarService` is constructed for every calendar operation, including availability checks on booking-page loads, and each construction now pays a blocking refresh POST to Salesforce plus a `prisma.credential.update` even when the stored access token is still valid. Check expiry first and refresh only when needed, as other providers do.

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

New access token saved but stale token used for jsforce connection — The connection keeps running on the stale `credentialKey.access_token` captured before the refresh, while the fresh token is only written to the database and never used. Pass `accessTokenParsed.data.access_token` to the `jsforce.Connection`.

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

Sync branch returns raw fetch Response instead of parsed token payload — Callers written for the non-sync shape — Google's `res?.data`, zoho's `tokenInfo.data`, hubspot's token fields — crash or misread the raw fetch Response. Await `response.json()` and return the parsed body so both branches honor the same contract. **Also found in:** - `packages/app-store/googlecalendar/lib/CalendarService.ts:86-96` - `packages/app-store/hubspot/lib/CalendarService.ts:177-191`

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

Webhook secret compared with non-constant-time !==, leaking it via timing — This endpoint can overwrite any user's OAuth credentials, and the `!==` comparison leaks the secret byte-by-byte through response timing, letting an attacker forge webhook calls. Compare hashed buffers with `crypto.timingSafeEqual` and fail closed when the header is missing.

Gold bugs found (9)

mediumThe webhook's non-atomic findFirst-then-create lets concurrent deliveries for the same user and app insert duplicate credential rows.
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.
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.
mediumZoho Bigin passes the credential id instead of the user id to refreshOAuthTokens, so the sync endpoint receives the wrong calcomUserId.
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.
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.

Gold bugs missed (10)

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.
highThe new Salesforce token refresh uses prisma without importing it, so the code fails type checking and throws a ReferenceError at runtime.
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.
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.
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.