Skip to content

Conversation

@akshayutture-augment
Copy link

…11059)

* Add credential sync .env variables

* Add webhook to send app credentials

* Upsert credentials when webhook called

* Refresh oauth token from a specific endpoint

* Pass appSlug

* Add credential encryption

* Move oauth helps into a folder

* Create parse token response wrapper

* Add OAuth helpers to apps

* Clean up

* Refactor `appDirName` to `appSlug`

* Address feedback

* Change to safe parse

* Remove console.log

---------

Co-authored-by: Syed Ali Shahbaz <[email protected]>
Co-authored-by: Omar López <[email protected]>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@akshayutture-augment
Copy link
Author

@greptileai

@greptile-apps
Copy link

greptile-apps bot commented Nov 14, 2025

Greptile Overview

Confidence Score: 0/5

  • This PR contains multiple critical bugs that will cause runtime failures and security vulnerabilities - NOT safe to merge
  • Score of 0 reflects severe implementation issues: invalid Zod schema syntax will crash on first use, unprotected JSON.parse enables DoS attacks, unreachable authorization logic creates security holes, and hardcoded placeholder values break OAuth flows. These are not edge cases but fundamental errors in core functionality.
  • packages/app-store/_utils/oauth/decodeOAuthState.ts, packages/app-store/_utils/oauth/parseRefreshTokenResponse.ts, and packages/app-store/_utils/oauth/createOAuthAppCredential.ts require immediate fixes before any deployment

Important Files Changed

File Analysis

Filename Score Overview
apps/web/pages/api/webhook/app-credential.ts 1/5 New webhook endpoint for credential sync - missing HTTP method validation and has weak encryption key handling
packages/app-store/_utils/oauth/decodeOAuthState.ts 0/5 Critical: JSON.parse without error handling can crash server on malicious input
packages/app-store/_utils/oauth/parseRefreshTokenResponse.ts 0/5 Critical: Invalid Zod schema syntax will cause runtime errors, hardcoded placeholder value breaks OAuth
packages/app-store/_utils/oauth/createOAuthAppCredential.ts 1/5 Unreachable authorization check for team credentials - admin validation never executes
packages/app-store/_utils/oauth/refreshOAuthTokens.ts 2/5 OAuth token refresh routing logic - external endpoint response lacks validation

Sequence Diagram

sequenceDiagram
    participant User
    participant CalApp as Cal.com App
    participant OAuthProvider as OAuth Provider
    participant WebhookAPI as Webhook API
    participant Database
    participant SyncService as External Sync Service

    Note over User,SyncService: OAuth Integration Flow
    User->>CalApp: Install app integration
    CalApp->>OAuthProvider: Initiate OAuth flow
    OAuthProvider->>User: Request authorization
    User->>OAuthProvider: Approve
    OAuthProvider->>CalApp: Redirect with auth
    CalApp->>OAuthProvider: Exchange for tokens
    OAuthProvider-->>CalApp: Return tokens
    CalApp->>Database: Store credentials

    Note over User,SyncService: Credential Sync (New Feature)
    SyncService->>WebhookAPI: POST encrypted credentials
    WebhookAPI->>WebhookAPI: Verify authentication
    WebhookAPI->>WebhookAPI: Decrypt payload
    WebhookAPI->>Database: Validate user exists
    WebhookAPI->>Database: Create or update credential
    WebhookAPI-->>SyncService: Return status

    Note over User,SyncService: Token Refresh (Modified)
    CalApp->>CalApp: Check token expiration
    alt Sync Enabled
        CalApp->>SyncService: Request refresh
        SyncService-->>CalApp: Return tokens
    else Standard
        CalApp->>OAuthProvider: Request refresh
        OAuthProvider-->>CalApp: Return tokens
    end
    CalApp->>Database: Update credentials
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (2)

  1. packages/app-store/_utils/oauth/decodeOAuthState.ts, line 9 (link)

    logic: JSON.parse without try-catch allows malicious/malformed state parameter to crash server

  2. packages/app-store/_utils/oauth/createOAuthAppCredential.ts, line 59 (link)

    logic: Unreachable code - if state?.teamId exists, function returns on line 56, so this check will never execute for team credentials

40 files reviewed, 7 comments

Edit Code Review Agent Settings | Greptile

keys: z.string(),
});
/** */
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Missing HTTP method validation allows GET/PUT/DELETE requests

Suggested change
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method !== 'POST') {
return res.status(405).json({ message: "Method not allowed" });
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/pages/api/webhook/app-credential.ts
Line: 17:17

Comment:
**logic:** Missing HTTP method validation allows GET/PUT/DELETE requests

```suggestion
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  if (req.method !== 'POST') {
    return res.status(405).json({ message: "Method not allowed" });
  }
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +25 to +27
if (!refreshTokenResponse.data.refresh_token) {
refreshTokenResponse.data.refresh_token = "refresh_token";
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Silently sets placeholder value on missing refresh_token - this will break OAuth flows that require valid refresh tokens

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/app-store/_utils/oauth/parseRefreshTokenResponse.ts
Line: 25:27

Comment:
**logic:** Silently sets placeholder value on missing refresh_token - this will break OAuth flows that require valid refresh tokens

How can I resolve this? If you propose a fix, please make it concise.

const minimumTokenResponseSchema = z.object({
access_token: z.string(),
// Assume that any property with a number is the expiry
[z.string().toString()]: z.number(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Invalid Zod schema - bracket notation with z.string().toString() is not valid Zod syntax and will fail at runtime

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/app-store/_utils/oauth/parseRefreshTokenResponse.ts
Line: 8:8

Comment:
**syntax:** Invalid Zod schema - bracket notation with `z.string().toString()` is not valid Zod syntax and will fail at runtime

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +57 to +59
const keys = JSON.parse(
symmetricDecrypt(reqBody.keys, process.env.CALCOM_APP_CREDENTIAL_ENCRYPTION_KEY || "")
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Empty string fallback for encryption key will cause decryption to silently fail or produce incorrect results

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/pages/api/webhook/app-credential.ts
Line: 57:59

Comment:
**logic:** Empty string fallback for encryption key will cause decryption to silently fail or produce incorrect results

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +8 to +14
const response = await fetch(process.env.CALCOM_CREDENTIAL_SYNC_ENDPOINT, {
method: "POST",
body: new URLSearchParams({
calcomUserId: userId.toString(),
appSlug,
}),
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Response from external sync endpoint is returned without validation or error handling

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/app-store/_utils/oauth/refreshOAuthTokens.ts
Line: 8:14

Comment:
**style:** Response from external sync endpoint is returned without validation or error handling

How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants