Skip to content

fix(core): ensure consistent symlink evaluation in ignore path handling - #28915

Merged
DavidAPierce merged 3 commits into
google-gemini:mainfrom
luisfelipe-alt:bugfix/WT-engineer_465457725
Aug 20, 2026
Merged

DavidAPierce merged 3 commits into
google-gemini:mainfrom
luisfelipe-alt:bugfix/WT-engineer_465457725

Conversation

@luisfelipe-alt

@luisfelipe-alt luisfelipe-alt commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This pull request improves path normalization and ignore pattern evaluation across symbolic links in @google/gemini-cli-core. It ensures that .geminiignore and .gitignore rules are consistently evaluated against both literal paths and resolved canonical paths, eliminating tool behavioral asymmetries while preserving optimal linear file traversal performance.


Details

1. Centralized Symlink Evaluation in FileDiscoveryService

  • Hoisted symbolic link canonicalization to FileDiscoveryService._shouldIgnore.
  • Added a fast filesystem guard using fs.lstatSync(absolutePath, { throwIfNoEntry: false }) to inspect link status without adding I/O overhead for regular files.
  • Implemented fail-closed evaluation: if a symbolic link is detected, ignore patterns are evaluated against both the literal path and the canonical real path resolved via resolveToRealPath.
  • Added graceful error handling (try/catch) to ensure broken or dangling symbolic links degrade safely without unhandled exceptions.
  • Preserved getNormalizedRelativePath as a pure string operation, preventing quadratic I/O latency in GitIgnoreParser ancestor traversal loops.

2. Tool Boundary Verification in ReadFileTool

  • Updated ReadFileTool.validateToolParamValues to evaluate shouldIgnoreFile on both the input parameter (sanitizedPath) and the canonical target path (resolvedPath).
  • Multi-file tools (read_many_files, grep, glob) and search utilities automatically inherit consistent ignore handling via FileDiscoveryService.filterFilesWithReport().

3. Automated Test Coverage

  • Added a dedicated unit test suite in packages/core/src/services/fileDiscoveryService.symlink.test.ts covering:
    • In-workspace unignored symbolic link pointing to an ignored target file (Scenario A).
    • In-workspace ignored symbolic link pointing to an unignored target file (Scenario B).
    • Broken/dangling symbolic link resilience (Scenario C).
    • Filter report generation for mixed file/symlink lists.

Related Issues


How to Validate

1. Run the Symlink Unit Tests

npm test -w @google/gemini-cli-core -- src/services/fileDiscoveryService.symlink.test.ts

Expected Result: 4 passed / 4 tests (100% SUCCESS).

2. Run Tool Boundary Tests

npm test -w @google/gemini-cli-core -- src/tools/read-file.test.ts

Expected Result: 37 passed / 37 tests (100% SUCCESS).

3. Run Quality & Type Checks

npm run lint
npm run typecheck

Expected Result: 0 errors, 0 warnings across all workspaces.

4. Full Pipeline Verification

./test-check.sh

Expected Result: Clean, Install, Build, Lint, Typecheck, and Unit Tests all complete with SUCCESS.


Pre-Merge Checklist

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

@luisfelipe-alt
luisfelipe-alt requested review from a team as code owners August 19, 2026 18:09
@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 enhances path normalization and ignore pattern evaluation for symbolic links within the core CLI package. By ensuring that both literal and resolved paths are evaluated against ignore rules, the changes eliminate behavioral inconsistencies while maintaining efficient file traversal performance. The update also improves the robustness of file discovery by safely handling broken symbolic links.

Highlights

  • Symlink Ignore Logic: Centralized symlink evaluation in FileDiscoveryService to ensure ignore patterns are checked against both literal and canonical paths.
  • Resilience: Implemented fail-closed evaluation with graceful error handling for broken or dangling symbolic links.
  • Tool Integration: Updated ReadFileTool to validate ignore rules on both input and resolved paths, ensuring consistency across multi-file tools.
  • Testing: Added a comprehensive unit test suite covering various symlink scenarios, including ignored targets and broken links.
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 github-actions Bot added the size/m A medium sized PR label Aug 19, 2026
@github-actions

github-actions Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 305
  • Additions: +293
  • Deletions: -12
  • Files changed: 6

@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Aug 19, 2026

@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 symlink ignore handling to FileDiscoveryService by resolving symbolic links to their real paths and checking them against ignore filters, accompanied by a new test suite. It also updates ReadFileTool to check both sanitized and resolved paths. The review feedback points out a performance issue where synchronous I/O (fs.lstatSync) is used within _shouldIgnore, which blocks the event loop during directory traversal, and recommends refactoring to asynchronous operations.

@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 enhances the FileDiscoveryService to correctly handle symbolic links by resolving them to their real paths and checking them against ignore filters. It also updates the ReadFileTool to validate both sanitized and resolved paths, and introduces a comprehensive suite of unit tests for symlink ignore scenarios. No review comments were provided, and the implementation is clean and well-tested.

