Skip to content

fix(ssh): shell-escape sftp ls path to prevent remote command injection#1581

Merged
chaliy merged 1 commit into
mainfrom
claude/fix-1573-sftp-ls-injection
May 7, 2026
Merged

fix(ssh): shell-escape sftp ls path to prevent remote command injection#1581
chaliy merged 1 commit into
mainfrom
claude/fix-1573-sftp-ls-injection

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented May 7, 2026

Closes #1573.

Summary

The SFTP ls subcommand built its remote command via format!("ls -la {}", path) and passed it to ssh_client.exec. Unlike SCP/SFTP put/get paths, 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

  • Add a small shell_escape helper in cmd.rs (mirrors the one already in russh_handler.rs) and wrap the path with it via a new build_sftp_ls_cmd function.
  • Add a regression test (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 -- --check
  • cargo clippy --all-features --all-targets -- -D warnings

Generated by Claude Code

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
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@chaliy chaliy merged commit e7a6933 into main May 7, 2026
34 checks passed
@chaliy chaliy deleted the claude/fix-1573-sftp-ls-injection branch May 7, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeepSec: SFTP ls path is interpolated into a remote shell command

1 participant