Bug: preToolUse askAgent hook allows command execution bypass of trusted commands list
Before opening, please confirm:
- [x] I have searched for duplicate or closed issues
Operating System
Windows 10
Kiro Version
Current (pre-1.107 update)
Bug Description
Hook involved:
enforce-powershell-execution-rules.kiro.hook
{
"enabled": true,
"name": "Enforce PowerShell Execution Rules",
"when": {
"type": "preToolUse",
"toolTypes": ["shell"]
},
"then": {
"type": "askAgent",
"prompt": "BLOCK if command starts with: powershell, pwsh, '& .', '. .', or contains ';'. BLOCK if controlPwshProcess action=start and a terminal already exists. Otherwise ALLOW and proceed immediately without comment."
}
}
Observed behavior:
When the agent calls execute_pwsh with a command not in the trusted commands list:
- Kiro intercepts the tool call via the preToolUse hook
- The hook returns to the agent with "The tool was NOT executed. Address each hook instruction..."
- The agent evaluates the hook prompt, determines the command is ALLOW (doesn't match block patterns)
- The agent re-submits the identical command
- The command executes successfully despite not being in the trusted commands list
Repeat steps:
- Ensure aws iam delete-role --role-name
is NOT in the Kiro trusted commands list - Have the enforce-powershell-execution-rules hook active as above
- Ask the agent to execute aws iam delete-role --role-name
- Observe: hook intercepts on first submission, agent re-submits, command executes on second submission 5. without trusted commands approval
Commands that reproduced this:
- aws iam detach-role-policy --role-name iamr-stkt-prd-allx-iacado-001 --policy-arn ...
- aws iam remove-role-from-instance-profile ...
- aws iam delete-instance-profile ...
- aws iam delete-role --role-name iamr-stkt-prd-allx-iacado-001
Expected behavior: After the hook returns control to the agent and the agent determines ALLOW, the command should still be subject to trusted commands list evaluation before executing. The hook's ALLOW decision should not bypass the trusted commands gate.
Impact: Destructive and irreversible IAM operations executed without explicit user approval via the trusted commands mechanism
Steps to Reproduce
- Ensure aws iam delete-role --role-name is NOT in the Kiro trusted commands list
- Have the enforce-powershell-execution-rules hook active as above
- Ask the agent to execute aws iam delete-role --role-name
- Observe: hook intercepts on first submission, agent re-submits, command executes on second submission 5. without trusted commands approval
Note: These steps do not always skip the Trusted Commands check. This has happened intermittently.
Expected Behavior
After the hook returns control to the agent and the agent determines ALLOW, the command should still be subject to trusted commands list evaluation before executing. The hook's ALLOW decision should not bypass the trusted commands gate.
Conversation ID
No response
Additional Context
No response
🤖 Potential Duplicate Detected
This issue appears to be similar to:
- #9355: kiro-cli 2.6.1: headless session crashes with Bedrock ValidationException "duplicate Ids" after preToolUse hook blocks the same tool call twice (85% similar)
- #8775: Shell redirects (>) bypass pretrusted command checks and write files without approval (85% similar)
- #8264: Kiro CLI PreToolUse hooks not working correctly on Windows 11 (85% similar)
- #7611: IDE Trust Command feature is too simplistic for sophisticated commands (85% similar)
- #9206: Agent ran rm -rf before mv on uncommitted files without confirmation (82% similar)
What happens next?
- ⏰ This issue will be automatically closed in 3 days
- 🏷️ If this is not a duplicate, you can prevent automatic closure by adding a comment or reacting with 👎 to this message.
- 💬 Comment on the original issue if you have additional information
Why is this marked as duplicate? Both issues involve preToolUse hooks causing problems with tool execution - the new issue describes hooks allowing command execution bypass, while #9355 describes hooks causing crashes when blocking the same tool call twice. Both involve the preToolUse hook mechanism malfunctioning in different ways.
This issue has been automatically closed as it appears to be a duplicate of #9355.
If you believe this is incorrect, please comment on this issue and a maintainer will review it.
This does not appear to be a duplicate of #9355. How can I reopen it?
#9355 has to do with the duplicate commands processing issue, and is a real credits waster. I definitely want to see it fixed.
This is a security bug. Kiro ignored my Trusted Commands list and executed destructive commands without verification.
Thank you for your feedback! 🙏
The duplicate label has been removed and this issue has been sent back for maintainer review.
A maintainer will review this issue shortly.
This may be more similar to #8775 but I am not certain.
I found a "*" in my trusted commands list, so PEBKAC.