Repository navigation
fix(terminal): keep the cwd one argument in external_terminal_cmd - #607
Conversation
…uments `external.open` pastes `vim.fn.getcwd()` into a two-`%s` `external_terminal_cmd` with `string.format` and then splits the whole string. These specs run folder names with spaces, quotes, backslashes, shell syntax and `%s` through `alacritty --working-directory %s -e %s` and `alacritty --working-directory=%s -e %s`, and expect the cwd to stay one argument. A folder named `demo -e sh -c 'touch PWNED' x` now becomes extra alacritty arguments, so 14 of these specs fail. A cwd `%s` inside a larger argument (`sh -c 'cd %s && ...'`) is expected to be refused, which fails too. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Signed-off-by: Thomas Kosiewski <[email protected]>
With two `%s` placeholders, `external.open` pasted `vim.fn.getcwd()` into the template with `string.format` and then split the whole string with `utils.parse_command`. A folder named `demo -e sh -c 'touch PWNED' x` became extra terminal arguments, so `alacritty --working-directory %s -e %s` ran `sh -c 'touch PWNED'` (CWE-88), and a folder with a space split into two arguments. Format a marker in place of the cwd, split, then put the cwd into the one argument that holds the marker. That argument must be the marker alone or `--option=` and the marker. Anywhere else, such as in `sh -c 'cd %s && ...'`, the program that gets the argument would parse the folder name, so the template is refused with one ERROR notification. A function covers that form. The one-placeholder path and the command slot are unchanged. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_ Signed-off-by: Thomas Kosiewski <[email protected]>
|
@codex review |
|
@codex security review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
PASS+NOTES at c2e8616 I'm an independent verifier and did not write this PR. I ran real Neovim 0.12.3 headless (
These are the folder names I used: plain names, a space, a tab, On base the attack reproduces. With the attack folder, Notes:
Generated with |
Only the file hash of lua/claudecode/terminal/external.lua changed. It holds no covered block or call site and cannot reach diff state, an openDiff answer, a disconnect or a diff command. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_ Signed-off-by: Thomas Kosiewski <[email protected]>
Why
With
terminal.provider = "external"and the documented two-%stemplate ("alacritty --working-directory %s -e %s"),external.openpastedvim.fn.getcwd()into the template and then split the whole string withutils.parse_command. A folder name from a cloned repo or archive was parsed as arguments: a folder nameddemo -e sh -c 'touch PWNED' xmade the terminal runsh -c 'touch PWNED'(CWE-88). A folder with a space also broke the launch.What changed
external.openformats a marker in place of the cwd, splits, and only then puts the cwd into the one argument that holds the marker. The cwd reachesjobstartas one argument, byte-equal togetcwd().%s, quoted or not) or--option=%s. Anywhere else, such assh -c 'cd %s && ...', the template is refused with one ERROR notification, because the program that gets that argument would parse the folder name again. A function covers that form.lua/claudecode/terminal/README.mdstate the rule.Scope
Only the two-
%sstring template. The one-%stemplate, the command slot, the function form and the other providers behave as before.Tradeoffs
sh -c '...'template, the folderx;touch${IFS}PWNED;:still ran.gnome-terminal -e '%s'from one argument into several words.Blast Radius
A two-
%stemplate with the cwd inside a larger argument now refuses to launch, with an error that names the fix.Verification
external_specspecs pass on the fix.:cdinto 9 crafted folders times 3 templates, then:ClaudeCode, with a stub terminal that logs its argv and runs what follows-e. main: the attacker's command ran 5 times, and 17 launches had a wrong argv or did not start. This branch: 0 attacker runs, 18 correct launches, 9 refused (thesh -ctemplate).mise run allpasses.Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:high