Skip to content

bug(core): massive false positives with "Untrusted Command Flags Detected" security warning after PR #29250 #29579

Closed

Description

@ng-galien

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:

  1. 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.).
  2. In findUntrustedFlags(command, untrustedContext):
    • Any token starting with - whose name or value appears in untrustedTokens is flagged as untrusted.
    • Any token containing /, . or : that exists in untrustedTokens is flagged as an untrusted parameter.
  3. 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 in untrustedTokens.

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: getPolicyUpdateOptions returns undefined when 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?

  1. 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.
  2. 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.
  3. 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 [].

Activity

  1. added
    status/need-triage
    area/security
    on Sep 30, 2026
  2. abhinav-phi commented on Sep 30, 2026

    @abhinav-phi

    i can reproduce this, same thing on 0.62.0 with plain ls -la and cat -n.

    extractUntrustedContext walks 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.json all match.

    happy to take a shot at it if maintainers want to confirm the approach first, or if this gets marked help-wanted.

  3. AdamMajer commented on Oct 7, 2026

    @AdamMajer

    0.62.0 doesn't have this issue for me and downgrading to it is a workaround here

  4. justinsb commented on Oct 7, 2026

    @justinsb

    Can we revert #29250 @DavidAPierce ? I am seeing refusals in --yolo mode, and it (combined with #29506) look to be responsible.

  5. samvallad33 commented on Oct 8, 2026

    @samvallad33

    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-lite

    it wires into gemini cli and starts in shadow mode, recording what it would have stopped, so nothing changes at first.

    npx operator-lite mode enforce

    run that once from your own terminal and the blocking is on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/securitystatus/need-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions