MiniMax M3 · Balanced
oauth-credential-sync-and-app-integration-enhancements-cal-com
cal.com · TypeScript · M · 100–299 lines · 6 files
The normal review, with one generalist agent. Judge: Claude Haiku 5.5.
- Gold bugs found
- 4 of 9
- Comments published
- 9
- Comments matching a bug
- 4
- Comments not matching
- 5
- Cost of this PR
- $0.142
Published comments (9)
parseRefreshTokenResponse schema uses computed keys instead of catchall — Computed keys become literal `'ZodString'` rather than a catch-all, so real provider responses with `refresh_token`/`expiry_date` fail validation and `parseRefreshTokenResponse` throws. Use `z.object({ access_token: z.string() }).catchall(z.number())` so arbitrary keys are accepted.
refreshOAuthTokens returns inconsistent shapes across branches — Sync returns a `Response` while no-sync returns `refreshFunction`'s result, and `CalendarService.ts` consumers read `.data`/`.expiresIn` unconditionally, so toggling `APP_CREDENTIAL_SHARING_ENABLED` crashes refresh for those four integrations. Normalize both branches to the same shape before returning.
Race condition in credential findFirst/update/create webhook handler — Two concurrent webhooks for the same `(userId, appSlug)` can both miss the lookup and race to `create`, producing duplicate or failed rows. Replace `findFirst`/`update`/`create` with a single `prisma.credential.upsert` keyed on the unique `(userId, appId)` constraint.
Webhook secret check misses headers due to missing toLowerCase on key — Node lowercases incoming header keys, so a non-lowercase `CALCOM_WEBHOOK_HEADER_NAME` silently breaks verification and effectively disables the webhook. Normalize the lookup key via `.toLowerCase()` before reading `req.headers`.
Pass user id, not credential id, to refreshOAuthTokens — Passing `credentialId` instead of `credential.userId` causes the admin sync endpoint to receive the credential row's id as `calcomUserId` and resolve the wrong principal (or reject). Pass `credential.userId` to the third argument of `refreshOAuthTokens`.
Salesforce refresh path returns Connection with stale access_token/instance_url — The returned `jsforce.Connection` still reads `accessToken`/`instanceUrl` from the stale `credentialKey`, so `this.conn` resolves to an expired connection while the DB holds fresh tokens. Pass `accessToken: accessTokenParsed.data.access_token` and `instanceUrl: accessTokenParsed.data.instance_url` when constructing the `Connection`.
Refresh token fallback writes literal "refresh_token" instead of previous token — Set the fallback to `response.refresh_token` or omit the override.
Webhook handler must not 500 on invalid JSON body or decryption failure — `safeParse` and `JSON.parse`/`symmetricDecrypt` throw on bad input and bubble up as Next.js 500s instead of structured errors. Switch to `safeParse` returning `res.status(400).json(...)`, and wrap `symmetricDecrypt`/`JSON.parse` to return the same 400 on failure.
Webhook secret compared with !== is vulnerable to timing attacks — `!==` short-circuits on length and the first differing byte, letting attackers recover the secret character-by-character via request latency. Compare equal-length `Buffer`s with `crypto.timingSafeEqual`.