google-gemini/gemini-cli
hasPromptCommandTransform compares node.type to '@' instead of node.text, failing to detect bash @P transform
Summary
Context: The
hasPromptCommandTransformfunction inpackages/core/src/utils/shell-utils.tsis part of the shell command security validation system that detects dangerous bash parameter expansion patterns before executing shell commands.Bug: The function checks
operatorNode?.type === '@'instead ofoperatorNode?.text === '@', causing it to never detect the bash@Pprompt transformation operator.Actual vs. expected: The function currently compares the tree-sitter node’s grammar rule type (e.g., “expansion”, “operator”) against the literal string
'@', when it should compare the node’s text content to detect the actual@character in the source code.Impact: This bug allows dangerous bash prompt transformation commands like
echo ${var@P}to bypass security checks, potentially enabling command injection attacks through carefully crafted prompt expansion exploits.
Code with bug
Logical proof
Tree-sitter nodes expose two relevant properties:
node.typeis the grammar rule name (e.g., “operator”, “expansion”).node.textis the literal source text (e.g., “@”, “P”).
For a parameter expansion like ${foo@P}, the node representing @ has type = "operator" (or similar) and text = "@". Comparing operatorNode.type === '@' will always be false, so hasPromptCommandTransform never flags @P. Switching to operatorNode.text === '@' correctly detects the operator and allows the function to block such commands as intended.
Recommended fix
Replace the comparison of the operator node from using type to using text:
with: