Skip to content

Conversation

@jgranesa
Copy link

@jgranesa jgranesa commented Jan 9, 2026

Summary

Brief description of what this PR does and why.

Fixes #(issue)

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

How has this been tested? What should reviewers focus on?

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)

Screenshots/Videos

@vercel
Copy link

vercel bot commented Jan 9, 2026

@jgranesa is attempting to deploy a commit to the Sim Team on Vercel.

A member of the Team first needs to authorize it.

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

Greptile Summary

Summary

This PR adds a new command execution feature to the Sim application, allowing workflows to execute bash commands through a new block and tool. The implementation includes:

  • New API Route: /api/tools/command/exec/route.ts - Handles command execution with timeout and shell configuration
  • Block Definition: command.ts - Provides the UI block for users to configure command execution
  • Tool Configuration: tools/command/ - Defines the tool interface and types
  • Registry Updates: Both block and tool registries updated to include the new command executor

Issues Found

Critical Security Issues

  1. Missing Authentication: The API route lacks authentication checks. Other tool routes in the codebase use getSession() to verify user identity before executing operations. Command execution is a sensitive operation that must be restricted to authenticated users only.

  2. Missing Input Validation: The workingDirectory and shell parameters are not validated:

    • workingDirectory could contain path traversal sequences
    • shell parameter accepts any arbitrary value instead of being restricted to a whitelist
    • The codebase has established validation patterns using validatePathSegment() from /lib/core/security/input-validation that should be used here

Code Quality Issues

  1. Inconsistent Logging: Uses console.error instead of the createLogger pattern used throughout the codebase. Global standards require using @sim/logger.

  2. Missing Output Schema: The tool configuration in chat.ts doesn't define the outputs field, which other similar tools include for documentation and type safety.

Positive Aspects

  • Block definition is well-structured with proper subBlocks, parameters, and I/O definitions
  • Type definitions are clear with good JSDoc documentation
  • Proper integration with block and tool registries
  • Correct use of lucide-react icons consistent with other blocks
  • Good timeout and signal handling logic (SIGTERM → SIGKILL fallback)

Recommendations

  • Add authentication check using getSession()
  • Validate workingDirectory with validatePathSegment() and allowDots: true
  • Add whitelist validation for shell parameter
  • Replace console.error with structured logging using createLogger
  • Add outputs schema definition to tool configuration

Confidence Score: 2/5

  • This PR introduces critical security vulnerabilities that must be fixed before merging. The command execution endpoint lacks authentication and input validation, creating significant risk.
  • The low confidence score reflects two critical security issues: (1) Missing authentication allows unauthenticated users to execute arbitrary commands on the server, and (2) Lack of input validation on shell and working directory parameters could enable injection attacks or path traversal. These are not best-practice issues but actual security vulnerabilities that would allow attackers to execute arbitrary code. The route handling and block definitions are otherwise well-implemented, but the security gaps overshadow this. Additional code quality issues (logging, missing output schema) are secondary to the critical security problems.
  • The primary file requiring attention is apps/sim/app/api/tools/command/exec/route.ts, which must be updated with: (1) authentication check via getSession(), (2) input validation for workingDirectory and shell parameters, and (3) proper logging using createLogger. The apps/sim/tools/command/chat.ts file should have output schema added for consistency with similar tools.

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/app/api/tools/command/exec/route.ts 2/5 API route for command execution with multiple critical issues: missing authentication check, inconsistent logging (console.error instead of logger), and no input validation on workingDirectory and shell parameters. Spawns shell processes with user input which requires proper validation. Missing environment variable sanitization and error handling consistency.
apps/sim/tools/command/chat.ts 3/5 Tool configuration for command execution is mostly correct but missing outputs definition. Tool config follows patterns from other tools (request, params, body functions) but lacks the outputs schema that describes the response structure.
apps/sim/blocks/blocks/command.ts 4/5 Block definition is well-structured with proper subBlocks, tool config, and I/O definitions. Uses lucide-react Terminal icon which is consistent with other blocks. Parameter transformation in tool config correctly converts timeout to number. No issues found.

Sequence Diagram

sequenceDiagram
    participant User as User/Workflow
    participant Block as Command Block
    participant Tool as Tool Config
    participant API as /api/tools/command/exec
    participant Executor as Shell Executor
    participant Process as Child Process

    User->>Block: Configure command parameters
    Block->>Tool: Transform and prepare request
    Tool->>API: POST request with command, workingDirectory, shell, timeout
    Note over API: ⚠️ Missing: Authentication check
    Note over API: ⚠️ Missing: Input validation
    API->>Executor: executeCommand(command, cwd, timeout, shell)
    Executor->>Process: spawn(shell, ["-c", command])
    Process-->>Executor: stdout/stderr data
    Executor->>Executor: Set timeout handler (SIGTERM → SIGKILL)
    Process-->>Executor: close event with exit code
    Executor-->>API: ExecutionResult (stdout, stderr, exitCode, timedOut)
    API-->>Tool: NextResponse.json(CommandOutput)
    Tool-->>Block: Response data
    Block-->>User: Display results
Loading

jgranesa and others added 5 commits January 9, 2026 14:03
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
add authentication check using session

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@jgranesa jgranesa changed the title add commandline executor block feat(block): add command line executor block Jan 10, 2026
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.

1 participant