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