Skip to content

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Jan 25, 2026

Summary

Validates that credentials set by the copilot are valid and belong to the user. Also doesn't allow the api key to be set for hosted models if ishosted

Type of Change

  • Bug fix

Testing

Tested with @icecrasher321

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Jan 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 29, 2026 6:42pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 25, 2026

Greptile Overview

Greptile Summary

This PR adds credential and API key validation to the workflow editing tool. The changes introduce a new preValidateCredentialInputs function that validates OAuth credentials before applying operations, and filters out API keys for hosted models. Additionally, the post-validation step now skips oauth-input fields since they are pre-validated.

Key changes:

  • Added preValidateCredentialInputs function that validates credential IDs belong to the user before operations are applied
  • Filters out apiKey inputs for hosted models when isHosted is true
  • Modified validateWorkflowSelectorIds to skip oauth-input validation (line 2513) since credentials are now pre-validated
  • Uses structuredClone to deep copy operations before filtering
  • Credential validation errors are added to the validation errors array and returned to the client

How it works:
The validation now happens in two phases - pre-validation removes invalid credentials and hosted model API keys before applying operations, while post-validation checks other selector types. This prevents invalid credentials from being applied to the workflow state while allowing existing collaborator credentials to remain untouched.

Confidence Score: 4/5

  • This PR is safe to merge with minor attention to error handling
  • The implementation adds important validation logic and follows good patterns - validates credentials early, uses deep cloning, and properly propagates errors. The logic is sound and well-structured. Score is 4 instead of 5 because the PR lacks tests and the structuredClone usage should be verified to work in all target environments (though it's used elsewhere in the codebase).
  • No files require special attention - the server-side changes are the most significant but appear well-implemented

Important Files Changed

Filename Overview
apps/sim/lib/copilot/tools/client/workflow/edit-workflow.ts Minor comment update - removed "just" from comment for clarity
apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts Added credential and apiKey validation with pre-validation function to filter invalid credentials and hosted model apiKeys before applying operations

Sequence Diagram

sequenceDiagram
    participant Client as EditWorkflowClientTool
    participant API as /api/copilot/execute-copilot-server-tool
    participant Server as EditWorkflowServerTool
    participant PreValidate as preValidateCredentialInputs
    participant Validator as validateSelectorIds
    participant Apply as applyOperationsToWorkflowState
    participant PostValidate as validateWorkflowSelectorIds
    
    Client->>API: POST operations, workflowId
    API->>Server: execute(params, context)
    
    Note over Server: Parse currentUserWorkflow or fetch from DB
    
    Server->>PreValidate: validate credentials & apiKeys
    PreValidate->>PreValidate: Collect oauth-input & apiKey fields from operations
    PreValidate->>PreValidate: Filter apiKeys for hosted models
    PreValidate->>Validator: validateSelectorIds('oauth-input', credentialIds)
    Validator->>Validator: Check credentials belong to user
    Validator-->>PreValidate: {valid, invalid, warning}
    PreValidate->>PreValidate: Remove invalid credentials from operations
    PreValidate-->>Server: {filteredOperations, errors}
    
    Server->>Apply: applyOperationsToWorkflowState(workflowState, filteredOperations)
    Apply-->>Server: {modifiedWorkflowState, validationErrors, skippedItems}
    
    Note over Server: Add credential errors to validationErrors
    
    Server->>PostValidate: validateWorkflowSelectorIds(modifiedWorkflowState)
    Note over PostValidate: Skips oauth-input (already validated)
    PostValidate->>Validator: validateSelectorIds(other selector types)
    Validator-->>PostValidate: validation results
    PostValidate-->>Server: selector validation errors
    
    Server-->>API: {workflowState, validationErrors, skippedItems}
    API-->>Client: {workflowState, inputValidationErrors, skippedItems}
    
    Note over Client: Apply diff & mark complete with errors
Loading

Copy link
Contributor

@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.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@icecrasher321
Copy link
Collaborator

@cursor review

@Sg312 Sg312 merged commit 2b026de into staging Jan 29, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/copilot-credential-validator branch January 30, 2026 04:12
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