- Enforce symlink canonicalization in FileDiscoveryService._shouldIgnore to ensure .geminiignore and .gitignore patterns are evaluated against both literal paths and resolved canonical paths.

- Guard symlink resolution with fs.lstatSync to maintain optimal linear traversal performance.

- Update ReadFileTool.validateToolParamValues to evaluate input paths and resolved paths against ignore rules.

- Add comprehensive Vitest unit test suite covering symlink ignore filtering, target resolution, and broken link handling.
@luisfelipe-alt
luisfelipe-alt force-pushed the bugfix/WT-engineer_465457725 branch from 2c47fcf to b438fcc Compare August 19, 2026 19:59
@github-actions github-actions Bot added the size/l A large sized PR label Aug 19, 2026
@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 enhances symbolic link and cross-platform path resolution handling across the file discovery and utility services, adding comprehensive test coverage. The review feedback highlights critical security and correctness issues, including a potential path traversal vulnerability in isWithinRoot due to premature symlink bypass, an ignore pattern bypass when parent directories are symlinks, and recommendations to consistently use resolveToRealPath in ignorePathUtils for robust path resolution.

Comment thread packages/core/src/utils/fileUtils.ts Resolved
@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 introduces symbolic link ignore handling to the FileDiscoveryService, along with comprehensive unit tests and cross-platform path resolution fixes for macOS symlink aliases (such as /var vs /private/var). While these changes improve correctness, the code reviewer identified significant performance concerns on macOS due to heavy synchronous I/O from unconditional or frequent calls to resolveToRealPath. To address this, the reviewer recommends adding a fast filesystem guard using fs.lstatSync in _shouldIgnore to only resolve paths for actual symbolic links, and implementing fast, string-based canonicalization of common macOS prefixes in isWithinRoot and getNormalizedRelativePath to avoid triggering synchronous filesystem I/O entirely for standard paths.

Comment thread packages/core/src/utils/fileUtils.ts Resolved
@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 introduces robust symbolic link handling and macOS path canonicalization (resolving /private prefix discrepancies) in the file discovery and ignore services, alongside a comprehensive test suite for symlink ignore scenarios. A key feedback point is that when evaluating a symbolic link, the target path may point to a directory. If isDirectory is passed as false, directory-only ignore patterns will fail to match the resolved real path. Dynamically checking if the resolved target path is a directory using fs.statSync is recommended to ensure correctness.

@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 introduces robust symlink ignore handling and macOS-specific path canonicalization (addressing /private symlink aliases) across FileDiscoveryService, ReadFileTool, and path utilities, accompanied by comprehensive test coverage. The review feedback highlights three key areas for improvement: removing a redundant shouldIgnoreFile call in read-file.ts to prevent duplicate I/O, consolidating duplicated symlink resolution logic in fileDiscoveryService.ts, and updating canonicalizeMacosPath in fileUtils.ts to handle exact paths like /var or /tmp without trailing slashes.

Comment thread packages/core/src/tools/read-file.ts Resolved
Comment thread packages/core/src/utils/fileUtils.ts Resolved

@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 introduces symlink ignore handling in FileDiscoveryService and addresses cross-platform path resolution discrepancies on macOS (such as /private/var vs /var) in path utility functions. The review feedback suggests refactoring duplicated symlink checking logic in FileDiscoveryService, enhancing canonicalizeMacosPath to handle exact matches of system directories, and removing redundant path.resolve calls in ignorePathUtils.

Comment thread packages/core/src/utils/fileUtils.ts Resolved
@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 introduces comprehensive symlink ignore handling in FileDiscoveryService, including cross-platform path canonicalization for macOS /private paths. However, a security review identified a potential bypass vulnerability in ReadFileTool where evaluating shouldIgnoreFile only on sanitizedPath could allow access to files inside ignored directories if accessed via a parent directory symlink. It is recommended to check both the unresolved sanitizedPath and the fully resolved resolvedPath to prevent this bypass.

Comment thread packages/core/src/tools/read-file.ts Resolved
@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 enhances symbolic link handling and macOS path canonicalization across the file discovery and ignore utilities. Key changes include updating FileDiscoveryService to resolve symlinks to their real paths before applying ignore filters, adding macOS-specific path normalization for /var, /tmp, and /etc paths, and expanding test coverage for symlink scenarios. Additionally, ReadFileTool now checks both sanitized and resolved paths, and test environment variables are updated for UTF-8 encoding. No review comments were provided, so there is no additional feedback.

@github-actions

Copy link
Copy Markdown

✅ 68 tests passed successfully on gemini-3-flash-preview.

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

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

This branch was previously deployed

1 inactive deployment
eval-gate — 30392749 Deployed Aug 20, 2026 by luisfelipe-alt via Evaluate Steering & Regressions #1829
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l A large sized PR size/m A medium sized PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants