GLM-5.3 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 Opus 5.5.
- Gold bugs found
- 9 of 19
- Comments published
- 10
- Comments matching a bug
- 9
- Comments not matching
- 1
- Cost of this PR
- $0.270
Published comments (10)
Sync-mode refresh responses rejected by strict webexRefreshedTokenSchema — Sync-mode responses only carry an access token and expiry, but `webexRefreshedTokenSchema` demands literal `scope`, `token_type`, and `refresh_token` fields, so every webex refresh rejects and no token is ever persisted. Validate the response with `parseRefreshTokenResponse` like the other adapters do.
Credential key stores parseRefreshTokenResponse wrapper instead of parsed token — `parseRefreshTokenResponse` returns the `{ success, data }` safeParse wrapper, so the credential key becomes that wrapper instead of the token, and Google Calendar breaks on the next call after its first refresh. Store `parsedToken.data` as the key, matching the other consumers.
Broken computed keys make token schema strip expiry_date and real refresh_token — The computed keys evaluate to the literal key `[object Object]`, so `z.object` strips `expiry_date` and the real `refresh_token`, and persisting the result wipes the user's stored refresh token. Use a passthrough schema that captures the numeric expiry and never write a placeholder `refresh_token`. **Also found in:** - `packages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:25-27`
refreshOAuthTokens is passed credential id instead of the user id, risking cross-user token sync — Passing `credentialId` as the `userId` argument makes the sync endpoint return another user's OAuth tokens, which would be persisted into this user's credential — a cross-user leak. Pass `credential.userId`, as the other integrations do.
Token refresh success check relies on environment-dependent statusText — `statusText` is empty for HTTP/2 and in runtimes that drop the reason phrase, so a valid 200 response fails this check and the whole refresh rejects. Test `response.ok` (or `response.status === 200`) instead.
Non-atomic find-then-create can create duplicate credentials for same user+app — Concurrent webhooks can both pass `findFirst` and each run `create`, leaving duplicate `Credential` rows — `schema.prisma` has no unique constraint on (`userId`, `appId`). Use a transaction with SELECT ... FOR UPDATE, or add a unique constraint and upsert with a `P2002` fallback.
getClient performs blocking token refresh and DB write on every service construction — `SalesforceCalendarService` is constructed for every calendar operation, including availability checks on booking-page loads, and each construction now pays a blocking refresh POST to Salesforce plus a `prisma.credential.update` even when the stored access token is still valid. Check expiry first and refresh only when needed, as other providers do.
New access token saved but stale token used for jsforce connection — The connection keeps running on the stale `credentialKey.access_token` captured before the refresh, while the fresh token is only written to the database and never used. Pass `accessTokenParsed.data.access_token` to the `jsforce.Connection`.
Sync branch returns raw fetch Response instead of parsed token payload — Callers written for the non-sync shape — Google's `res?.data`, zoho's `tokenInfo.data`, hubspot's token fields — crash or misread the raw fetch Response. Await `response.json()` and return the parsed body so both branches honor the same contract. **Also found in:** - `packages/app-store/googlecalendar/lib/CalendarService.ts:86-96` - `packages/app-store/hubspot/lib/CalendarService.ts:177-191`
Webhook secret compared with non-constant-time !==, leaking it via timing — This endpoint can overwrite any user's OAuth credentials, and the `!==` comparison leaks the secret byte-by-byte through response timing, letting an attacker forge webhook calls. Compare hashed buffers with `crypto.timingSafeEqual` and fail closed when the header is missing.