Deny rules, the working-directory boundary and plan mode cover less than the docs say (hook allow, MCP tools, shell, link swap, redirects)

Offen
#5,614 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
bash, python
Bereich
cli, security

Rechercherichtung

Start with the permissions documentation and the hooks, MCP server, shell, and plan-mode permission paths; reproduce using test_mcp_server.py, ~/.mcp/mcp-config.json, and ~/.copilot/hooks/allow.json as described. Trace where deny rules, working-directory checks, URL checks, and filesystem effects are evaluated for each tool route. Done means the listed bypasses are blocked consistently or their limitations are explicitly documented, with regression coverage for the affected routes.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

triage:needs-human
Describe the bug

--deny-tool / --deny-url rules, the working-directory boundary and plan mode block an action when it is done the plain way (the built-in tool, a plain shell command, the URL typed in the command), but the same action goes through on another route. Some of these limits are documented; I'm reporting them because the docs elsewhere say deny rules always win, and a user who sets these rules cannot tell which routes they cover.

  1. A hook that answers "allow" overrides --deny-tool and --deny-url rules. The docs say: "Deny rules always take precedence over allow rules, even when --allow-all is set or a matching approval has been saved in permissions-config.json." (docs: "Allowing tools"), and "Deny rules win over every allow, including --allow-all-tools." (copilot help permissions). With a user preToolUse hook that prints {"permissionDecision":"allow"}, calls that a --deny-tool or --deny-url rule denies without the hook run: shell, read and write (also with a path), MCP tool and URL rules. A permissionRequest hook printing {"behavior":"allow"} does the same; for that hook the hooks reference says the decision "short-circuits the normal permission flow", which conflicts with the precedence statement. Managed permissions.deny rules and plan mode still blocked the same calls with the same hooks.
  2. MCP tools are not checked against path rules, the working-directory boundary or plan mode. The docs say: read(path?) "Matches file-read requests from built-in tools", MCP tools are their own kind <mcp-server-name>(tool-name?), and "File access is limited to the working directory and the system temp directory" (copilot help permissions); plan mode lets "calls to external/MCP tools you've connected" through (CLI command reference). A file-capable MCP tool (canary_read(path), canary_write(path, content), from a user server or a plugin's server) reads a file that --deny-tool='read(/work/secret/**)' denies for view, reads /outside/x.txt with no prompt while view of it needs approval, and writes in plan mode where create is blocked. Nothing says the working-directory boundary does not apply to MCP tools.
  3. --deny-tool=read/write do not stop the same read or write done by a shell command. The docs say: "A rule with a path does not apply to shell commands", and "An unscoped "write" rule (for example --allow-tool='write') approves a shell command's redirection of output into a file" (copilot help permissions). --deny-tool=write denies create, but printf %s PT > /work/canary/x.txt runs, although --allow-tool=write would approve that same redirection; --deny-tool=read denies view but not cat. A user who reads that a denied tool means "the AI model cannot use that tool at all" (docs: "Allowing tools") may expect these rules to stop file reads and writes in general.
  4. Plan mode lets file-writing shell commands through. The docs say: "It's a safety net, not a guarantee ... Some things are intentionally allowed through so research isn't overly restricted: for example, shell commands whose effect can't be clearly determined in advance" (CLI command reference, plan mode). touch, \touch, /usr/bin/touch and git diff --output=... are blocked, but sh -c 'touch ...', env X=1 touch ..., $(echo touch) ..., X=touch; $X ..., t'o'uch ..., find ... -fprint, sed -n 'w ...', sort -o, git -C <dir> config and python3 -c 'import subprocess; ...' write files with no block. These have a clear effect that can be determined in advance; subagents and custom agents behave the same.
  5. A path is checked, then opened again: a directory swapped for a link between check and use defeats path rules (race). The docs say nothing about this for the built-in tools; "Symlinks are resolved for existing files, but not for files being created" is said for shell path detection ("Configuring Copilot CLI"). With --deny-tool='write(/work/canary/**)', create /work/link/x.txt is denied when /work/link is a fixed link to /work/canary. When /work/rc keeps switching between a real directory and that link, repeated create /work/rc/x.txt calls are sometimes denied and one succeeded while /work/rc was the link, so the file ended up in /work/canary. The same pattern defeated the working-directory boundary, managed Read(...) rules for view and the sandbox's deniedPaths for view; it needs a second local process and repeated attempts.
  6. --deny-url checks the typed URL, not where it redirects. The docs say: "For shell commands, URLs are extracted using regex patterns" (docs: "Configuring Copilot CLI"), and "Deny rules win over every allow" (copilot help permissions); redirects are not among the listed limitations. With --allow-url=http://allowed.test:8081 --deny-url=http://canary.test:8081, curl -s -m 5 http://canary.test:8081/x is denied, but curl -sL -m 5 http://allowed.test:8081/redirect/x follows the server's 302 to the denied host and returns its response ("canary ok").

See also the issue about settings that SDK and ACP sessions do not apply, and hooks that fail open.

Affected version

1.0.117

Steps to reproduce the behavior

Setup for all steps: a Debian 12 container with Node 22; a git repository /work with /work/secret/x.txt containing SECRET, the directory /work/canary, and /outside/x.txt. Every run is echo '<prompt>' | copilot --no-auto-update --no-ask-user --disable-builtin-mcps --allow-tool=shell --allow-tool=write <flags> from /work (with --no-ask-user, a request that needs approval is denied). Shell prompts are "Run this exact shell command with the bash tool: ". For steps 1 and 2, test_mcp_server.py is any stdio MCP server with the tools canary_read(path) (returns the file's content) and canary_write(path, content) (writes the file), saved as ~/.mcp/test_mcp_server.py, with ~/.copilot/mcp-config.json: {"mcpServers": {"canary": {"type": "local", "command": "python3", "args": ["/home/node/.mcp/test_mcp_server.py"], "tools": ["*"]}}} and the flag --allow-tool=canary.

  1. Create ~/.copilot/hooks/allow.json:
    {"version": 1, "hooks": {"preToolUse": [{"type": "command", "bash": "echo '{\"permissionDecision\":\"allow\"}'"}]}}
    
    Run the shell command touch /work/canary/canary.txt with --deny-tool='shell(touch)': the file is created. Without the hook file: "Permission to run this tool was denied due to the following rules: shell(touch)". The same with --deny-tool='canary(canary_write)' and the prompt "Use the canary_write tool to write PT to /work/canary/x.txt" ("written"), --deny-tool='read(/work/secret/**)' and view (content returned), --deny-url=http://canary.test:8081 with curl, and with a permissionRequest hook printing {"behavior":"allow"}.
  2. With --deny-tool='read(/work/secret/**)': "Use the view tool to show /work/secret/x.txt" is denied; "Use the canary_read tool to show /work/secret/x.txt" returns the content. Without --deny-tool, the same two prompts for /outside/x.txt: view "Permission denied because no interactive user response was available...", canary_read returns the file. With --plan: "Use the canary_write tool to write PT to /work/canary/x.txt" writes the file, create is blocked ("Plan mode does not permit changes outside the session folder"). A plugin's server with the same definition behaves the same.
  3. With --deny-tool=read: "Use the view tool to show /work/secret/x.txt" is denied ("... following rules: read"); the shell command cat /work/secret/x.txt shows the content. With --deny-tool=write: "Use the create tool to create /work/canary/x.txt with content PT" is denied; the shell command printf %s PT > /work/canary/x.txt writes the file. The path forms read(/work/secret/**) / write(/work/canary/**) and python3 -c reads and writes behave the same. (--allow-tool=write is the grant a user gives so that the agent may write files; the deny rule must win over it.)
  4. With --plan: the shell command touch /work/canary/a.txt is blocked ("This shell command would modify files outside the session folder and was blocked."); sort -o /work/canary/b.txt /dev/null writes the file. Repeat with each command in item 4. For git config: git init -q --bare /work/canary/g && mkdir /work/rd && printf 'gitdir: /work/canary/g\n' > /work/rd/.git, then git -C /work/rd config test.mark PT; the value appears in /work/canary/g/config.
  5. Start a switcher in the background:
    ( while true; do rm -rf /work/rc; mkdir -p /work/rc; rm -rf /work/rc; ln -s /work/canary /work/rc; done ) >/dev/null 2>&1 &
    
    With --deny-tool='write(/work/canary/**)', prompt "Use the create tool to create /work/rc/x.txt with content PT. If it fails, try again, up to 30 times." Stop the switcher: /work/canary/x.txt exists (it can take more than one run). Observed: two calls denied by write(/work/canary/**), then "Created file /work/rc/...".
  6. Make allowed.test and canary.test resolve to 127.0.0.1 and run a small web server on port 8081 that answers allowed.test:8081/redirect/<x> with 302 Location: http://canary.test:8081/<x> and canary.test:8081/<x> with canary ok, logging each request. With --allow-url=http://canary.test:8081 --allow-url=http://allowed.test:8081 --deny-url=http://canary.test:8081, the shell command curl -sL -m 5 http://allowed.test:8081/redirect/x returns canary ok (log: GET allowed.test /redirect/x, then GET canary.test /x); curl -s -m 5 http://canary.test:8081/x is denied by url(http://canary.test:8081).
Expected behavior
  1. Expected: the matching --deny-tool / --deny-url rule denies the call, as without the hook. Suggested: check deny rules before, or in addition to, a hook's "allow"; or say in "Allowing tools" that a hook "allow" wins.
  2. Expected: the MCP call is denied by the path rule, needs approval outside the working directory, and is blocked in plan mode, as the built-in tools are. Suggested: let path rules apply to MCP arguments declared as paths, at least for the working-directory boundary; otherwise say plainly that read(...)/write(...) rules and the boundary do not cover MCP tools.
  3. Expected: --deny-tool=write stops the shell redirection that --allow-tool=write approves (the CLI already finds redirection targets for managed Write(...) rules). Suggested: deny the detected redirections and in-place writes; document next to --deny-tool that read/write deny rules do not cover other shell reads and writes.
  4. Expected: commands that write files are blocked like touch. Suggested: treat wrappers and expansions (sh -c, env, $(...), $VAR, interpreters with -c) as "effect can't be determined" and block or ask; count the write options of find, sed, sort and git config as modifications; or list the exceptions in the plan-mode docs.
  5. Expected: no file is ever created inside the denied directory. Suggested: open the path that was checked (open the resolved path, or each component with O_NOFOLLOW, and re-check the opened file's real path before writing or returning content).
  6. Expected: the request to the denied host is blocked. Suggested: ask (or deny) for network commands that follow redirects (curl -L/--location) while URL deny rules are in force, or enforce URL rules at the network level; otherwise name redirects among the limitations in "Configuring Copilot CLI".
Additional context

No response

Vorherrschende Sprache
Python
Sterne
11.5k
Forks
2k
Ø Merge
6 Std. 34 Min.
Gemergte PRs (30 T.)
3

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus github/copilot-cli

Alle Issues in github/copilot-cli

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.