fix(core): handle nested plan files by resolving paths correctly#24854
fix(core): handle nested plan files by resolving paths correctly#24854mahimashanware wants to merge 1 commit intoworktree-con-plan-bugfrom
Conversation
|
Hi @mahimashanware, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
🧠 Model Steering GuidanceThis PR modifies files that affect the model's behavior (prompts, tools, or instructions).
This is an automated guidance message triggered by steering logic signatures. |
f403b78 to
fd8cfad
Compare
This fixes a bug where path.basename was incorrectly stripping directory structures from plan files (e.g., trying to write to plans/nested/file.md would incorrectly write to plans/file.md). By using path.resolve and verifying with isSubpath, nested files are now handled securely and correctly.
229d2ca to
81ac743
Compare
🛑 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. |
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 addresses a critical bug that prevented the correct handling of nested plan files by misinterpreting their paths. By transitioning from 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 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 counter productive. 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
|
There was a problem hiding this comment.
Code Review
This pull request enhances security for the EditTool and WriteFileTool by implementing stricter path validation in 'plan mode.' It replaces path.basename with path.resolve and uses isSubpath to verify that all file operations occur within the designated plans directory. Review feedback suggests refactoring the duplicated path resolution logic into a shared utility and trimming tool parameters to ensure robust validation.
| const resolvedPlanPath = path.resolve(plansDir, this.params.file_path); | ||
| if (!isSubpath(plansDir, resolvedPlanPath)) { | ||
| throw new Error( | ||
| `Security violation: plan path (${this.params.file_path}) must be within the designated plans directory (${plansDir}).`, | ||
| ); | ||
| } | ||
| this.resolvedPath = resolvedPlanPath; |
There was a problem hiding this comment.
The path resolution logic for plan files is duplicated in both EditToolInvocation and EditTool.validateToolParamValues. To ensure consistent and robust validation, refactor this into a shared utility using resolveToRealPath. Additionally, ensure that tool parameters are trimmed before validation to prevent whitespace-only values from being accepted.
References
- Ensure consistent path resolution by using a single, robust function (e.g., resolveToRealPath) for all related path validations.
- When validating string parameters from tools, trim the string first and then check for emptiness to prevent whitespace-only values from being accepted.
| const resolvedPlanPath = path.resolve(plansDir, this.params.file_path); | ||
| if (!isSubpath(plansDir, resolvedPlanPath)) { | ||
| throw new Error( | ||
| `Security violation: plan path (${this.params.file_path}) must be within the designated plans directory (${plansDir}).`, | ||
| ); | ||
| } | ||
| this.resolvedPath = resolvedPlanPath; |
There was a problem hiding this comment.
Similar to the EditTool, the path resolution and security checks for plan files are duplicated. Refactoring this into a common utility using resolveToRealPath would improve maintainability and ensure consistent security enforcement. Also, ensure tool parameters are trimmed before checking for emptiness in validateToolParamValues to align with repository security standards.
References
- Ensure consistent path resolution by using a single, robust function (e.g., resolveToRealPath) for all related path validations.
- When validating string parameters from tools, trim the string first and then check for emptiness to prevent whitespace-only values from being accepted.
Summary
This fixes a bug where
path.basenamewas incorrectly stripping directory structures from plan files (e.g., trying to write toplans/nested/file.mdwould incorrectly write toplans/file.md). By usingpath.resolveand verifying withisSubpath, nested files are now handled securely and correctly.Details
path.basenamelogic inedit.ts,write-file.ts, andplanUtils.tswith proper path resolution.Fixes #24961