Repository navigation
Closed
Labels
area/securityIssues related to securitystatus/need-triageIssues that need to be triaged by the triage automation.
Description
What happened?
Following PR #29250 ("fix(core): prevent indirect prompt injection via build file modifications and untrusted flags"), shell execution frequently prompts the user with a critical security alert on harmless routine commands (such as ls -la, grep -rn, cat -n, git diff, etc.):
⚠️ CRITICAL SECURITY WARNING: Untrusted Command Flags Detected
The following flags/arguments were sourced from external untrusted input (e.g., Buganizer ticket, external document):
• <flag/path/token>
Executing commands with flags sourced from untrusted input can execute arbitrary code on your machine.
Carefully verify these flags before approving.
Root Cause Analysis
In packages/core/src/utils/untrustedContextTracker.ts:
extractUntrustedContext(history)extracts all text from<untrusted_context>...</untrusted_context>tags across the entire session history and breaks them down into arbitrary tokens (splitting on whitespace, punctuation, slashes, etc.).- In
findUntrustedFlags(command, untrustedContext):- Any token starting with
-whose name or value appears inuntrustedTokensis flagged as untrusted. - Any token containing
/,.or:that exists inuntrustedTokensis flagged as an untrusted parameter.
- Any token starting with
- Because tool outputs (like
ls,grep,cat, git commands, etc.) are wrapped in<untrusted_context>, virtually every standard command-line flag (-la,-n,-rn,--help, etc.) or workspace path (src/...,package.json,./...) eventually appears inuntrustedTokens.
Severe Side Effects:
- Disrupts regular workflows: Nearly every subsequent shell command gets interrupted by this warning dialog.
- Bypasses YOLO mode: In
packages/core/src/tools/shell.ts,findUntrustedFlags(command, untrustedContext)is evaluated before checking YOLO mode (this.context.config.getApprovalMode() === ApprovalMode.YOLO), so even users running with YOLO / auto-approval are repeatedly stopped. - Breaks Policy Persistence:
getPolicyUpdateOptionsreturnsundefinedwhen untrusted flags are detected, making it impossible to "Always allow" or save approvals to policy. - No toggle: There is currently no configuration option in
security.*or CLI flag to disable or tune this heuristic.
What did you expect to happen?
- Routine shell commands should not be flagged as untrusted prompt-injections simply because common options (like
-la,-n) or file paths appeared in previous command outputs. - The tracker should distinguish between actual external untrusted inputs (e.g. web fetch, third-party docs, issue descriptions) vs. local tool execution results / developer's own files.
- A configuration option or flag should be provided to adjust or disable this behavior.
Client information
Client Information
- Gemini CLI Version: 0.62.0
- Platform: Linux (x86_64)
- Node.js: v22.23.1
Additional context
Temporary workaround used locally: patching findUntrustedFlags in the bundle chunks to return [].
Reacted by David Franck, Dimitar Pavlov, Justin Santa Barbara, Peter Ebden and Kim Skinner
Metadata
Metadata
Assignees
Labels
area/securityIssues related to securitystatus/need-triageIssues that need to be triaged by the triage automation.
Activity
abhinav-phi commentedon Sep 30, 2026
i can reproduce this, same thing on 0.62.0 with plain
ls -laandcat -n.extractUntrustedContextwalks the entire history on every check and builds one token set from all<untrusted_context>blocks. since shell output gets wrapped in those tags too (shell.ts), a command's own output feeds the next check, and tokens get split on/and=and indexed without their flag prefix, so-la,src/...,package.jsonall match.happy to take a shot at it if maintainers want to confirm the approach first, or if this gets marked help-wanted.
AdamMajer commentedon Oct 7, 2026
0.62.0 doesn't have this issue for me and downgrading to it is a workaround here
justinsb commentedon Oct 7, 2026
Can we revert #29250 @DavidAPierce ? I am seeing refusals in --yolo mode, and it (combined with #29506) look to be responsible.
samvallad33 commentedon Oct 8, 2026
a critical security warning on git diff. when half the routine commands flag, the real warnings become noise and everyone clicks through them.
this is the failure I built a small gate for. it does not care where a flag came from. it reads each command the way the shell is about to run it and classifies what it would actually do, so reads pass and the destructive ones it knows get stopped. a recursive delete is one of them and a force push to a shared branch is another.
it is free, it runs on your machine, and it is part of vestige.
npx operator-liteit wires into gemini cli and starts in shadow mode, recording what it would have stopped, so nothing changes at first.
npx operator-lite mode enforcerun that once from your own terminal and the blocking is on.