Predictable temp directory paths in pack management enable symlink attacks (CWE-377)
还没有人认领这个 Issue。
评估
调研方向
从 st2common/st2common/services/packs.py 开始,阅读 temp_backup_action_files、restore_temp_action_files 和 remove_temp_action_files,然后检查 st2common/st2common/util/pack_management.py 中的锁创建。将可预测的临时路径和基于 /tmp 的锁路径替换为安全的处理方式,同时保留 pack 备份、恢复、删除和安装锁定行为。完成的标准是:这些操作不再将可预测的 /tmp 路径暴露给 symlink 或锁文件攻击。
由索引模型根据 Issue 内容生成。
描述
Summary
Pack management functions use hardcoded, predictable paths under /tmp/ with os.mkdir instead of tempfile.mkdtemp. This creates a TOCTOU (time-of-check-time-of-use) race condition where a local attacker can pre-create a symlink at the expected path, causing StackStorm to write pack files to an arbitrary location.
Affected Files
st2common/st2common/services/packs.py
Three functions use predictable temp paths:
# Line 426
def temp_backup_action_files(pack_base_path, metadata_file, entry_point, temp_sub_dir):
temp_dir_path = "/tmp/%s" % temp_sub_dir
os.mkdir(temp_dir_path)
# Line 450
def restore_temp_action_files(pack_base_path, metadata_file, entry_point, temp_sub_dir):
temp_dir_path = "/tmp/%s" % temp_sub_dir
# Line 468
def remove_temp_action_files(temp_sub_dir):
temp_dir_path = "/tmp/%s" % temp_sub_dir
if os.path.isdir(temp_dir_path):
shutil.rmtree(temp_dir_path)
st2common/st2common/util/pack_management.py
# Line 120-123
temp_dir_name = hashlib.md5(
pack_url.encode(), **hashlib_kwargs
).hexdigest()
lock_file = LockFile("/tmp/%s" % (temp_dir_name))
The lock file path is derived from an MD5 hash of the pack URL, which is predictable and not collision-resistant.
Impact
A local attacker with write access to /tmp/ can:
-
Symlink attack on
temp_backup_action_files: Pre-create a symlink at the expected path beforeos.mkdiris called. If the symlink points to a directory the attacker controls, pack files will be written there, potentially leaking sensitive configuration or entry point code. -
Symlink attack on
restore_temp_action_files: Replace the temp directory with a symlink pointing to attacker-controlled content. When StackStorm restores from the "backup," it copies the attacker's files into the pack directory, achieving arbitrary code execution via a malicious entry point. -
Lock file manipulation: The predictable lock file path allows an attacker to pre-create the lock file, causing a denial of service (pack installations hang waiting for the lock), or to delete the lock file to cause concurrent pack installations to race.
Recommended Fix
Use tempfile.mkdtemp for all temporary directories:
import tempfile
# Instead of:
temp_dir_path = "/tmp/%s" % temp_sub_dir
os.mkdir(temp_dir_path)
# Use:
temp_dir_path = tempfile.mkdtemp(prefix="st2_pack_backup_")
For the lock file, use a directory under StackStorm's control (e.g., /opt/stackstorm/locks/) rather than /tmp/.
References
- CWE-377: Insecure Temporary File
- CWE-362: Race Condition (TOCTOU)
- Discovered via manual code review
- 主要语言
- Python
- 星标
- 6.5k
- 派生
- 792
- 平均合并
- 1 天 3 小时
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
StackStorm/st2 的其他 Issue
-
yaml.FullLoader used instead of SafeLoader in pack metadata parsing (CWE-502)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
StackStorm/st2#6393 · 1 条评论 ·
-
Git worktree directories created with chmod 777 (CWE-732)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
StackStorm/st2#6392 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
StackStorm/st2#6389 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
StackStorm/st2#6387 ·
-
CORS middleware reflects Origin with Allow-Credentials, enabling cross-origin attacks (CWE-346)可能已有人在做 @R-zin 于 12 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
StackStorm/st2#6390 ·
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 82/100
EchoTools/nevr-runtime#651 ·
维护者通常 1 天内回复
-
bug frontend rt sev-3
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
noontide-co/mainbranch#1211 · 1 条评论 ·
维护者通常 1 天内回复
-
[1.x Bug] run-operation --sql reports success but rolls back writes on transaction-capable adapters未关闭triage
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复