Skip to content

feat(cua): prevent press key command injection - #251

Merged
yinchengfeng-bytedance merged 1 commit into
volcengine:mainfrom
helenyang88:fix/computer-use-presskey-security-pr
Jul 23, 2026
Merged

yinchengfeng-bytedance merged 1 commit into
volcengine:mainfrom
helenyang88:fix/computer-use-presskey-security-pr

Conversation

@helenyang88

@helenyang88 helenyang88 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

背景

tool_serverPressKey 接口此前将请求参数 Key 拼接为 shell 命令,并通过 create_subprocess_shell() 执行;同时,auth_key 为空时会跳过鉴权。

该组合可能导致未授权调用及命令注入风险。

变更

  • 强制要求配置非空 auth_key

    • 服务启动时空值会直接失败。
    • 鉴权中间件不再因空配置放行请求。
    • 支持通过 AUTH_KEY 环境变量注入密钥。
  • 修复 PressKey 命令注入:

    • 使用 asyncio.create_subprocess_exec() 参数化调用 xdotool
    • 用户输入不再进入 shell。
    • Key 仅允许 KEYS 中定义的按键、单个字母/数字及合法组合键。
    • 支持如 ctrl+calt+tab 等组合键。
    • 非法 Key 返回 HTTP 400。
  • 保留错误处理:

    • xdotool 不存在时返回错误结果。
    • 子进程超时时终止子进程并抛出超时错误。
  • 更新配置和文档说明,明确 auth_key 必须配置。

验证

  • uv run python tests/test_presskey_security.py
    • 6 个安全回归测试通过。
  • uv run python tests/test_startup_security.py
    • 2 个启动鉴权测试通过。
  • AUTH_KEY=configured-secret uv run python -m compileall -q common middleware services tools main.py
    • 编译检查通过。
  • 验证 AUTH_KEY 配置可通过启动校验,空 auth_key 会被拒绝。

@helenyang88 helenyang88 changed the title fix(demohouse/computer_use): prevent press key command injection feat(cua): prevent press key command injection Jul 23, 2026
@helenyang88

Copy link
Copy Markdown
Contributor Author

麻烦帮忙 approve and run workflows,感谢。

@helenyang88
helenyang88 force-pushed the fix/computer-use-presskey-security-pr branch from aefbd62 to 47aca59 Compare July 23, 2026 08:12
@yinchengfeng-bytedance
yinchengfeng-bytedance merged commit b2db209 into volcengine:main Jul 23, 2026
3 checks passed
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.

2 participants