Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

added session context checks in copilot tool calls for added security, to ensure user's have an authenticated context before the copilot executes tools on their behalf

Type of Change

  • Other: Security

Testing

Manually.

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 Sep 27, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 27, 2025 1:14am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 27, 2025 1:14am

@vercel vercel bot temporarily deployed to Preview – docs September 27, 2025 01:07 Inactive
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.

Greptile Overview

Summary

This PR strengthens security by adding session context checks to copilot tool calls, ensuring users are authenticated before tools execute on their behalf.

Key improvements:

  • Added verifyWorkflowAccess() function with comprehensive permission checking for workflow ownership and workspace access
  • Modified all user-related server tools (get-environment-variables, set-environment-variables, get-oauth-credentials) to require authenticated user context
  • Enhanced the tool execution pipeline to pass userId from authenticated sessions through to individual tools
  • Implemented proper error handling with descriptive permission error messages
  • Replaced direct getUserId() calls with authenticated context verification

Security enhancements:

  • Tools now verify user authentication before accessing sensitive data like environment variables and OAuth credentials
  • Workflow access is properly validated against database ownership and workspace permissions
  • Prevents unauthorized tool execution by requiring active authenticated sessions

Confidence Score: 5/5

  • This PR is safe to merge with no security risks
  • The implementation follows security best practices with proper authentication, authorization checks, comprehensive error handling, and no breaking changes to existing functionality
  • No files require special attention

Important Files Changed

File Analysis

Filename        Score        Overview
apps/sim/lib/copilot/auth/permissions.ts 5/5 Added comprehensive workflow access verification with proper permission checks and error handling
apps/sim/app/api/copilot/execute-copilot-server-tool/route.ts 5/5 Enhanced to pass authenticated userId context to tool execution for security
apps/sim/lib/copilot/tools/server/user/get-environment-variables.ts 5/5 Added authentication checks and workflow access verification before accessing environment variables
apps/sim/lib/copilot/tools/server/user/set-environment-variables.ts 5/5 Implemented authentication and workflow access controls before allowing environment variable modifications
apps/sim/lib/copilot/tools/server/user/get-oauth-credentials.ts 5/5 Added session context validation and workflow access verification for OAuth credential access
apps/sim/lib/copilot/tools/server/base-tool.ts 5/5 Updated interface to include optional userId context parameter for authentication
apps/sim/lib/copilot/tools/server/router.ts 5/5 Enhanced to accept and forward userId context to individual tools for authentication

Sequence Diagram

sequenceDiagram
    participant C as Copilot Client
    participant A as API Endpoint
    participant R as Tool Router
    participant T as Server Tool
    participant P as Permissions
    participant D as Database

    C->>A: Execute tool request
    A->>A: Authenticate session
    
    alt Authentication fails
        A-->>C: Unauthorized error
    else Authentication succeeds
        A->>R: Route execution with user context
        R->>T: Execute tool with context
        
        alt Workflow access required
            T->>P: Verify workflow access
            P->>D: Check permissions
            D-->>P: Return access data
            P-->>T: Return access result
            
            alt Access denied
                T-->>A: Permission error
                A-->>C: Forbidden response
            else Access granted
                T->>T: Process tool execution
                T-->>R: Return result
                R-->>A: Forward result
                A-->>C: Success response
            end
        else No workflow check needed
            T->>T: Process tool execution
            T-->>R: Return result
            R-->>A: Forward result
            A-->>C: Success response
        end
    end
Loading

18 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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.

2 participants