DeepSeek V4.1 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 Haiku 5.5.

Gold bugs found
6 of 9
Comments published
11
Comments matching a bug
6
Comments not matching
5
Cost of this PR
$0.358

Published comments (11)

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

Webhook looks up app metadata by slug but map is keyed by dirName — For every app whose `dirName` differs from its `slug`, the lookup returns undefined and the webhook answers 404, so credential sync silently fails for the main OAuth apps. Resolve the metadata by scanning entries for `meta.slug === app.slug`, as `getAppWithMetadata` in packages/app-store/_appRegistry.ts does, or look the app up by `dirName`.

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

Salesforce connection uses stale access token after refresh — The fresh token is persisted and then discarded, so the exchange can never fix an expired token and the stored credential is rotated without effect. Build the connection from `accessTokenParsed.data.access_token` and its `instance_url`, or drop the refresh and let jsforce handle it.

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

Webhook findFirst overwrites wrong credential for multi-account users — For a user with two Google or Outlook accounts, the arbitrary first row is overwritten with the synced account's keys, corrupting the other account while the intended one is never updated. The payload carries no credential identity, so the webhook needs an external credential identifier instead of `findFirst`.

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

Credential sync never clears the invalid flag on synced credentials — A credential previously marked broken stays excluded from `getCalendarsEvents`, which filters `!credential.invalid`, even after valid credentials are pushed, so sync can never recover the user's app. Set `invalid: false` in both the `update` and the `create`.

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

Shared-credential branch returns raw fetch Response without a .data property — Callers still read `res?.data`, so this branch yields undefined and throws a TypeError or silently returns expired credentials in Google's try/catch. Parse the body with `await response.json()` and return an object with a `data` property.

highbugpackages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:21-29

parseRefreshTokenResponse returns safeParse envelope instead of token data — Google's refresh path assigns the envelope straight to `credential.key`, so the stored value becomes `{ success: true, data: {...} }` and every later `googleCredentialSchema.parse` fails. Return `refreshTokenResponse.data` so the persisted value keeps the expected shape. **Also found in:** - `packages/app-store/googlecalendar/lib/CalendarService.ts:97-100`

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

refreshOAuthTokens receives credential id instead of user id — When credential sync is enabled, the endpoint receives a credential id where it expects a cal.com user id and refreshes the wrong user's credential. Pass the credential's `userId` like the other callers do.

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

Computed Zod keys collide, stripping refresh_token from token responses — Both computed keys resolve to "[object Object]", so the schema has no expiry or catch-all rule and Zod strips `refresh_token`; line 25 then substitutes the literal placeholder, which callers persist and permanently destroy the real refresh token. Declare the schema explicitly and only fall back to a placeholder when the provider genuinely returns no refresh token.

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

Placeholder refresh_token overwrites the real stored credential when missing — Zoom and office365calendar persist this literal string, so the real refresh token is overwritten and every later refresh fails with `invalid_grant`, forcing a reinstall. Leave the existing refresh token untouched instead of substituting a dummy string.

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

Salesforce OAuth refresh runs on every service instantiation — `getClient` runs from the `SalesforceCalendarService` constructor, so every booking and availability operation pays a synchronous OAuth round trip to login.salesforce.com even when the stored token is still valid. Check the `credentialKey` expiry before exchanging, or refresh lazily on a 401.

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

Webhook secret compared with non-constant-time equality — The `!==` comparison short-circuits on the first differing byte, so response timing leaks how many leading characters of `CALCOM_WEBHOOK_SECRET` were guessed, letting an attacker recover it and inject credentials. Compare with `crypto.timingSafeEqual` over fixed-length buffers, after normalizing a `string[]` header to one string.

Gold bugs found (6)

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

Gold bugs missed (3)

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.