Skip to content

Commit decc233

Browse files
committed
Remove unused code
1 parent 0c481a3 commit decc233

File tree

2 files changed

+0
-126
lines changed

2 files changed

+0
-126
lines changed

webview-ui/src/utils/__tests__/command-validation.spec.ts

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
getSingleCommandDecision,
1212
CommandValidator,
1313
createCommandValidator,
14-
containsSubshell,
1514
} from "../command-validation"
1615

1716
describe("Command Validation", () => {
@@ -43,66 +42,6 @@ describe("Command Validation", () => {
4342
expect(parseCommand("diff <(sort f1) <(sort f2)")).toEqual(["diff", "sort f1", "sort f2"])
4443
})
4544

46-
it("detects additional subshell patterns", () => {
47-
// Test $[] arithmetic expansion detection
48-
expect(parseCommand("echo $[1 + 2]")).toEqual(["echo $[1 + 2]"])
49-
50-
// Verify containsSubshell detects all subshell patterns
51-
expect(containsSubshell("echo $[1 + 2]")).toBe(true) // $[] arithmetic expansion
52-
expect(containsSubshell("echo $((1 + 2))")).toBe(true) // $(()) arithmetic expansion
53-
expect(containsSubshell("echo $(date)")).toBe(true) // $() command substitution
54-
expect(containsSubshell("echo `date`")).toBe(true) // backtick substitution
55-
expect(containsSubshell("diff <(sort f1) <(sort f2)")).toBe(true) // process substitution
56-
expect(containsSubshell("echo hello")).toBe(false) // no subshells
57-
})
58-
59-
it("detects subshell grouping patterns", () => {
60-
// Basic subshell grouping with shell operators
61-
expect(containsSubshell("(ls; rm file)")).toBe(true)
62-
expect(containsSubshell("(cd /tmp && rm -rf *)")).toBe(true)
63-
expect(containsSubshell("(command1 || command2)")).toBe(true)
64-
expect(containsSubshell("(ls | grep test)")).toBe(true)
65-
expect(containsSubshell("(sleep 10 & echo done)")).toBe(true)
66-
67-
// Nested subshells
68-
expect(containsSubshell("(cd /tmp && (rm -rf * || echo failed))")).toBe(true)
69-
70-
// Multiple operators in subshell
71-
expect(containsSubshell("(cmd1; cmd2 && cmd3 | cmd4)")).toBe(true)
72-
73-
// Subshell with spaces
74-
expect(containsSubshell("( ls ; rm file )")).toBe(true)
75-
})
76-
77-
it("does NOT detect legitimate parentheses usage", () => {
78-
// Function calls should not be flagged as subshells
79-
expect(containsSubshell("myfunction(arg1, arg2)")).toBe(false)
80-
expect(containsSubshell("func( arg1, arg2 )")).toBe(false)
81-
82-
// Simple parentheses without operators
83-
expect(containsSubshell("(simple text)")).toBe(false)
84-
85-
// Parentheses in strings
86-
expect(containsSubshell('echo "this (has) parentheses"')).toBe(false)
87-
88-
// Empty parentheses
89-
expect(containsSubshell("()")).toBe(false)
90-
})
91-
92-
it("handles mixed subshell patterns", () => {
93-
// Mixed subshell types
94-
expect(containsSubshell("(echo $(date); rm file)")).toBe(true)
95-
96-
// Subshell with command substitution
97-
expect(containsSubshell("(ls `pwd`; echo done)")).toBe(true)
98-
99-
// No subshells
100-
expect(containsSubshell("echo hello world")).toBe(false)
101-
102-
// Empty string
103-
expect(containsSubshell("")).toBe(false)
104-
})
105-
10645
it("handles empty and whitespace input", () => {
10746
expect(parseCommand("")).toEqual([])
10847
expect(parseCommand(" ")).toEqual([])
@@ -899,7 +838,6 @@ describe("Unified Command Decision Functions", () => {
899838

900839
expect(details.decision).toBe("auto_approve")
901840
expect(details.subCommands).toEqual(["npm install", "echo done"])
902-
expect(details.hasSubshells).toBe(false)
903841
expect(details.allowedMatches).toHaveLength(2)
904842
expect(details.deniedMatches).toHaveLength(2)
905843

@@ -912,12 +850,10 @@ describe("Unified Command Decision Functions", () => {
912850

913851
it("detects subshells correctly", () => {
914852
const details = validator.getValidationDetails("npm install $(echo test)")
915-
expect(details.hasSubshells).toBe(true)
916853
expect(details.decision).toBe("auto_approve") // all commands are allowed
917854

918855
// Test with denied prefix in subshell
919856
const detailsWithDenied = validator.getValidationDetails("npm install $(npm test)")
920-
expect(detailsWithDenied.hasSubshells).toBe(true)
921857
expect(detailsWithDenied.decision).toBe("auto_deny") // npm test is denied
922858
})
923859

webview-ui/src/utils/command-validation.ts

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -58,65 +58,6 @@ type ShellToken = string | { op: string } | { command: string }
5858
* This allows users to have personal defaults while projects can define specific restrictions.
5959
*/
6060

61-
/**
62-
* Detect subshell usage and command substitution patterns that could be security risks.
63-
*
64-
* Subshells allow executing commands in isolated environments and can be used to bypass
65-
* command validation by hiding dangerous commands inside substitution patterns.
66-
*
67-
* Detected patterns:
68-
* - $() - command substitution: executes command and substitutes output
69-
* - `` - backticks (legacy command substitution): same as $() but older syntax
70-
* - <() - process substitution (input): creates temporary file descriptor for command output
71-
* - >() - process substitution (output): creates temporary file descriptor for command input
72-
* - $(()) - arithmetic expansion: evaluates mathematical expressions (can contain commands)
73-
* - $[] - arithmetic expansion (alternative syntax): same as $(()) but older syntax
74-
* - (cmd1; cmd2) - subshell grouping: executes multiple commands in isolated subshell
75-
*
76-
* @param source - The command string to analyze for subshell patterns
77-
* @returns true if any subshell patterns are detected, false otherwise
78-
*
79-
* @example
80-
* ```typescript
81-
* // Command substitution - executes 'date' and substitutes its output
82-
* containsSubshell("echo $(date)") // true
83-
*
84-
* // Backtick substitution - legacy syntax for command substitution
85-
* containsSubshell("echo `date`") // true
86-
*
87-
* // Process substitution - creates file descriptor for command output
88-
* containsSubshell("diff <(sort f1)") // true
89-
*
90-
* // Arithmetic expansion - can contain command execution
91-
* containsSubshell("echo $((1+2))") // true
92-
* containsSubshell("echo $[1+2]") // true
93-
*
94-
* // Subshell grouping - executes commands in isolated environment
95-
* containsSubshell("(ls; rm file)") // true
96-
* containsSubshell("(cd /tmp && rm -rf *)") // true
97-
*
98-
* // Safe patterns that should NOT be flagged
99-
* containsSubshell("func(arg1, arg2)") // false - function call, not subshell
100-
* containsSubshell("echo hello") // false - no subshell patterns
101-
* containsSubshell("(simple text)") // false - no shell operators in parentheses
102-
* ```
103-
*/
104-
export function containsSubshell(source: string): boolean {
105-
// Check for command substitution, process substitution, and arithmetic expansion patterns
106-
// These patterns allow executing commands and substituting their output, which can bypass validation
107-
const commandSubstitutionPatterns = /(\$\()|`|(<\(|>\()|(\$\(\()|(\$\[)/.test(source)
108-
109-
// Check for subshell grouping: parentheses containing shell command operators
110-
// Pattern explanation: \( = literal opening paren, [^)]* = any chars except closing paren,
111-
// [;&|]+ = one or more shell operators (semicolon, ampersand, pipe), [^)]* = any chars except closing paren, \) = literal closing paren
112-
// This detects dangerous patterns like: (cmd1; cmd2), (cmd1 && cmd2), (cmd1 || cmd2), (cmd1 | cmd2), (cmd1 & cmd2)
113-
// But avoids false positives like function calls: func(arg1, arg2) - no shell operators inside
114-
const subshellGroupingPattern = /\([^)]*[;&|]+[^)]*\)/.test(source)
115-
116-
// Return true if any subshell pattern is detected
117-
return commandSubstitutionPatterns || subshellGroupingPattern
118-
}
119-
12061
/**
12162
* Split a command string into individual sub-commands by
12263
* chaining operators (&&, ||, ;, |, or &) and newlines.
@@ -681,10 +622,8 @@ export class CommandValidator {
681622
subCommands: string[]
682623
allowedMatches: Array<{ command: string; match: string | null }>
683624
deniedMatches: Array<{ command: string; match: string | null }>
684-
hasSubshells: boolean
685625
} {
686626
const subCommands = parseCommand(command)
687-
const hasSubshells = containsSubshell(command)
688627

689628
const allowedMatches = subCommands.map((cmd) => ({
690629
command: cmd,
@@ -701,7 +640,6 @@ export class CommandValidator {
701640
subCommands,
702641
allowedMatches,
703642
deniedMatches,
704-
hasSubshells,
705643
}
706644
}
707645

0 commit comments

Comments
 (0)