Kimi K3.1 Pro · 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
14
Comments matching a bug
6
Comments not matching
8
Cost of this PR
$3.230

Published comments (14)

mediumbugapps/web/pages/api/webhook/app-credential.ts:40-50

Metadata lookup uses app slugs instead of directory names — `appStoreMetadata` is keyed by `dirName` (`googlecalendar`, `zoomvideo`), but this indexes it with the database `slug` (`google-calendar`, `zoom`), so valid sync requests for those apps return 404 before credentials are written. Select `dirName` in the Prisma query and use it for the metadata lookup, or find the metadata entry by `meta.slug`.

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

Two concurrent webhook requests can both observe no credential and both execute `create`… — Make the check-and-create idempotent with serialization or an appropriate uniqueness/upsert strategy.

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

The documented sync payload of an access token plus expiry cannot satisfy Lark's… — Define a common parsed token result and adapt those callers while preserving their existing credential fields.

mediumbugpackages/app-store/zoomvideo/lib/VideoApiAdapter.ts:79-94

Zoom passes its directory name `zoomvideo` as `appSlug`, while its app and stored credentials use… — Pass `"zoom"` instead.

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

The refreshed Salesforce token is written to Prisma, but the new `jsforce.Connection` below still… — Build the connection from `accessTokenParsed.data`, or update `credentialKey` before constructing it.

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

Unconditional token refresh adds a Salesforce request and DB write per client — Every `SalesforceCalendarService` construction now performs a blocking Salesforce token request and a database update before any operation, even when the saved access token is still valid. This adds an external round trip and write to every calendar operation and can consume Salesforce API limits; only refresh when expired or let jsforce refresh on demand.

mediumbugapps/web/pages/api/webhook/app-credential.ts:77-79

Updating credentials preserves the stale invalid flag — Updating only `key` preserves an existing credential's automatically-set `invalid` flag, so a successful webhook delivering repaired credentials still leaves that credential excluded by paths such as `getCalendarsEvents`. Set `invalid: false` when the replacement keys are successfully stored.

mediumbugpackages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:15-18

Provider-fallback team refreshes incorrectly use the sync response schema — The parser chooses the sync schema from global configuration even when `refreshOAuthTokens` took its provider fallback for a team credential (`userId === null`). With sync configured, provider-native team responses therefore bypass app-specific validation and transforms such as Office365's `expires_in` conversion, breaking refreshes; select the schema using the refresh path actually taken or pass an explicit sync-response flag.

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

Webhook secret comparison is vulnerable to timing attacks — The webhook secret is authenticated with a direct string `!==` comparison. String comparison can exit at the first differing character, exposing match-dependent timing on a secret that authorizes creation and replacement of stored app credentials.

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

Computed Zod keys strip token fields during credential sharing — These computed properties do not declare a Zod index signature: `z.string().toString()` and `z.string().optional().toString()` evaluate to ordinary object keys (both normally `[object Object]`, with the second overwriting the first). Consequently, in credential-sharing mode the default `z.object` behavior strips the actual numeric expiry (`expiry_date`/`expires_in`) and other token fields instead of preserving them.

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

Missing refresh tokens are replaced with a hardcoded placeholder — Do not substitute the literal string `"refresh_token"` when a refresh response omits this credential. The sync-endpoint path explicitly permits access-token-only responses, and callers subsequently persist this parsed data; for example, Office365 merges it over the existing credentials, replacing a valid refresh token with the placeholder.

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

The sharing branch always returns a raw `fetch` `Response`, while the fallback returns each… — That contract is incompatible with several changed callers: Google expects a gaxios response with `.data` and then dereferences `token.access_token`, and Zoho Bigin/Zoho CRM expect an Axios response with `.data`; HubSpot treats the result directly as a token object. With syncing enabled, these paths either throw during refresh or persist an empty/invalid token object.

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

Refreshed Google credentials are persisted as a safe-parse wrapper — `parseRefreshTokenResponse` returns the safe-parse result (`{ success, data }`), not the parsed credentials. Persisting `key` directly therefore replaces Google's credential JSON with that wrapper.

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

OAuth refresh passes the credential ID instead of the user ID — The third argument is the helper's `userId`, but this call passes `credentialId` (assigned from `credential.id` at line 53). The sync request consequently sends the credential row ID as `calcomUserId`.

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.