Skip to content

Security: Potential Command Injection in Process Execution#1637

Open
tomaioo wants to merge 1 commit into
runhey:masterfrom
tomaioo:fix/security/potential-command-injection-in-process-e
Open

Security: Potential Command Injection in Process Execution#1637
tomaioo wants to merge 1 commit into
runhey:masterfrom
tomaioo:fix/security/potential-command-injection-in-process-e

Conversation

@tomaioo

@tomaioo tomaioo commented Jun 24, 2026

Copy link
Copy Markdown

Summary

Security: Potential Command Injection in Process Execution

Problem

Severity: High | File: deploy/process.py:L56

The execute method in ProcessManager constructs and executes shell commands using string formatting with external inputs. While the specific execute implementation is not fully shown, the pattern of building command strings with f'taskkill /f /pid {row[2]}' and similar constructs in pip_install with user-configurable mirrors suggests potential for command injection if inputs are not properly sanitized.

Solution

Use subprocess with argument lists instead of string formatting for shell commands. Validate and sanitize all inputs that are incorporated into commands. Consider using subprocess.run with a list of arguments rather than shell=True to prevent injection attacks.

Changes

  • deploy/process.py (modified)

Summary by Sourcery

Bug Fixes:

  • 在进程终止逻辑中调用 taskkill 时,使用参数列表执行方式,而不是格式化后的 shell 命令。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Use argument list execution instead of formatted shell command when invoking taskkill in process termination logic.

Summary by CodeRabbit

  • Bug Fixes
    • 优化了进程终止命令的执行方式,提升了命令传参的稳定性与一致性。
    • 仍可按目标进程 ID 强制结束进程,行为保持不变。

The `execute` method in ProcessManager constructs and executes shell commands using string formatting with external inputs. While the specific `execute` implementation is not fully shown, the pattern of building command strings with `f'taskkill /f /pid {row[2]}'` and similar constructs in `pip_install` with user-configurable mirrors suggests potential for command injection if inputs are not properly sanitized.

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

@sourcery-ai sourcery-ai Bot 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.

Hey - 我在这里给出了一些高层面的反馈:

  • 既然 execute 现在可以接收参数列表,需要确保它的实现能够一致地区分列表和字符串,并且避免调用 shell(例如设置 shell=False),这样可以防止未来的调用方无意间重新引入命令注入风险。
  • 可以考虑将这里使用的“参数列表”模式应用到其它构造命令的地方(例如 pip_install 或类似的辅助函数),以保持整个模块的进程执行行为一致,同时降低整体的安全风险。
面向 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- Now that `execute` can receive a list of arguments, ensure its implementation consistently detects lists vs strings and avoids invoking a shell (e.g., `shell=False`) so that future callers don't accidentally reintroduce command injection risks.
- Consider applying the same argument-list pattern used here to other places where commands are constructed (such as `pip_install` or similar helpers) to keep process execution behavior consistent and reduce security risk across the module.

Sourcery 对开源项目免费——如果你喜欢我们的评审,请考虑分享给他人 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • Now that execute can receive a list of arguments, ensure its implementation consistently detects lists vs strings and avoids invoking a shell (e.g., shell=False) so that future callers don't accidentally reintroduce command injection risks.
  • Consider applying the same argument-list pattern used here to other places where commands are constructed (such as pip_install or similar helpers) to keep process execution behavior consistent and reduce security risk across the module.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Now that `execute` can receive a list of arguments, ensure its implementation consistently detects lists vs strings and avoids invoking a shell (e.g., `shell=False`) so that future callers don't accidentally reintroduce command injection risks.
- Consider applying the same argument-list pattern used here to other places where commands are constructed (such as `pip_install` or similar helpers) to keep process execution behavior consistent and reduce security risk across the module.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

deploy/process.pykill_by_name 方法中,调用 self.execute 时的 taskkill 命令从 f-string 拼接字符串 taskkill /f /pid {row[2]} 改为参数列表 ['taskkill', '/f', '/pid', str(row[2])],同时将 PID 显式转换为字符串类型。allow_failure=Trueoutput=False 参数保持不变,仅修改命令组装方式。

Poem

🐇 小兔敲键盘,命令列表更整齐,
字符串拼接已成昨日烟,
['taskkill', '/f', '/pid'] 排成行,
PID 显式转型不含糊,
进程终止稳稳当当真好哇! 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@deploy/process.py`:
- Line 61: The `DeployConfig.execute` contract is broken because it still treats
`command` as a string and calls `command.replace(...)`, so the new `taskkill`
list argument from `execute` will crash at runtime. Update
`DeployConfig.execute` to accept argv-style lists as well as strings, detect the
list case, and invoke `subprocess.run(..., shell=False)` for list commands while
preserving existing `allow_failure` and `output` behavior. Make sure the fix is
applied in `execute` and works with the `taskkill` call site in the process
cleanup flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4292a949-ac5d-4b00-8fe4-af257cc5cd80

📥 Commits

Reviewing files that changed from the base of the PR and between fea7221 and 1ea658c.

📒 Files selected for processing (1)
  • deploy/process.py

Comment thread deploy/process.py
for row in self.iter_process_by_name(name):
logger.info(' '.join(map(str, row)))
self.execute(f'taskkill /f /pid {row[2]}', allow_failure=True, output=False)
self.execute(['taskkill', '/f', '/pid', str(row[2])], allow_failure=True, output=False)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

execute 调用契约被破坏,会在运行时崩溃(Line 61)

这里传入 list,但 DeployConfig.execute 仍按 str 处理并调用 command.replace(...),命中该分支会直接抛异常并中断安装流程。请同步改造 execute 以支持 argv 列表并使用 subprocess.run(..., shell=False),否则此修改不可用。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@deploy/process.py` at line 61, The `DeployConfig.execute` contract is broken
because it still treats `command` as a string and calls `command.replace(...)`,
so the new `taskkill` list argument from `execute` will crash at runtime. Update
`DeployConfig.execute` to accept argv-style lists as well as strings, detect the
list case, and invoke `subprocess.run(..., shell=False)` for list commands while
preserving existing `allow_failure` and `output` behavior. Make sure the fix is
applied in `execute` and works with the `taskkill` call site in the process
cleanup flow.

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.

1 participant