fix(ssh): shell-escape sftp ls path to prevent remote command injection#1581
Merged
Conversation
Previously, the SFTP ls command path was interpolated raw into a remote
shell command via format!("ls -la {}", path). A path containing shell
metacharacters (;, |, &, $(...), `...`) was interpreted by the remote
shell on the allowlisted SSH target, bypassing the SFTP command subset.
Quote the path with the existing single-quote shell_escape helper and
add a regression test covering metacharacter inputs.
Closes #1573
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 92f6ee9 | Commit Preview URL Branch Preview URL |
May 07 2026, 03:56 AM |
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.
Closes #1573.
Summary
The SFTP
lssubcommand built its remote command viaformat!("ls -la {}", path)and passed it tossh_client.exec. Unlike SCP/SFTPput/getpaths, this path was not shell-escaped, so a path containing shell metacharacters (;,|,&,$(),`...`) was interpreted by the remote shell on the allowlisted SSH target — bypassing the SFTP command subset and executing arbitrary commands with the configured credentials.Fix
shell_escapehelper incmd.rs(mirrors the one already inrussh_handler.rs) and wrap the path with it via a newbuild_sftp_ls_cmdfunction.test_sftp_ls_quotes_metacharacters) verifying that;,$(),`, and embedded single quotes are all single-quoted.Test plan
cargo test -p bashkit --features ssh --lib builtins::ssh::cmd::tests(5/5 passing, including the new test)cargo fmt --all -- --checkcargo clippy --all-features --all-targets -- -D warningsGenerated by Claude Code