fix(security): restore defensive path resolution for at-reference files (re-applies #27943) - #28180
Conversation
|
📊 PR Size: size/L
|
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
There was a problem hiding this comment.
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.
|
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. |
|
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. |
Summary
This PR re-applies the security fix from #27943 that was reverted in #27992.
The revert removed
resolveDefensiveToolPathandresolveToRealPathfrom theread_file,write_file, andedittools, 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:workspace/link -> /etc/passwdlinkvalidatePathAccess("workspace/link")passes — the symlink path is inside workspace/etc/passwd— outside workspaceThe reverted fix addressed this by calling
resolveToRealPath()(which resolves symlinks viafs.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:
../../sequences@-prefixed path strippingcc: original author @luisfelipe-alt