Skip to content

fix(security): restore defensive path resolution for at-reference files (re-applies #27943) - #28180

Closed
XananasX7 wants to merge 1 commit into
google-gemini:mainfrom
XananasX7:fix/security-restore-path-traversal-symlink-defense
Closed

fix(security): restore defensive path resolution for at-reference files (re-applies #27943)#28180
XananasX7 wants to merge 1 commit into
google-gemini:mainfrom
XananasX7:fix/security-restore-path-traversal-symlink-defense

Conversation

@XananasX7

Copy link
Copy Markdown

Summary

This PR re-applies the security fix from #27943 that was reverted in #27992.

The revert removed resolveDefensiveToolPath and resolveToRealPath from the read_file, write_file, and edit tools, re-introducing a class of path traversal vulnerabilities via symlinks.

Vulnerability Re-introduced by the Revert

Without symlink resolution before validatePathAccess, the following attack is possible:

  1. An attacker places a symlink inside the workspace: workspace/link -> /etc/passwd
  2. An AI tool is instructed to read/write link
  3. validatePathAccess("workspace/link") passes — the symlink path is inside workspace
  4. The actual filesystem operation follows the symlink to /etc/passwd — outside workspace

The reverted fix addressed this by calling resolveToRealPath() (which resolves symlinks via fs.realpathSync) before performing the workspace boundary check.

This PR

Cherry-picks commit f741d032 (the original security fix) back onto main, since the revert (4d3dcdce) removed it without a replacement mitigation.

The original PR #27943 included 591 lines of tests covering:

  • Path traversal via ../../ sequences
  • Symlink loop detection
  • @-prefixed path stripping
  • Plan mode path resolution

cc: original author @luisfelipe-alt

@XananasX7
XananasX7 requested review from a team as code owners June 28, 2026 01:06
@github-actions github-actions Bot added the size/l A large sized PR label Jun 28, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 911
  • Additions: +882
  • Deletions: -29
  • Files changed: 6

@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 restores critical security mitigations that were inadvertently removed in a previous revert. By re-implementing defensive path resolution and symlink canonicalization, it ensures that AI-driven file operations cannot escape the designated workspace boundary, effectively closing a path traversal vulnerability.

Highlights

  • Security Fix Restoration: Re-applies defensive path resolution and symlink handling to prevent path traversal vulnerabilities in AI-driven file operations.
  • Path Validation: Ensures all file operations resolve paths to their real location on the filesystem before performing workspace boundary checks.
  • Testing: Added extensive test coverage for path resolution, symlink handling, and @-reference path stripping.
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.

@github-actions

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 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 implements defensive path resolution and sanitization across file-related tools (edit, read-file, write-file, and pathCorrector) in packages/core. It introduces a new utility function resolveDefensiveToolPath to strip user-facing reference prefixes (like @ or @/) generated by the LLM, and adds a comprehensive test suite in at-reference-resolution.test.ts to validate resolution behavior, path traversal prevention, and symlink loop handling. I have no feedback to provide as there are no review comments.

@gemini-cli

gemini-cli Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'.

This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

@gemini-cli

gemini-cli Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants