Skip to content

fix(core): treat project temp paths as local in untrusted flag checks - #30026

Open
moah0911 wants to merge 2 commits into
google-gemini:mainfrom
moah0911:fix/untrusted-flag-temp-dir-scope
Open

moah0911 wants to merge 2 commits into
google-gemini:mainfrom
moah0911:fix/untrusted-flag-temp-dir-scope

Conversation

@moah0911

@moah0911 moah0911 commented Oct 29, 2026 •

Copy link
Copy Markdown

Summary

The agent's own helper scripts under Gemini CLI's session project temp directory
(~/.gemini/tmp/<project>/...) were reported as untrusted shell arguments. Once
shell output such as a Python traceback mentioned the script path, the next
python3 <path> invocation requested confirmation even in YOLO mode.

This change treats the project temp directory as local for untrusted-flag
detection, alongside the workspace.

Details

findUntrustedFlags() exempts path arguments that resolve inside the workspace
(isPathWithinWorkspace). The project temp directory lives outside the
workspace, so a local script written there and later named in its own traceback
was flagged as untrusted — the false positive reported in #30004.

  • packages/core/src/utils/untrustedContextTracker.ts: UntrustedFlagOptions
    gains projectTempDir; isWorkspaceLocalPath() now also accepts paths below
    it via isSubpath(), and isPathWithinWorkspace is optional so the temp-dir
    exemption works without a workspace callback.
  • packages/core/src/tools/shell.ts: passes
    config.storage?.getProjectTempDir() when finding untrusted flags.

This mirrors the project temp directory trust that Config.isPathAllowed()
already applies for file access.

The remaining issue items are intentionally unchanged here: executable scripts,
URLs, and paths with shell expansions (~, $VAR) stay out of the
workspace-local exemption, and output from remote-retrieval commands keeps
external provenance, per #29833. The settings toggle is a separate design
decision.

Related Issues

Related to #30004

How to Validate

  • npm test -w @google/gemini-cli-core -- src/utils/untrustedContextTracker.test.ts src/tools/shell.test.ts
    • New tests: should not flag project temp paths that appeared in local shell output
      and should not flag project temp paths printed by earlier shell output.
      Both fail before the change and pass after it.
  • Manual check: in a session, run a command whose output names a file under the
    project temp directory (for example a traceback), then run python3 <path>.
    No confirmation should appear in YOLO mode. Paths outside both the workspace
    and the project temp directory are still reported.
  • npm run preflight passed locally (Linux, Node 20.19.0) on the initial
    commit; the review follow-up was validated with the affected suites, ESLint,
    Prettier, and the core tsc check.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

FindUntrustedFlags reported the agent's own files under the session's
project temp directory as untrusted arguments, because only the workspace
was treated as local. Shell output such as a Python traceback mentioning
~/.gemini/tmp/<session>/parse_pr.py then forced a confirmation even in
YOLO mode.

Pass config.storage.getProjectTempDir() through the flag options and
treat paths below it as local, matching the temp directory trust already
used for file access. Executable scripts, URLs, shell expansions, and
remote output keep their existing handling.

Refs google-gemini#30004.
@moah0911
moah0911 requested review from a team as code owners October 29, 2026 07:41
@github-actions github-actions Bot added the size/m A medium sized PR label Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 73
  • Additions: +67
  • Deletions: -6
  • Files changed: 4

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a false positive issue where the Gemini CLI incorrectly flagged its own helper scripts as untrusted when they appeared in shell output (e.g., tracebacks). By including the project's temporary directory in the workspace-local exemption logic, the agent can now safely reference these paths without triggering unnecessary confirmation prompts in YOLO mode.

Highlights

  • Untrusted Flag Detection: Updated the untrusted flag detection logic to treat the project's temporary directory as a local, trusted path, preventing false positives when helper scripts are referenced in shell output.
  • Configuration Updates: Extended UntrustedFlagOptions to include projectTempDir and updated ShellToolInvocation to pass this directory during flag validation.
  • Testing: Added new test cases in shell.test.ts and untrustedContextTracker.test.ts to verify that paths within the project temp directory are correctly identified as local.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for ignoring session-scoped temporary directories when detecting untrusted execution paths in the shell tool. It updates UntrustedFlagOptions to include projectTempDir and modifies isWorkspaceLocalPath to treat paths within this directory as trusted. The feedback recommends improving robustness by safely handling optional properties: specifically, using optional chaining when accessing config.storage in shell.ts and ensuring isPathWithinWorkspace is treated as optional in isWorkspaceLocalPath to prevent potential runtime errors.

Comment on lines +320 to +324
return (
options.isPathWithinWorkspace(absolutePath) ||
(options.projectTempDir !== undefined &&
isSubpath(options.projectTempDir, absolutePath))
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In isWorkspaceLocalPath, options.isPathWithinWorkspace is called directly as a function, but the UntrustedFlagOptions interface defines isPathWithinWorkspace as an optional property. If a caller provides projectTempDir but omits isPathWithinWorkspace, the function currently returns false early due to the check !options.isPathWithinWorkspace on line 310 (outside the diff).

To make the function robust and adhere to the interface contract where both properties are optional, we should allow isPathWithinWorkspace to be optional and only invoke it if defined, while still allowing projectTempDir checks to proceed.

Please update the early return check to not require isPathWithinWorkspace if projectTempDir is provided, and use optional chaining when invoking isPathWithinWorkspace.

    return (
      (options.isPathWithinWorkspace !== undefined &&
        options.isPathWithinWorkspace(absolutePath)) ||
      (options.projectTempDir !== undefined &&
        isSubpath(options.projectTempDir, absolutePath))
    );
References
  1. When consuming an object, if a property is optional in its type definition (interface), callers must handle the undefined case. Do not rely on the implementation details of the function that creates the object to always provide a value, as this can change. Code against the interface contract.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in ce8c4e3: isPathWithinWorkspace is now optional in isWorkspaceLocalPath, the early return no longer requires it, and the temp-dir exemption works without a workspace callback. Added coverage for the temp-dir-only options case.

Comment thread packages/core/src/tools/shell.ts Outdated
@gemini-cli gemini-cli Bot added the area/security Issues related to security label Oct 29, 2026
Make isPathWithinWorkspace optional in isWorkspaceLocalPath so the
projectTempDir exemption applies when callers omit the workspace callback,
and use optional chaining when reading config.storage. Add coverage for
the temp-dir-only options case.

This branch is waiting to be deployed

1 waiting deployment
eval-gate — ce8c4e3c Waiting Oct 29, 2026 by moah0911 via Evaluate Steering & Regressions #2270
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/security Issues related to security size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant