Policy rules and the workspace check match the command text or the tool name, not what the tool call does
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, shell, typescript
- Ambito
- cli, documentation, security
Direzione di ricerca
Start with packages/core/src/policy/utils.ts, packages/core/src/policy/policy-engine.ts, packages/core/src/tools/write-file.ts, and packages/core/src/services/fileSystemService.ts, then review docs/reference/policy-engine.md and docs/tools/file-system.md. Reproduction steps and the three suggested fixes define the scope: command matching, tool-boundary documentation, and symlink-safe writes. Done means the behavior is consistently specified, the documented policy boundaries are explicit, and focused tests cover command variants, alternative file access paths, and workspace escape attempts.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What happened?
Policy rules and the file tools' workspace check decide on what a tool call looks like (the literal command text, the tool name, a path resolved once), not on what the call then does. There are three ways around them:
commandPrefixrules match the literal command text. A user or admin rule withtoolName = "run_shell_command",commandPrefix = "touch",decision = "deny"deniestouch <project>/canary/canary.txtand also catchestrue && touch ...,(touch ...)andsh -c 'touch ...', but/usr/bin/touch,\touch,env FOO=1 touch,t'o'uch,$(echo touch)andX=touch; $Xrun and create the file. The same happens withdecision = "ask_user"(headless treats it as deny), with the rule in an admin policy (--admin-policy <dir>), and over ACP (gemini --acp), where anask_userrule sent no permission request for/usr/bin/touch.commandPrefixbecomes the regular expression"command":"touch(?:[\s"]|\\")(packages/core/src/policy/utils.ts:56-83), tested against the raw arguments of each sub-command; the program name is not normalised (path, backslash, quotes,env, expansions).- File rules, admin file rules and the workspace limit bind only Gemini's own file tools. A rule that denies
read_file,read_many_filesandgrep_searchon<project>/secret/stopsread_file("<project>/secret/secret.txt"), but the same file is read byrun_shell_command("cat <project>/secret/secret.txt"), by a program the shell starts (python3 -c "print(open(...).read())") and by an MCP tool (canary_read(path)); the same holds for the same rules in an admin policy. Likewise for the workspace limit ("All file system tools operate within arootDirectory(the current working directory or workspace root) for security.", docs/tools/file-system.md:8-9):read_fileof a file outside the workspace is refused with "Path not in workspace", but the shell, a Python process started by the shell, and an MCP tool read and write outside the workspace (no sandbox set). Rules match the tool name and its arguments (packages/core/src/policy/policy-engine.ts:214-226), and the workspace check is inside the file tools. This follows from the documented design ("ThetoolNamein the rule must match the name of the tool being called", docs/reference/policy-engine.md:74), so this item is a documentation request. write_file's workspace check and its write resolve a symlink separately.write_filerefuses paths that resolve outside the workspace, but the check (packages/core/src/tools/write-file.ts:372,this.config.validatePathAccess(this.resolvedPath)) and the write (packages/core/src/services/fileSystemService.ts:57-95,writeTextFileresolves the path again withresolveToRealPath, then writes a temp file next to the real path and renames it) each resolve the path on their own. If a directory in the path is swapped for a symlink between the two, the write lands outside the workspace. This was seen in a plaingemini -psession, in a session resumed with--resumeafter context compression, and with subagents; it is intermittent and needs a second local process that swaps the link at the right moment, so I'm filing it as hardening.
See also the issue about configuration and hooks that fail open (project settings that auto-approve tools, a policy file dropped for one bad entry, a blocking hook that fails), which uses the same policy files.
What did you expect to happen?
Setup for all steps (headless, trusted folder <project>, no sandbox): ~/.gemini/settings.json with {"security": {"auth": {"selectedType": "gemini-api-key"}}}, and ~/.gemini/policies/base.toml allowing every tool in the default mode, so only the deny decides (step 3 uses only the first five lines):
[[rule]]
toolName = "*"
decision = "allow"
priority = 1
modes = ["default"]
allowRedirection = true
allowCommandSubstitution = true
The base file sets allowCommandSubstitution = true because without it an allow becomes ask on $(...) (docs/reference/policy-engine.md:355-359); the deny rules themselves have no such option.
~/.gemini/policies/deny.toml:
Run[[rule]] toolName = "run_shell_command" commandPrefix = "touch" decision = "deny" priority = 500gemini -p "Run exactly this shell command: /usr/bin/touch <project>/canary/canary.txt"(tool call:run_shell_command({"command": "/usr/bin/touch <project>/canary/canary.txt"})): the file is created. Comparison:gemini -p "Run exactly this shell command: touch <project>/canary/canary.txt"givesTool execution denied by policy.<project>/secret/secret.txtcontainingSECRET-1, and~/.gemini/policies/deny.tomlreplaced by:
Run[[rule]] toolName = ["read_file", "read_many_files", "grep_search"] argsPattern = '<project>/secret/' decision = "deny" priority = 500gemini -p "Run this shell command and show its output: cat <project>/secret/secret.txt"(tool call:run_shell_command({"command": "cat <project>/secret/secret.txt"})): the tool output isSECRET-1. Comparison:gemini -p "Read <project>/secret/secret.txt with the read_file tool"givesTool execution denied by policy.- No
deny.toml.OUT=$(mktemp -d)(use it as<outside>, a writable folder outside the workspace) and start this loop in the background:
Runwhile true; do rm -rf <project>/rc-x; mkdir -p <project>/rc-x; rm -rf <project>/rc-x; ln -s <outside> <project>/rc-x; donegemini -p "Use write_file four times in parallel to write PT to <project>/rc-x/x.txt"; repeat until<outside>/x.txtappears. One session's four callswrite_file({"file_path": "<project>/rc-x/x.txt", "content": "PT"})returned:
andSuccessfully created and wrote to new file: <project>/rc-x/x.txt ... Error writing to file '<project>/rc-x/x.txt': ENOENT: no such file or directory, open '<project>/rc-x/x.txt.<uuid>.tmp' Path not in workspace: Attempted path "<project>/rc-x/x.txt" resolves outside the allowed workspace directories ... Successfully created and wrote to new file: <project>/rc-x/x.txt ...<outside>/x.txtexisted afterwards.
Client information
Client Information
Run gemini to enter the interactive CLI, then run the /about command.
> /about
About Gemini CLI
CLI Version 0.69.0
Git Commit 58840eb92
Model Auto
Sandbox no sandbox
OS linux
Auth Method gemini-api-key
Platform: Linux (Debian GNU/Linux 12 bookworm, kernel 6.8.0), Node.js v22.23.5. Gemini CLI installed with npm install -g @google/[email protected].
Login information
API key
Anything else we need to know?
- Suggested fix 1: normalise the program name of each sub-command before matching: strip the path and a leading
\, remove quotes, skipenv VAR=..., and treat a program name that comes from an expansion as not matching an allow and matching a deny. If that is not wanted, please state in the docs that command rules are not a boundary against a model that rewrites the command, and point to the sandbox. - Suggested fix 2: add a clear sentence in reference/policy-engine.md, tools/file-system.md and the enterprise guide that path rules and the workspace limit cover only the built-in file tools, and that protecting a path from the shell or MCP servers needs the sandbox (or denying those tools). Administrators reading docs/cli/enterprise.md may otherwise take an admin path deny as complete.
- Suggested fix 3: resolve once, check that real path and write to it with
O_NOFOLLOWor through an open directory handle, or re-check the real path of the opened file before the rename.
- Lingua principale
- TypeScript
- Stelle
- 109k
- Fork
- 15k
- Merge medio
- 1g 24m
- PR unite (30g)
- 91
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google-gemini/gemini-cli
-
npm ci fails with EALLOWREMOTE on npm 12Forse già presa @landry-kapgnep l’ha presa oggi. Apertastatus/need-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
google-gemini/gemini-cli#30525 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
hooks migrate preserves regex SessionStart alternatives that native exact trigger matching never runsForse già presa @ayam04 l’ha presa oggi. Apertastatus/need-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
google-gemini/gemini-cli#30514 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
CLI reference documents unsupported bulk skills enable and disable commandsForse già presa @jadelike-wine l’ha presa 1 giorno fa. Apertastatus/need-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
google-gemini/gemini-cli#30505 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Footer ignores custom model displayName and drops Vertex AI model info despite hideModelInfo=falseForse già presa @bitwizard25 l’ha presa 2 giorni fa. Apertastatus/need-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
google-gemini/gemini-cli#30482 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
fix(extensions): allowUnsafeConfigPaths missing in GIT_EXTENSION_OPTIONS causes `extensions update` failureForse già presa @kccrcodes l’ha presa 4 giorni fa. Apertastatus/need-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
google-gemini/gemini-cli#30416 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di google-gemini/gemini-cli
Issue simili
-
enhancement from-app needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
nightly-labs/openbot#19162 ·
I maintainer di solito rispondono entro 1 giorno
-
triage:in-progress
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Cotal-AI/Cotal#11229 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
omdsh-dev/DSH-better-sidebar#1290 ·
I maintainer di solito rispondono entro 1 giorno
-
Suggest a wallet: WalletChanForse già presa @apoorvlathey l’ha presa oggi. Apertaawaiting changes needs triage 📥
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
ethereum/ethereum-org-website#20000 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno