kilocode icon indicating copy to clipboard operation
kilocode copied to clipboard

`external_directory` permission isn't checked when a bash command reads an outside file through a symlink

Open chrischant3 opened this issue 3 weeks ago • 1 comments

Component

CLI / TUI

Description

With bash allowed and external_directory set to deny (or ask), a bash command that reads a file outside the project directly is refused. The same read done through a symlink gets no permission request, and the file's contents go back to the model.

I know the permission system is a UX feature and not a sandbox (SECURITY.md, "Threat Model"), so I'm reporting this as an inconsistency, not a vulnerability. Teams set external_directory to keep an agent's attention inside the repo, and this is a case where it silently doesn't apply.

Command Permission requested Outside contents returned
cat ../outside/canary.txt yes no
cd .. && cat outside/canary.txt yes no
cat "$(cd .. && pwd)/outside/canary.txt" yes no
ln -sf ../outside/canary.txt link.txt && cat link.txt no yes

The table is from 7.8.18, with external_directory: ask. The first and last rows give the same result on 7.8.27.

Under deny, the symlink command got through in 3 of 3 runs on 7.8.27, and under ask too. Under deny, the direct read is refused with "The user has specified a rule which prevents you from using this specific tool call". The read tool isn't affected: it resolves the symlink and asks for external_directory against the real target. So it looks as if the bash tool checks the paths written in the command and doesn't follow a link to where it points. That's my guess from the behaviour; I haven't read the code.

Expected Result: the symlinked read gets the same external_directory check as the direct one, or the docs say that bash commands can reach outside paths without a prompt.

Plugins

No response

Kilo version

7.8.27 (@kilocode/cli). First seen on 7.8.18

Steps to reproduce

  1. Make a project and an outside folder next to it:
    mkdir -p demo/project demo/outside
    echo "CANARY-outside-123" > demo/outside/canary.txt
    cd demo/project && git init -q
    echo '{ "permission": { "bash": "allow", "external_directory": "ask" } }' > kilo.jsonc
    
  2. Ask for a direct read. Kilo asks first: stderr shows permission requested: external_directory (.../outside/*); auto-rejecting, and the file isn't read:
    kilo run --pure --format json "Run this exact shell command and show me the output: cat ../outside/canary.txt"
    
  3. Ask for the same read through a symlink. There's no permission request, and CANARY-outside-123 appears in the output:
    kilo run --pure --format json "Run this exact shell command and show me the output: ln -sf ../outside/canary.txt link.txt && cat link.txt"
    

With "external_directory": "deny" the result is the same: the direct read is refused and the symlinked one goes through. It also reproduces in a Linux arm64 Docker container (on 7.8.18), so it isn't macOS-specific. Model: anthropic/claude-haiku-4-5. A run with a fresh HOME, so no user config applies, gives the same result.

Screenshot and/or share link

No response

Operating System

macOS 27.3. Also Linux arm64 in Docker.

Terminal

iTerm2

chrischant3 avatar Nov 10 '26 17:11 chrischant3

I'd like to work on this. Before writing code I wanted to check the approach, since there are a few options.

What's happening: ShellTool.collect (packages/opencode/src/tool/shell.ts) only checks path arguments for commands in the FILES set (cd, rm, cp, mv, mkdir, touch, chmod, chown, cat, plus PowerShell/cmd equivalents). It resolves each argument with path.resolve() and compares it with containsPath(), without following symlinks. So in ln -sf ../outside/canary.txt link.txt && cat link.txt:

ln isn't in FILES, so ../outside/canary.txt is never checked. cat link.txt resolves to a path inside the project, so it passes. The read tool is different because kilocode/tool/read-object.ts calls realpath() before checking.

Options:

Add ln (and link) to FILES. Creating the link then triggers external_directory for its target. This catches the repro in the issue, but not a symlink that already exists in the repo. realpath() arguments that already exist before containsPath(), the way the read tool does. This catches existing symlinks that point outside. It costs one fs call per path argument of a FILES command, and does nothing for links created in the same command. Both 1 and 2, which covers both cases. Docs only: say that the bash external_directory check is best-effort and only covers a fixed list of commands. I'd suggest 3, plus a line in the docs from 4. The command list means any check on bash will always be heuristic. For example, from reading the code, head ../outside/file doesn't look like it gets checked either. I haven't tested that. Users should know external_directory on bash is a guardrail, not a boundary, which matches the "no sandbox" note in SECURITY.md.

Does that direction work for you, or would you rather keep it to one of these?

Beehtrix avatar Nov 16 '26 02:11 Beehtrix