fix: validate $ARGUMENTS path before shell interpolation in optimize command#197
Open
xiaolai wants to merge 1 commit intoccplugins:mainfrom
Open
fix: validate $ARGUMENTS path before shell interpolation in optimize command#197xiaolai wants to merge 1 commit intoccplugins:mainfrom
xiaolai wants to merge 1 commit intoccplugins:mainfrom
Conversation
…command The pre-context shell commands `du -h $ARGUMENTS` and `wc -l $ARGUMENTS` interpolated raw user input directly into shell, enabling injection via the !` execution mechanism (e.g. a value like `"; rm -rf ~"`). Add a `[[ "$ARGUMENTS" =~ ^[a-zA-Z0-9_./-]+$ ]]` guard before each command and quote the variable, so only safe file path characters are accepted. Co-Authored-By: Claude Code <noreply@anthropic.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.
Security Bug (Medium)
plugins/optimize/commands/optimize.mdlines 6–7 use the!(pre-context shell execution) mechanism to gather file metadata:$ARGUMENTSis interpolated unquoted and unvalidated directly into shell commands. A user passing a crafted value such as"; rm -rf ~"or$(malicious-command)would have it executed during context-building — before Claude is even invoked.Note: the
allowed-tools: Bash(du:*), Bash(wc:*)restriction applies to the Bash tool used during Claude's turn, not to the!pre-context execution which happens at prompt-build time. The injection surface is the!backtick mechanism.Fix
Add a
[[ "$ARGUMENTS" =~ ^[a-zA-Z0-9_./-]+$ ]]guard before each command and quote the variable:This allows safe file paths (letters, digits,
_,.,/,-) and rejects anything with shell metacharacters. The behavior for legitimate file path arguments is unchanged.