Repository navigation
fix(core): ensure consistent symlink evaluation in ignore path handling - #28915
DavidAPierce merged 3 commits into
Conversation
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 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
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
|
|
📊 PR Size: size/L
|
There was a problem hiding this comment.
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.
19a3c4c to
0f1f46a
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
2c47fcf to
b438fcc
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
5d4673a to
21e29e2
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
21e29e2 to
4be8fbc
Compare
|
/gemini review |
98885e2 to
c367ed9
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
c367ed9 to
b61e65e
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
b61e65e to
88a3cb4
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
88a3cb4 to
3039274
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
|
✅ 68 tests passed successfully on gemini-3-flash-preview. 🧠 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. |
Summary
This pull request improves path normalization and ignore pattern evaluation across symbolic links in
@google/gemini-cli-core. It ensures that.geminiignoreand.gitignorerules 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
FileDiscoveryServiceFileDiscoveryService._shouldIgnore.fs.lstatSync(absolutePath, { throwIfNoEntry: false })to inspect link status without adding I/O overhead for regular files.resolveToRealPath.try/catch) to ensure broken or dangling symbolic links degrade safely without unhandled exceptions.getNormalizedRelativePathas a pure string operation, preventing quadratic I/O latency inGitIgnoreParserancestor traversal loops.2. Tool Boundary Verification in
ReadFileToolReadFileTool.validateToolParamValuesto evaluateshouldIgnoreFileon both the input parameter (sanitizedPath) and the canonical target path (resolvedPath).read_many_files,grep,glob) and search utilities automatically inherit consistent ignore handling viaFileDiscoveryService.filterFilesWithReport().3. Automated Test Coverage
packages/core/src/services/fileDiscoveryService.symlink.test.tscovering:Related Issues
How to Validate
1. Run the Symlink Unit Tests
npm test -w @google/gemini-cli-core -- src/services/fileDiscoveryService.symlink.test.tsExpected Result: 4 passed / 4 tests (100% SUCCESS).
2. Run Tool Boundary Tests
npm test -w @google/gemini-cli-core -- src/tools/read-file.test.tsExpected Result: 37 passed / 37 tests (100% SUCCESS).
3. Run Quality & Type Checks
Expected Result: 0 errors, 0 warnings across all workspaces.
4. Full Pipeline Verification
Expected Result: Clean, Install, Build, Lint, Typecheck, and Unit Tests all complete with
SUCCESS.Pre-Merge Checklist