Kiro icon indicating copy to clipboard operation
Kiro copied to clipboard

cd breaks allowedCommands for shell tool

Open TrevorBurnham opened this issue 11 months ago • 4 comments

Before opening, please confirm:

Operating System

macOS 26.2

Kiro Version

kiro-cli 1.23.1

Bug Description

In my custom agent, I'm using allowedCommands to allow commands, per the docs:

"toolsSettings": {
  "shell": {
    "allowedCommands": [
      "npx vitest .*"
    ],
    "autoAllowReadonly": true
  }
}

That regex has the intended effect of allowing my agent to run commands like this:

npx vitest --reporter=dot

However, my agent will often preface commands with cd to ensure that they're running in the correct directory. When they do so, the command doesn't match the allowlist.

Steps to Reproduce

Here's a brief conversation that I had to test this:

[custom_agent] λ > Run the command `npx vitest --reporter=dot` in the current directory.

I will run the following command: cd /MyProject && npx vitest --project app --reporter=dot (using tool: shell)
Purpose: Run Vitest tests for the app project

Allow this action? Use 't' to trust (always allow) this tool for the session. [y/n/t]:

Expected Behavior

Prefacing a command with cd shouldn't affect whether it's allowed or not. (Sandboxing and configuring allowing commands on a per-project basis would be nice, but that's a separate story…)

Conversation ID

No response

Additional Context

I think the most direct solution would be to provide a cwd option to the shell tool, so that agents wouldn't feel the need to use cd to make the command run in the correct directory.

TrevorBurnham avatar Dec 24 '25 00:12 TrevorBurnham

~~I found the workaround of adding cd .* to allowedCommands. 🤦‍♂️ That might seem obvious to others, but it seems like it shouldn't be necessary… (Also, why isn't cd allowed by autoAllowReadonly?)~~ Adding cd .* is a workaround that is extremely insecure since it matches commands like this:

cd / && rm -rf

TrevorBurnham avatar Dec 24 '25 00:12 TrevorBurnham

I think this issue is more about chained commands in general, although I also am running into problems with agents trying to chain commands to cd.

The workaround I went with is to add cd .* to the alllowedCommands, but keep a detailed deniedCommands list, with .* added before and after each command. This will prevent them from appearing anywhere in a chained command. For example, adding ".*rm -rf.*" should block the command cd / && rm -rf or rm -rf foo.

One other related concern I have is what actually gets added to the allowed commands when you respond with t to a chained command. If the request was cd ./foo && npm run build would it add something like cd .*?

horsmand avatar Jan 22 '26 22:01 horsmand

Hey @TrevorBurnham, thanks for reporting this issue! We added a fix last week that updates the shell tool with a working_dir parameter to prevent the model from prefixing all commands with cd, which should mitigate the problem. Could you please download/update to the latest CLI v1.26.2 and try again?

evanliu048 avatar Feb 18 '26 23:02 evanliu048

I believe this has been fully resolved as of v1.27.0 by an internal change that parses shell commands into their individual parts when checking permissions.

TrevorBurnham avatar Feb 28 '26 21:02 TrevorBurnham