-
Notifications
You must be signed in to change notification settings - Fork 136
Fix PTY provider command hardening follow-ups from PR 938#957
Merged
rabanspiegel merged 2 commits intomain from Feb 19, 2026
Merged
Fix PTY provider command hardening follow-ups from PR 938 #957rabanspiegel merged 2 commits intomain from
rabanspiegel merged 2 commits intomain from
Conversation
Greptile SummaryHardens PTY provider command resolution by replacing subprocess-based path lookup with in-process checks and improving shell escaping for remote SSH execution. Key Changes:
Minor Issues:
Confidence Score: 4/5
|
| 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]
Last reviewed commit: a1addde
There was a problem hiding this 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
src/main/services/ptyIpc.ts
Outdated
fallbackProvider?.cli ||
providerId.toLowerCase()
).trim();
const normalizedCliCommand = cliCommand || fallbackProvider?.cli || providerId.toLowerCase();
There was a problem hiding this comment.
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);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
Summary
Validation
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/wheresubprocess calls by resolving executables in-process (PATH scanning, PATHEXT handling, executability checks), and addsparseCustomCliForDirectSpawnso 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.