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)
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`.
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.
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.
Zoom passes its directory name `zoomvideo` as `appSlug`, while its app and stored credentials use… — Pass `"zoom"` instead.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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`.