Claude Sonnet 5.5 · 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
10
Comments matching a bug
5
Comments not matching
5
Cost of this PR
$2.703

Published comments (10)

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

Placeholder refresh_token applied outside credential sync mode — Overwriting a valid stored refresh token with a placeholder breaks later refreshes for callers like Zoom, which copy `newTokens.refresh_token` into the credential. Apply the `"refresh_token"` default only in sync mode, and otherwise keep the existing stored token.

highbugapps/web/pages/api/webhook/app-credential.ts:49-54

App metadata looked up by slug but appStoreMetadata is keyed by directory name — For apps whose slug differs from the directory name, such as Google Calendar and Zoom, the lookup returns undefined and the webhook returns 404, so their credentials never sync. `appStoreMetadata` is keyed by directory name, so find the entry in `Object.values(appStoreMetadata)` whose `slug` matches `app.slug`.

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

Webhook header name lookup is case-sensitive against lowercased req.headers — Node lowercases names in `req.headers`, so a mixed-case `CALCOM_WEBHOOK_HEADER_NAME` like `X-Webhook-Secret` never matches and every request gets a 403. Lowercase the configured name before indexing `req.headers`.

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

Credential key is overwritten with a SafeParse wrapper instead of parsed data — `parseRefreshTokenResponse` returns a SafeParse wrapper (`{success, data}`), so `key` holds the wrapper and `prisma.credential.update` stores it, corrupting the credential. Use the `.data` of the result as `key`.

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

credentialId passed to refreshOAuthTokens as userId argument — Pass `credential.userId` instead, threading it into `refreshAccessToken`.

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

Schema uses computed keys that become literal strings and reject valid token responses — `[z.string().toString()]` and `[z.string().optional().toString()]` evaluate to literal strings like "ZodString", not wildcards, so the schema demands a property with that name and rejects real token responses when sharing is on. Use `access_token: z.string()` with `.passthrough()` and an explicit expiry check.

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

Sync-mode token refresh returns raw fetch Response instead of expected shape — Returning the raw fetch `Response` in sync mode breaks callers expecting other shapes: Google reads `res.data`, HubSpot reads `.accessToken` and `.expiresIn`, and Zoho CRM and Bigin read `tokenInfo.data`. Parse `response.json()` and return the shape each caller expects. **Also found in:** - `packages/app-store/googlecalendar/lib/CalendarService.ts:86-94`

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

Salesforce token refreshed on every client creation and stale access token used — Every `getClient` call hits the Salesforce token endpoint, bypassing credential sync, and the `jsforce.Connection` receives the stale `credentialKey.access_token`. Refresh only when expired, route it through `refreshOAuthTokens`, and pass `accessTokenParsed.data.access_token`.

mediumbugpackages/app-store/office365calendar/lib/CalendarService.ts:263-264

Invalid token response now throws and loses error logging on refresh — A malformed Microsoft response now rejects the whole refresh and its details go unlogged, whereas before the zod error was logged and execution continued. Wrap `parseRefreshTokenResponse` in a try/catch, or use `safeParse`, and keep the error logging.

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

Webhook secret compared with non-constant-time !== operator — Comparing the webhook secret with `!==` leaks timing information on a network-exposed endpoint. Compare SHA-256 digests with `crypto.timingSafeEqual` and reject non-string header values.

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 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.
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.
highAfter refreshing the Salesforce token, jsforce.Connection is created with the stale access_token and instance_url instead of the newly refreshed values.