Gemini 3.8 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 Haiku 5.5.

Gold bugs found
3 of 9
Comments published
8
Comments matching a bug
3
Comments not matching
5
Cost of this PR
$1.400

Published comments (8)

highbugpackages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:25-27

Hardcoded refresh token dummy string overwrites stored credentials — Merging this result overwrites and permanently corrupts valid OAuth refresh tokens in the database. Remove the fallback assignment so `refresh_token` is omitted when absent.

highbugpackages/app-store/googlecalendar/lib/CalendarService.ts:97-98

Credential key updated with SafeParseReturnType instead of parsed data — Storing the wrapper object in the database corrupts the credential record and breaks subsequent calendar operations. Destructure `data` from `parseRefreshTokenResponse` so only the parsed credential payload is passed to `prisma.credential.update`.

highbugpackages/app-store/zoho-bigin/lib/CalendarService.ts:92-94

refreshOAuthTokens receives credential ID instead of user ID — Passing a credential record ID prevents the sync endpoint from locating the Cal.com user. Pass `credential.userId` to `refreshOAuthTokens` instead of `credentialId`.

highbugpackages/app-store/_utils/oauth/refreshOAuthTokens.ts:8-16

Raw fetch Response returned instead of response data expected by callers — Returning a raw `Response` lacks the `.data` property expected by callers, causing unhandled `TypeError` exceptions when accessing tokens. Parse the response body with `await response.json()` before returning it.

highsecurityapps/web/pages/api/webhook/app-credential.ts:24-27

Header lookup fails if CALCOM_WEBHOOK_HEADER_NAME has uppercase characters — Node normalizes incoming header names to lowercase, causing lookup failures if `CALCOM_WEBHOOK_HEADER_NAME` contains uppercase characters. Call `.toLowerCase()` on the header key before indexing `req.headers`.

mediumsecurityapps/web/pages/api/webhook/app-credential.ts:57-59

Insecure fallback to empty string for encryption key — Decrypting with an empty string compromises security when the environment variable is unset. Reject the request early if `process.env.CALCOM_APP_CREDENTIAL_ENCRYPTION_KEY` is missing instead of falling back to `""`.

mediumbugpackages/app-store/_utils/oauth/parseRefreshTokenResponse.ts:5-11

Invalid `[z.string().toString()]` key in Zod schema strips response properties — Evaluating `toString()` creates a static `"[object Object]"` key, causing Zod to strip token expiry fields from the response. Chain `.passthrough()` onto `minimumTokenResponseSchema` instead of defining computed schema keys.

mediumsecurityapps/web/pages/api/webhook/app-credential.ts:24-29

Timing attack vulnerability in webhook secret comparison — Comparing secrets with `!==` leaks timing information that allows attackers to guess the secret token. Use `crypto.timingSafeEqual` for a constant-time comparison instead.

Gold bugs found (3)

highparseRefreshTokenResponse writes the hardcoded string 'refresh_token' when the refresh response omits a refresh token, so the stored credential gets an invalid refresh token and later refreshes fail.
mediumminimumTokenResponseSchema uses computed keys from z.string().toString(), which produce a literal key rather than a wildcard, so the sync-mode schema does not validate or keep expiry and other token fields as intended.
highGoogle Calendar persists the safeParse result object instead of its data as the credential key, corrupting the stored credential so later reads fail.

Gold bugs missed (6)

mediumThe webhook parses the body with zod .parse and decrypts/JSON-parses the keys without error handling, so invalid payloads produce 500 errors instead of 400 responses.
mediumSalesforce getClient now refreshes the OAuth token and writes the credential on every service construction, adding a network round trip and DB write even when the access token is valid.
highThe new Salesforce token refresh uses prisma without importing it, so the code fails type checking and throws a ReferenceError at runtime.
highSalesforce checks response.statusText !== 'OK' instead of response.ok when refreshing the token, which can misclassify successful responses, and then ignores the refreshed token.
highAfter refreshing the Salesforce token, jsforce.Connection is created with the stale access_token and instance_url instead of the newly refreshed values.
highThe app-credential webhook looks up appStoreMetadata by app.slug, but the map is keyed by dirName, so apps whose slug differs from their directory (e.g. google-calendar) always get a 404 and their credentials cannot be synced.