Skip to content

fix: use mktemp to prevent /tmp race condition in install.sh#3

Merged
ythx-101 merged 1 commit intoythx-101:masterfrom
philo-veritas:fix/install-tmp-race-condition
Mar 14, 2026
Merged

fix: use mktemp to prevent /tmp race condition in install.sh#3
ythx-101 merged 1 commit intoythx-101:masterfrom
philo-veritas:fix/install-tmp-race-condition

Conversation

@philo-veritas
Copy link
Copy Markdown
Contributor

问题

install.sh 使用固定路径 /tmp/ask-search-wrapper 作为临时文件,存在 TOCTOU(time-of-check-time-of-use)竞态条件。攻击者可在写入和 install 之间通过 symlink 替换文件内容,将恶意脚本安装到 /usr/local/bin/

修复

将固定 /tmp/ask-search-wrapper 替换为 mktemp 生成的随机临时文件,消除 symlink attack 向量。

改动

-echo "$WRAPPER" > /tmp/ask-search-wrapper
-install -m 755 /tmp/ask-search-wrapper "$INSTALL_BIN/ask-search"
-rm -f /tmp/ask-search-wrapper
+TMPFILE=$(mktemp)
+echo "$WRAPPER" > "$TMPFILE"
+install -m 755 "$TMPFILE" "$INSTALL_BIN/ask-search"
+rm -f "$TMPFILE"

Replace hardcoded /tmp/ask-search-wrapper with mktemp to eliminate
TOCTOU (time-of-check-time-of-use) symlink attack vector during
installation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ythx-101 ythx-101 merged commit bc1647c into ythx-101:master Mar 14, 2026
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