Skip to content

fix(core): handle nested plan files by resolving paths correctly#24854

Open
mahimashanware wants to merge 1 commit intoworktree-con-plan-bugfrom
fix/nested-plan-files-v2
Open

fix(core): handle nested plan files by resolving paths correctly#24854
mahimashanware wants to merge 1 commit intoworktree-con-plan-bugfrom
fix/nested-plan-files-v2

Conversation

@mahimashanware
Copy link
Copy Markdown
Contributor

@mahimashanware mahimashanware commented Apr 7, 2026

Summary

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.

Details

  • Replaced path.basename logic in edit.ts, write-file.ts, and planUtils.ts with proper path resolution.
  • Updated the path boundary validations to ensure malicious paths still fail securely.

Fixes #24961

@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Apr 7, 2026

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!

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

🧠 Model Steering Guidance

This PR modifies files that affect the model's behavior (prompts, tools, or instructions).

  • ⚠️ Consider adding Evals: No behavioral evaluations (evals/*.eval.ts) were added or updated in this PR. Consider adding a test case to verify the new behavior and prevent regressions.
  • 🚀 Maintainer Reminder: Please ensure that these changes do not regress results on benchmark evals before merging.

This is an automated guidance message triggered by steering logic signatures.

@mahimashanware mahimashanware force-pushed the worktree-con-plan-bug branch from f403b78 to fd8cfad Compare April 8, 2026 16:37
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.
@mahimashanware mahimashanware force-pushed the fix/nested-plan-files-v2 branch from 229d2ca to 81ac743 Compare April 8, 2026 20:06
@mahimashanware mahimashanware requested a review from jerop April 8, 2026 20:17
@gemini-cli gemini-cli bot added the area/extensions Issues related to Gemini CLI extensions capability label Apr 8, 2026
@mahimashanware mahimashanware marked this pull request as ready for review April 8, 2026 20:45
@mahimashanware mahimashanware requested review from a team as code owners April 8, 2026 20:45
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

🛑 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 critical bug that prevented the correct handling of nested plan files by misinterpreting their paths. By transitioning from path.basename to a more robust path.resolve and incorporating isSubpath validation, the system now accurately processes and secures file paths within the plans directory. This enhancement not only fixes the immediate issue of incorrect file writes but also significantly bolsters security against potential path traversal attacks, ensuring all file operations remain confined to their intended scope.

Highlights

  • Nested Plan File Handling: Corrected a bug where path.basename incorrectly stripped directory structures from plan file paths, leading to incorrect file writes for nested files.
  • Secure Path Resolution: Implemented path.resolve and isSubpath checks to ensure plan files are handled securely and correctly within their designated directories, preventing path traversal vulnerabilities.
  • Code Refactoring: Replaced path.basename logic with proper path resolution in edit.ts, write-file.ts, and planUtils.ts to support nested paths.
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 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 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

  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.

Copy link
Copy Markdown
Contributor

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

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

Comment on lines +468 to +474
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;
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

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
  1. Ensure consistent path resolution by using a single, robust function (e.g., resolveToRealPath) for all related path validations.
  2. When validating string parameters from tools, trim the string first and then check for emptiness to prevent whitespace-only values from being accepted.

Comment on lines +171 to +177
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;
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

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
  1. Ensure consistent path resolution by using a single, robust function (e.g., resolveToRealPath) for all related path validations.
  2. When validating string parameters from tools, trim the string first and then check for emptiness to prevent whitespace-only values from being accepted.

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

Labels

area/extensions Issues related to Gemini CLI extensions capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant