Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix PTY provider command hardening follow-ups from PR 938#957

Merged
rabanspiegel merged 2 commits intomain from
emdash/938-67l
Feb 19, 2026
Merged

Fix PTY provider command hardening follow-ups from PR 938 #957
rabanspiegel merged 2 commits intomain from
emdash/938-67l

Conversation

@rabanspiegel
Copy link
Contributor

@rabanspiegel rabanspiegel commented Feb 19, 2026
edited by cursor bot
Loading

Summary

  • harden remote provider invocation quoting by using shared POSIX shell escaping and tokenized command assembly
  • prevent Windows custom CLI paths from being incorrectly treated as shell expressions in direct spawn
  • replace sync command path resolution subprocess usage with in-process path/executable checks and keep caching
  • add regression tests for remote CLI metachar quoting and Windows absolute custom CLI parsing

Validation

  • pnpm run format
  • pnpm exec vitest run src/test/main/ptyManager.test.ts src/test/main/ptyIpc.test.ts
  • pnpm run type-check

Note

Medium Risk
Touches PTY spawn and remote command construction, where subtle quoting/path resolution changes could break provider startup across platforms; mitigated by added regression tests.

Overview
Hardens remote provider execution by switching to shared POSIX escaping (quoteShellArg) and assembling the remote provider command as tokenized parts before joining, preventing shell metachar expansion/injection and ensuring consistent quoting.

Updates direct-spawn command resolution to avoid which/where subprocess calls by resolving executables in-process (PATH scanning, PATHEXT handling, executability checks), and adds parseCustomCliForDirectSpawn so Windows absolute/UNC custom CLI paths aren’t misclassified as shell expressions. Adds/updates tests covering remote quoting behavior and Windows custom CLI parsing.

Written by Cursor Bugbot for commit fc5dfe2. This will update automatically on new commits. Configure here.

greptile-apps[bot] reacted with thumbs up emoji
Copy link

vercel bot commented Feb 19, 2026
edited
Loading

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

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Feb 19, 2026 5:18am

Request Review

Copy link

greptile-apps bot commented Feb 19, 2026

Greptile Summary

Hardens PTY provider command resolution by replacing subprocess-based path lookup with in-process checks and improving shell escaping for remote SSH execution.

Key Changes:

  • Moved quoteShellArg to shared utility and applied it consistently to all remote command tokens, preventing shell metacharacter injection in custom CLI strings
  • Replaced which/where subprocess calls with in-process PATH resolution using fs.statSync and fs.accessSync, maintaining result caching
  • Added parseCustomCliForDirectSpawn to handle Windows absolute paths (including quoted paths with spaces) correctly, preventing them from being misclassified as shell expressions
  • Removed backslash from needsShellResolution regex so Windows paths like C:\Tools\tool.exe can use direct spawn instead of shell mode
  • Extended tests to verify metacharacter quoting and Windows path parsing edge cases

Minor Issues:

  • Line 198 in ptyIpc.ts contains redundant fallback logic that duplicates the fallback chain from lines 193-197

Confidence Score: 4/5

  • This PR is safe to merge with low risk, implementing security-focused improvements with comprehensive test coverage
  • The changes improve security by hardening shell escaping and removing subprocess dependencies, with regression tests covering edge cases. Minor style issue with redundant fallback logic doesn't affect correctness. The removal of backslash from shell resolution regex and new Windows path parsing are well-tested and intentional improvements.
  • No files require special attention

Important Files Changed

Filename Overview
src/main/services/ptyIpc.ts Refactored remote provider invocation to use tokenized command assembly with proper shell quoting, moved quoteShellArg to shared utility. Minor redundancy in normalizedCliCommand fallback logic.
src/main/services/ptyManager.ts Replaced subprocess-based command resolution with in-process PATH checks and caching, added Windows-specific CLI parsing to handle absolute paths correctly, removed backslash from shell resolution regex to support Windows paths.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
 A[Start: Resolve Provider Command] --> B{Custom CLI configured?}
 B -->|Yes| C{Platform Check}
 B -->|No| D[Use Default Provider CLI]
 
 C -->|Windows| E[parseCustomCliForDirectSpawn]
 C -->|Unix| F[parseShellArgs]
 
 E --> G{Is Windows absolute/UNC path?}
 G -->|Yes, no spaces| H[Return as single token]
 G -->|Yes, quoted with spaces| I[Strip quotes, return path]
 G -->|No| F
 
 F --> J[Parse as shell args]
 J --> K{Multiple tokens?}
 K -->|Yes| L[Fallback to shell mode]
 K -->|No| M[Single executable token]
 
 M --> N{Needs shell resolution?}
 N -->|Has metacharacters| L
 N -->|No metacharacters| O[Resolve executable path]
 
 O --> P{Path-like or in PATH?}
 P -->|Path-like| Q[Resolve as absolute path]
 P -->|In PATH| R[Search PATH dirs]
 
 Q --> S{Is executable file?}
 R --> S
 S -->|Yes| T[Cache and return path]
 S -->|No| U[Return null, fallback]
 
 D --> V[Build remote command]
 H --> V
 I --> V
 T --> V
 L --> W[Shell spawn mode]
 U --> W
 
 V --> X[Quote all tokens with quoteShellArg]
 X --> Y[Join with spaces]
 Y --> Z[Execute via SSH or direct spawn]
Loading

Last reviewed commit: a1addde

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.

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

fallbackProvider?.cli ||
providerId.toLowerCase()
).trim();
const normalizedCliCommand = cliCommand || fallbackProvider?.cli || providerId.toLowerCase();
Copy link

@greptile-apps greptile-apps bot Feb 19, 2026

Choose a reason for hiding this comment

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

redundant fallback chain since cliCommand already contains these same fallbacks from line 193-197

Suggested change
const normalizedCliCommand = cliCommand||fallbackProvider?.cli||providerId.toLowerCase();
const parsedCliParts = parseShellArgs(cliCommand);

@rabanspiegel rabanspiegel merged commit 7c69595 into main Feb 19, 2026
4 checks passed
@rabanspiegel rabanspiegel deleted the emdash/938-67l branch February 19, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@greptile-apps greptile-apps[bot] greptile-apps[bot] left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

Comments

AltStyle によって変換されたページ (->オリジナル) /