GPT-6.1 Sol · 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 Haiku 5.5.

Gold bugs found
5 of 9
Comments published
9
Comments matching a bug
5
Comments not matching
4
Cost of this PR
$3.498

Published comments (9)

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

Fabricated refresh token overwrites the stored Office 365 refresh token — A successful Office 365 response can omit `refresh_token`, so fabricating it destroys a valid stored token. Leave `refreshTokenResponse.data.refresh_token` absent when no replacement is returned, preserving the stored token during merging.

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

Salesforce token refresh uses an unimported Prisma client — Successful Salesforce refreshes can throw `ReferenceError` in production because `packages/prisma/index.ts` initializes the global `prisma` only outside production. Import `prisma` explicitly from `@calcom/prisma` before updating the credential.

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

Sync refresh returns a Response where callers expect provider token objects — With synchronization enabled, callers of `refreshOAuthTokens` expecting `res.data.access_token`, `response.data.error`, or `HubspotToken` receive an unparsed `Response`, causing refresh failures or undefined token fields. Normalize the sync result and update consumers to a consistent contract while preserving support for fetch-based callers.

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

Token refresh persists the parse result instead of credential data — Writing the `parseRefreshTokenResponse` result directly stores a wrapper without top-level tokens, so the next `googleCredentialSchema.parse` fails even with sharing disabled. Check `success`, handle parsing failures, and assign `.data` to `key` before persisting.

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

OAuth refresh passes a credential ID instead of the owning user ID — Sync requests can target the wrong user because `refreshOAuthTokens` sends its third argument as `calcomUserId`, but `credentialId` comes from `credential.id`. Pass the owning `credential.userId` instead, using `null` for team-owned credentials so the helper falls back to normal refresh.

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

Concurrent first deliveries can create duplicate app credentials — Simultaneous deliveries can both reach `prisma.credential.create` and insert duplicate user/app credentials; check the `Credential` model for the missing uniqueness constraint. Serialize lookup and creation per user/app pair, or add a matching unique key and atomic upsert.

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

Salesforce initialization always refreshes tokens but uses the stale token — Each initialization incurs an OAuth request and database write even for valid tokens, yet the connection still uses the original `credentialKey.access_token`. Refresh only when necessary and initialize the connection with the refreshed token.

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

Webhook secret comparison leaks timing information — Direct equality against `CALCOM_WEBHOOK_SECRET` can expose secret information through timing differences on this credential-writing endpoint. Validate that the supplied header is a single string, then compare fixed-length cryptographic digests with `timingSafeEqual`.

mediumbugpackages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:7-10

Token response schema uses literal keys and strips additional properties — Ordinary token responses miss the documented handling because `[z.string().toString()]` and `[z.string().optional().toString()]` create literal property names, while `z.object` strips additional fields. Explicitly validate supported expiry fields and preserve additional token properties as required by the contract.

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

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