Kiro icon indicating copy to clipboard operation
Kiro copied to clipboard

Bug: preToolUse askAgent hook allows command execution bypass of trusted commands list

Open webbd-jabil opened this issue 5 months ago • 6 comments

Before opening, please confirm:

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:

  1. Kiro intercepts the tool call via the preToolUse hook
  2. The hook returns to the agent with "The tool was NOT executed. Address each hook instruction..."
  3. The agent evaluates the hook prompt, determines the command is ALLOW (doesn't match block patterns)
  4. The agent re-submits the identical command
  5. The command executes successfully despite not being in the trusted commands list

Repeat steps:

  1. Ensure aws iam delete-role --role-name is NOT in the Kiro trusted commands list
  2. Have the enforce-powershell-execution-rules hook active as above
  3. Ask the agent to execute aws iam delete-role --role-name
  4. 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

  1. Ensure aws iam delete-role --role-name is NOT in the Kiro trusted commands list
  2. Have the enforce-powershell-execution-rules hook active as above
  3. Ask the agent to execute aws iam delete-role --role-name
  4. 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

webbd-jabil avatar Jun 12 '26 17:06 webbd-jabil

🤖 Potential Duplicate Detected

This issue appears to be similar to:

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.

github-actions[bot] avatar Jun 12 '26 17:06 github-actions[bot]

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.

github-actions[bot] avatar Jun 16 '26 01:06 github-actions[bot]

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.

webbd-jabil avatar Jun 17 '26 16:06 webbd-jabil

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.

github-actions[bot] avatar Jun 17 '26 16:06 github-actions[bot]

This may be more similar to #8775 but I am not certain.

webbd-jabil avatar Jun 17 '26 16:06 webbd-jabil

I found a "*" in my trusted commands list, so PEBKAC.

webbd-jabil avatar Jun 17 '26 23:06 webbd-jabil