Claude Sonnet 5.5 · 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
- 10
- Comments matching a bug
- 5
- Comments not matching
- 5
- Cost of this PR
- $2.703
Published comments (10)
Placeholder refresh_token applied outside credential sync mode — Overwriting a valid stored refresh token with a placeholder breaks later refreshes for callers like Zoom, which copy `newTokens.refresh_token` into the credential. Apply the `"refresh_token"` default only in sync mode, and otherwise keep the existing stored token.
App metadata looked up by slug but appStoreMetadata is keyed by directory name — For apps whose slug differs from the directory name, such as Google Calendar and Zoom, the lookup returns undefined and the webhook returns 404, so their credentials never sync. `appStoreMetadata` is keyed by directory name, so find the entry in `Object.values(appStoreMetadata)` whose `slug` matches `app.slug`.
Webhook header name lookup is case-sensitive against lowercased req.headers — Node lowercases names in `req.headers`, so a mixed-case `CALCOM_WEBHOOK_HEADER_NAME` like `X-Webhook-Secret` never matches and every request gets a 403. Lowercase the configured name before indexing `req.headers`.
Credential key is overwritten with a SafeParse wrapper instead of parsed data — `parseRefreshTokenResponse` returns a SafeParse wrapper (`{success, data}`), so `key` holds the wrapper and `prisma.credential.update` stores it, corrupting the credential. Use the `.data` of the result as `key`.
credentialId passed to refreshOAuthTokens as userId argument — Pass `credential.userId` instead, threading it into `refreshAccessToken`.
Schema uses computed keys that become literal strings and reject valid token responses — `[z.string().toString()]` and `[z.string().optional().toString()]` evaluate to literal strings like "ZodString", not wildcards, so the schema demands a property with that name and rejects real token responses when sharing is on. Use `access_token: z.string()` with `.passthrough()` and an explicit expiry check.
Sync-mode token refresh returns raw fetch Response instead of expected shape — Returning the raw fetch `Response` in sync mode breaks callers expecting other shapes: Google reads `res.data`, HubSpot reads `.accessToken` and `.expiresIn`, and Zoho CRM and Bigin read `tokenInfo.data`. Parse `response.json()` and return the shape each caller expects. **Also found in:** - `packages/app-store/googlecalendar/lib/CalendarService.ts:86-94`
Salesforce token refreshed on every client creation and stale access token used — Every `getClient` call hits the Salesforce token endpoint, bypassing credential sync, and the `jsforce.Connection` receives the stale `credentialKey.access_token`. Refresh only when expired, route it through `refreshOAuthTokens`, and pass `accessTokenParsed.data.access_token`.
Invalid token response now throws and loses error logging on refresh — A malformed Microsoft response now rejects the whole refresh and its details go unlogged, whereas before the zod error was logged and execution continued. Wrap `parseRefreshTokenResponse` in a try/catch, or use `safeParse`, and keep the error logging.
Webhook secret compared with non-constant-time !== operator — Comparing the webhook secret with `!==` leaks timing information on a network-exposed endpoint. Compare SHA-256 digests with `crypto.timingSafeEqual` and reject non-string header values.