Predictable temp directory paths in pack management enable symlink attacks (CWE-377)
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
調査の方向性
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時間
- マージ済み PR(30日)
- 4
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
StackStorm/st2 のほかの issue
-
yaml.FullLoader used instead of SafeLoader in pack metadata parsing (CWE-502)対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
StackStorm/st2#6393 · コメント 1 件 ·
-
Git worktree directories created with chmod 777 (CWE-732)対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 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 が 9 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
StackStorm/st2#6390 ·
似ている issue
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
openwisp/openwisp-utils#777 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
google-research/weatherbenchX#310 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
huggingface/peft#3955 ·
メンテナーはふだん 1 日以内に返信
-
author-page correction
難易度 2/5 1〜3時間 初心者へのやさしさ 60/100
acl-org/acl-anthology#10313 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
AOSSIE-Org/Gitcord-GithubDiscordBot#147 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信