fix(bundle2-W5-5): desktop_driver AppleScript 注入加固 + macOS platform gate#44
Merged
Conversation
W5 sprint 收官项。对 2 个 macOS 自动化函数加三层 gate (env + platform + identifier 白名单):
- open_macos_app: subprocess `open -a {name}` — name 用户控可启任意 app
- macos_menu: subprocess `osascript -e {f-string}` — app_name/menu/item 用户控
历史上存在 AppleScript 注入 (引号逃逸 + `do shell script`)
加固:
- 新 env var TAGENT_DESKTOP_AUTHORIZED=1 (语义独立, 不复用 PENTEST)
- platform 必须 darwin, 非 macOS 自动 refuse
- AppleScript identifier 白名单 ^[A-Za-z][A-Za-z0-9 _.\-]{0,127}$
- 模块 docstring 加"安全约束 (W5-5 加固)"节
实测 (本地 Windows, 7/7 全过):
- env off → 2 ops 全 RuntimeError "TAGENT_DESKTOP_AUTHORIZED"
- env on + non-darwin → RuntimeError "macOS-only"
- 注入字符串 'Safari"; do shell script "rm -rf /' → ValueError
- 合法 idents ('Safari' / 'Sub Menu' / 'New-Tab.1') 通过
- _require_macos 单调 raise 验证
不在范围 (排队 task #6):
- get_windows_app exe_path / launch_electron executable_path 路径校验
(续点档限 macOS / AppleScript, 跨平台路径校验顺路记)
SECURITY.md 武器化表不更新 (desktop_driver 不属攻击工具是测试 driver),
与 "测试工具 gate 总览" 节同档延后批量加。
约束: utils 独立于 runtime, 用 env var gate 不用 runtime.config.safety。
Wool-xing
added a commit
that referenced
this pull request
May 13, 2026
W5 sprint 完结后阶段 3 文档兜底: SECURITY.md 加新节, 列全 3 个非武器化 但有 gate 的 utils (chaos / db_test / desktop), 与"武器化代码使用边界" 区分。说明授权范围 + 与生产环境隔离责任的关系。 PR 引用: chaos_helper #37 / db_test_helper #41 / desktop_driver #44。 范式: env gate + opt-in kwarg + platform gate + 输入白名单 (5 PR 沉淀)。 灵感库已私域同步范式总结 (D:\项目文件\灵感库\工程模式\ utils-env-var-gate-pattern-v2.md, 不入仓)。 Co-authored-by: xiaoxing0135 <706015750@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
范围
W5 sprint 收官项 (Phase 1 / Bundle 2):
05-代码示例/desktop_driver.py2 个 macOS 自动化函数加三层 gate。复用 W5-2 范式 v2 + 新加 platform 第三层 gate。动机 — AppleScript 注入面 (静态可验)
PoC:
app_name = 'X"\ndo shell script "rm -rf ~/Documents"\ntell process "X'即可注入 shell 命令。改了什么
1. 模块 docstring 加"安全约束 (W5-5)"节
显式说明三层 gate + 授权边界 (macOS 测试机自有)。
2. 新加模块级 gate (3 道工具)
GATE_ENV_VAR = "TAGENT_DESKTOP_AUTHORIZED"(新 env, 语义独立非 pentest)_require_authorized(op)— env 守卫_require_macos(op)— platform 守卫 (sys.platform != 'darwin' → raise)_validate_as_identifier(name, kind)— AppleScript identifier 白名单正则
^[A-Za-z][A-Za-z0-9 _.\-]{0,127}$3. 2 个 macOS op 加守
open_macos_appmacos_menu不在范围
get_windows_app(Windows pywinauto, 续点档未列) — 顺路 task deps(deps): bump the database group across 1 directory with 3 updates #6launch_electron(跨平台 playwright, 续点档未列) — 顺路 task deps(deps): bump the database group across 1 directory with 3 updates #6collect_proc_perf/save_perf/screenshot(无 offensive 面)main()仅暴露 perf/screenshot 子命令, 未暴露 macos_* — 不动 CLI本地测试 (7/7 全过, Windows 平台)
注: macOS 平台实跑 osascript 留给 CI / 用户验证 (sprint 在 Windows)。
协作宪章 §1.3 六道闸自检 (按 PR #42 f1-f6 标准)
All checks passed+ pre-commit (markdownlint skip 无 .md 改动)runtime/orchestrator/adapters/experts.py调 CLIcollect-perf子命令,03-技能定义/desktop-test.mdL48 osascript 示例非函数引用 — 全不经过我修的 2 ops置信度自检 (f5)
git diff --stat对外承诺仅基于 H, M/L 已加修饰。
假阳性过滤 (f6)
唯一 finding = "macos_menu / open_macos_app AppleScript / 任意 app 启动注入面":
假阳性候选数: 0 | 降置信 finding 数: 0
W5 Sprint 整体进度 (本 PR 合后)
W5 五项加固 sprint 完结 (合后)。下一阶段建议: 批量加 SECURITY.md "测试工具 gate 总览" 节 (含 W5-1/3/5 三个非武器化但有 gate 的 utils), + 灵感库批量入"utils env-var gate 范式 v2" + 顺路 task #3/#6 三方共决。