DeepSeek V4.1 Flash · 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
- 6 of 9
- Comments published
- 10
- Comments matching a bug
- 6
- Comments not matching
- 4
- Cost of this PR
- $0.176
Published comments (10)
App metadata lookup uses public slug instead of metadata key, causing 404 — `appStoreMetadata` is keyed by directory name while `app.slug` holds the public slug, so most apps resolve to `undefined` and return 404, breaking credential sync. Look up the entry by `dirName` (selected alongside `slug`) instead.
Refresh response without refresh_token overwrites stored token with placeholder — When the response omits `refresh_token`, this writes the literal `"refresh_token"` over the stored credential; for Office 365 (optional `refresh_token` in `refreshTokenResponseSchema`) it is persisted and permanently breaks later refreshes with `invalid_grant`. Keep the caller's existing refresh token instead of injecting a placeholder.
Refresh token wrapper stored as credential key breaks Google auth — `parseRefreshTokenResponse` returns the `SafeParseSuccess` wrapper, so storing it as the credential key makes `googleCredentialSchema.parse` fail in `googleAuth` on the next read and breaks Google Calendar after the first refresh. Persist `key.data` instead.
Sync path returns raw fetch Response instead of parsed token JSON — Callers like `googlecalendar`, `hubspot`, `zoho-bigin`, and `zohocrm` expect provider-native token shapes, so returning the raw `Response` makes them no-op, crash, or overwrite the stored credential in shared mode. Return `await response.json()` or normalize each caller.
refreshOAuthTokens receives credentialId instead of owning user id — `refreshOAuthTokens` is passed `credentialId` as its `userId`, so the sync endpoint fetches another user's tokens or none and persists them onto this credential. Pass the credential's `userId` instead.
Connection is built with stale access token after refresh — The `jsforce.Connection` is built right after refresh from the pre-refresh `credentialKey.access_token`, so an expired token still fails despite the fresh one being saved. Use `accessTokenParsed.data.access_token` and the refreshed `instance_url` when constructing it.
Salesforce token refresh validates via statusText instead of response.ok — `statusText` is empty for HTTP/2 and for servers omitting a reason phrase, so a valid 200 response throws `HttpError` and every Salesforce calendar operation fails. Check `response.ok` and read the body for the error message.
Salesforce client creation always refreshes token regardless of expiry — `getClient` runs on every constructor call, so each booking and calendar fetch now triggers a Salesforce token round trip and a `prisma.credential.update` write. Only refresh when the stored token is actually expired.
Webhook secret compared with timing-unsafe string inequality — The strict inequality short-circuits on the first differing byte and leaks the secret prefix through timing on this unauthenticated endpoint. Compare with `crypto.timingSafeEqual` over equal-length buffers after confirming the header is a string.
Race condition can create duplicate app credentials — Without a transaction or a unique constraint on userId+appId, concurrent webhook deliveries both `create`, leaving duplicate credentials where `findFirst` returns an arbitrary stale row. Add a unique constraint and `upsert`, or wrap the check-and-write in a serializable transaction.