fix(security): replace /tmp/pua-plugin-root TOCTOU race with CLAUDE_PLUGIN_ROOT#155
Open
xiaolai wants to merge 1 commit intotanweai:mainfrom
Open
fix(security): replace /tmp/pua-plugin-root TOCTOU race with CLAUDE_PLUGIN_ROOT#155xiaolai wants to merge 1 commit intotanweai:mainfrom
xiaolai wants to merge 1 commit intotanweai:mainfrom
Conversation
…_ROOT
The hook wrote the plugin root path to /tmp/pua-plugin-root and later
instructed Claude to read it back with $(cat /tmp/pua-plugin-root). On a
shared or multi-user system, an attacker with write access to /tmp/ could
overwrite that file between the write (line 60) and the exec (line 105),
redirecting Claude to run an arbitrary script.
Replace the temp file lookup with ${CLAUDE_PLUGIN_ROOT:-<glob fallback>},
which is already the authoritative env var used by hooks.json. This
eliminates the TOCTOU window entirely.
Co-Authored-By: Claude Code <noreply@anthropic.com>
This was referenced Apr 26, 2026
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.
Security Issue (Medium)
hooks/stop-feedback.shcontains a TOCTOU (time-of-check/time-of-use) race condition in the plugin root path lookup.The vulnerable pattern:
On a shared or multi-user system, an attacker with write access to
/tmp/can overwrite/tmp/pua-plugin-rootbetween the write and the exec, redirecting Claude to run an arbitrary script. The window is small but real — Claude has to process the hook output and present a question before executing the bash block, giving an attacker several seconds.Fix
Replace the temp file with
${CLAUDE_PLUGIN_ROOT}, the authoritative env var thathooks.jsonalready uses:bash "${CLAUDE_PLUGIN_ROOT:-$(ls -td ~/.claude/plugins/cache/pua-skills/pua/*/ | head -1)}/hooks/sanitize-session.sh" ...This reads the plugin root directly from the process environment at exec time — no writable file involved, no race window. The
lsfallback preserves behaviour in environments whereCLAUDE_PLUGIN_ROOTis not set.The dead code that computed
_PLUGIN_ROOTand wrote it to the temp file is also removed.