GPT-6.1 Sol · 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
- 9
- Comments matching a bug
- 5
- Comments not matching
- 4
- Cost of this PR
- $3.498
Published comments (9)
Fabricated refresh token overwrites the stored Office 365 refresh token — A successful Office 365 response can omit `refresh_token`, so fabricating it destroys a valid stored token. Leave `refreshTokenResponse.data.refresh_token` absent when no replacement is returned, preserving the stored token during merging.
Salesforce token refresh uses an unimported Prisma client — Successful Salesforce refreshes can throw `ReferenceError` in production because `packages/prisma/index.ts` initializes the global `prisma` only outside production. Import `prisma` explicitly from `@calcom/prisma` before updating the credential.
Sync refresh returns a Response where callers expect provider token objects — With synchronization enabled, callers of `refreshOAuthTokens` expecting `res.data.access_token`, `response.data.error`, or `HubspotToken` receive an unparsed `Response`, causing refresh failures or undefined token fields. Normalize the sync result and update consumers to a consistent contract while preserving support for fetch-based callers.
Token refresh persists the parse result instead of credential data — Writing the `parseRefreshTokenResponse` result directly stores a wrapper without top-level tokens, so the next `googleCredentialSchema.parse` fails even with sharing disabled. Check `success`, handle parsing failures, and assign `.data` to `key` before persisting.
OAuth refresh passes a credential ID instead of the owning user ID — Sync requests can target the wrong user because `refreshOAuthTokens` sends its third argument as `calcomUserId`, but `credentialId` comes from `credential.id`. Pass the owning `credential.userId` instead, using `null` for team-owned credentials so the helper falls back to normal refresh.
Concurrent first deliveries can create duplicate app credentials — Simultaneous deliveries can both reach `prisma.credential.create` and insert duplicate user/app credentials; check the `Credential` model for the missing uniqueness constraint. Serialize lookup and creation per user/app pair, or add a matching unique key and atomic upsert.
Salesforce initialization always refreshes tokens but uses the stale token — Each initialization incurs an OAuth request and database write even for valid tokens, yet the connection still uses the original `credentialKey.access_token`. Refresh only when necessary and initialize the connection with the refreshed token.
Webhook secret comparison leaks timing information — Direct equality against `CALCOM_WEBHOOK_SECRET` can expose secret information through timing differences on this credential-writing endpoint. Validate that the supplied header is a single string, then compare fixed-length cryptographic digests with `timingSafeEqual`.
Token response schema uses literal keys and strips additional properties — Ordinary token responses miss the documented handling because `[z.string().toString()]` and `[z.string().optional().toString()]` create literal property names, while `z.object` strips additional fields. Explicitly validate supported expiry fields and preserve additional token properties as required by the contract.