Skip to content

fix(security): 2 improvements across 1 files#315

Open
tomaioo wants to merge 1 commit into
awslabs:mainfrom
tomaioo:fix/security/command-injection-via-unsanitized-termin
Open

fix(security): 2 improvements across 1 files#315
tomaioo wants to merge 1 commit into
awslabs:mainfrom
tomaioo:fix/security/command-injection-via-unsanitized-termin

Conversation

@tomaioo

@tomaioo tomaioo commented Jun 18, 2026

Copy link
Copy Markdown

Summary

fix(security): 2 improvements across 1 files

Problem

Severity: High | File: src/cli_agent_orchestrator/cli/commands/terminal.py:L28

The restore() function in terminal.py constructs a shell command string using unsanitized user input (terminal_id) and passes it to get_backend().create_window() with window_shell. While the terminal_id is used to construct file paths, the window_shell parameter contains terminal_id interpolated into a shell command: f"cat '{scrollback_path}'; exec {login_shell} -l". The scrollback_path is derived from TERMINAL_LOG_DIR / f"{terminal_id}.scrollback". If terminal_id contains shell metacharacters, this could lead to command injection. More critically, the create_window method likely passes this to tmux's send-keys or new-window with shell execution, creating a command injection vector.

Solution

Sanitize terminal_id using a strict whitelist (e.g., alphanumeric only) before using it in file paths or shell commands. Use shlex.quote() for any values embedded in shell commands. Consider validating that terminal_id matches expected format before proceeding.

Changes

  • src/cli_agent_orchestrator/cli/commands/terminal.py (modified)

- Security: Command Injection via Unsanitized Terminal ID in restore()
- Security: Path Traversal via Terminal ID in restore()

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 the terminal restore CLI command against command-injection by validating terminal_id and properly shell-quoting values embedded in the window_shell command passed to the backend.

Changes:

  • Add a strict allowlist check for terminal_id before using it in paths/commands.
  • Use shlex.quote() when composing window_shell (scrollback path and login shell).

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

Comment on lines +29 to +32
if not re.fullmatch(r"[A-Za-z0-9_-]+", terminal_id):
raise click.ClickException(
f"Invalid terminal_id '{terminal_id}'. Only alphanumeric, underscore, and hyphen characters are allowed."
)
@@ -57,9 +64,9 @@ def restore(terminal_id: str):
login_shell = os.environ.get("SHELL", "bash")
Comment on lines +29 to +32
if not re.fullmatch(r"[A-Za-z0-9_-]+", terminal_id):
raise click.ClickException(
f"Invalid terminal_id '{terminal_id}'. Only alphanumeric, underscore, and hyphen characters are allowed."
)
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