MiniMax M3 · 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
2 of 9
Comments published
7
Comments matching a bug
2
Comments not matching
5
Cost of this PR
$0.262

Published comments (7)

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

parseRefreshTokenResponse overwrites missing refresh_token with literal string — In credential-sync mode the schema strips `refresh_token`, so the guard always writes the literal `"refresh_token"` to `Credential.key`. Subsequent Google and Microsoft refreshes then return `invalid_grant`.

highbugpackages/app-store/_utils/oauth/refreshOAuthTokens.ts:7-19

refreshOAuthTokens returns raw fetch Response on sync branch without parsing — Callers like `googlecalendar`, `hubspot`, `larkcalendar`, `zoho-bigin`, and `zohocrm` read `.data`/`.access_token` off the raw `Response` and throw. Await `.json()` and return `{ data }` so the sync branch matches the legacy shape. **Also found in:** - `packages/app-store/_utils/oauth/refreshOAuthTokens.ts:1-20`

highbugpackages/app-store/_utils/oauth/refreshOAuthTokens.ts:1-20

refreshOAuthTokens raw fetch Response breaks callers — Callers in `googlecalendar`, `zoomvideo`, and `office365calendar` read `.data`/`.access_token` from the raw `Response`, throwing on `token.access_token`. Await `.json()` (or reshape to the `{ res, tokens }` shape) so `parseRefreshTokenResponse` gets a parsed body.

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

statusText check fails on HTTP/2 responses — Salesforce serves over HTTP/2 where reason phrases arrive empty, so `response.statusText !== "OK"` rejects legitimate 200 responses with a spurious `HttpError`. Use `response.ok` (or a numeric status range) instead.

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

zoho-bigin passes credentialId where refreshOAuthTokens expects userId — `refreshOAuthTokens` posts its third arg as `calcomUserId`, but this caller passes `credential.id` (`credentialId`) instead of `credential.userId`. Pass `credential.userId` so the sync endpoint receives the user identifier it expects.

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

Webhook secret compared with non-constant-time equality — An attacker can recover the secret through timing because `!==` short-circuits on the first differing byte. Replace it with `crypto.timingSafeEqual` after the lengths match.

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

Race condition in credential findFirst/create creates duplicate Credential rows — Two concurrent webhook deliveries can both miss the `findFirst` and call `prisma.credential.create`, producing duplicate Credential rows. Wrap the pair in `prisma.$transaction` or use `prisma.credential.upsert` keyed on `userId`+`appId`.

Gold bugs found (2)

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

Gold bugs missed (7)

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