* Returns a shell command to disable extended glob patterns for security. * Extended globs (bash extglob, zsh EXTENDED_GLOB) can be exploited via * malicious filenames that expand after our security validation. * * When CLAUDE_CODE_SHELL_PREFIX is set, the actual executing shell may differ * fr
(shellPath: string)
| 37 | * When no shell prefix is set, we use the appropriate command for the detected shell. |
| 38 | */ |
| 39 | function getDisableExtglobCommand(shellPath: string): string | null { |
| 40 | // When CLAUDE_CODE_SHELL_PREFIX is set, the wrapper may use a different shell |
| 41 | // than shellPath, so we include both bash and zsh commands |
| 42 | if (process.env.CLAUDE_CODE_SHELL_PREFIX) { |
| 43 | // Redirect both stdout and stderr because zsh's command_not_found_handler |
| 44 | // writes to stdout instead of stderr |
| 45 | return '{ shopt -u extglob || setopt NO_EXTENDED_GLOB; } >/dev/null 2>&1 || true' |
| 46 | } |
| 47 | |
| 48 | // No shell prefix - use shell-specific command |
| 49 | if (shellPath.includes('bash')) { |
| 50 | return 'shopt -u extglob 2>/dev/null || true' |
| 51 | } else if (shellPath.includes('zsh')) { |
| 52 | return 'setopt NO_EXTENDED_GLOB 2>/dev/null || true' |
| 53 | } |
| 54 | // Unknown shell - do nothing, we don't know the right command |
| 55 | return null |
| 56 | } |
| 57 | |
| 58 | export async function createBashShellProvider( |
| 59 | shellPath: string, |