Claude Sonnet 5.5 · 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
- 3 of 9
- Comments published
- 7
- Comments matching a bug
- 3
- Comments not matching
- 4
- Cost of this PR
- $0.923
Published comments (7)
Safe-parse result stored as credential key instead of parsed data — Saving the whole safe-parse result makes the stored key `{ success, data }`, so later `googleCredentialSchema.parse(credential.key)` fails and the credential breaks. Store `parseRefreshTokenResponse(...).data` as `key`.
Sync-mode refreshOAuthTokens returns raw Response instead of token data — Callers read `res.data` or `.accessToken`/`.expiresIn`, which are undefined on a `Response`, so Google's TypeError is swallowed and Hubspot computes a NaN expiry. Parse the JSON in `refreshOAuthTokens` and adapt it to each caller's shape, or have callers call `response.json()`.
Credential id passed as userId to refreshOAuthTokens — The sync endpoint receives a credential id as `calcomUserId`, so it refreshes tokens for the wrong user or none. Pass `credential.userId` through `biginAuth` and `refreshAccessToken` instead of `credentialId`.
Salesforce token refresh bypasses refreshOAuthTokens and credential sync — Calling Salesforce directly bypasses `refreshOAuthTokens`, so for synced credentials `parseRefreshTokenResponse` can store the placeholder refresh token, Salesforce rejects it, and no connection is created. Wrap the fetch in `refreshOAuthTokens(..., "salesforce", credential.userId)` and skip the local refresh when synced.
Salesforce connection built with stale access token after refresh — The fresh token is saved, but the `jsforce.Connection` still uses the old `credentialKey.access_token`, so calls can fail with an expired session. Use `accessTokenParsed.data.access_token` and its instance URL, and route the refresh through `refreshOAuthTokens`.
Salesforce token refresh and DB write run on every service instantiation — `getClient` runs in the constructor, so every instantiation adds a blocking token refresh and a DB write, risking Salesforce rate limits. Refresh only when the stored token is expired or a call fails with an auth error.
Webhook secret compared with non-constant-time !== operator — Comparing with `!==` leaks timing information, letting an attacker recover the secret and overwrite any user's app credentials. Use `crypto.timingSafeEqual` on equal-length buffers and handle a missing header value explicitly.