Repository navigation
fix(core): mitigate NTFS 8.3 short name (SFN) path - #29116
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 addresses critical security vulnerabilities related to path traversal and blocklist bypasses on Windows NTFS filesystems. By explicitly handling 8.3 short name patterns and ensuring canonical path resolution, the safety engine is now better equipped to prevent unauthorized access to sensitive directories. 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
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
📊 PR Size: size/L
|
There was a problem hiding this comment.
Code Review
This pull request enhances path safety checks by blocking NTFS 8.3 short names (SFNs) such as git1, env1, node_m1, and vscode1 to prevent security bypasses. It also updates robustRealpath to use fs.realpathSync.native on Windows. The review feedback highlights a potential issue where fs.realpathSync.native returns paths prefixed with volume namespaces on Windows, which can cause path comparison mismatches. It is recommended to strip these prefixes to ensure consistent path operations.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances path safety checks by blocking NTFS 8.3 short names (SFNs) for sensitive directories and improves Windows path resolution by handling UNC and long path prefixes. The review feedback correctly identifies a critical security bypass where NTFS collision-based SFN generation (e.g., using hexadecimal hashes) could evade the current blocklist, and provides actionable regex suggestions to mitigate this vulnerability.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances path safety checks and path resolution, particularly on Windows. It updates the AllowedPathChecker to block NTFS 8.3 short names (SFNs) and collision-based SFN formats for sensitive directories like .git, .env, node_modules, and .vscode. Additionally, it updates robustRealpath to use fs.realpathSync.native on Windows and correctly strip long path prefixes and UNC prefixes. Corresponding unit tests have been added to verify these security and path resolution improvements. I have no feedback to provide as the changes are well-implemented and covered by tests.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances path validation and resolution security, particularly on Windows. It updates AllowedPathChecker to block sensitive paths specified via NTFS 8.3 short names (SFNs) and collision-based SFN formats for .git, .env, node_modules, and .vscode. Additionally, it updates robustRealpath to use fs.realpathSync.native on Windows and correctly strip Windows long path prefixes (UNC and standard). Corresponding unit tests have been added to verify these changes. I have no further feedback to provide.
|
/Gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for detecting and blocking NTFS 8.3 short names (SFNs) in the AllowedPathChecker to prevent security bypasses. It also updates robustRealpath on Windows to use fs.realpathSync.native and correctly normalize long path prefixes (such as \?\ and \?\UNC\). Comprehensive unit tests have been added to verify these changes. I have no feedback to provide as there are no review comments.
…les tests Updates packages/core/src/tools/read-many-files.test.ts to use resolveToRealPath when resolving temporary directories. This expands NTFS 8.3 short paths (SFNs) to canonical long names on Windows, resolving the final slow-test mismatch without affecting Linux or macOS.
|
/Gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances path validation and normalization to prevent security bypasses on Windows, specifically addressing NTFS 8.3 short names (SFNs) and long path prefixes (such as \?\ and \?\UNC\). It centralizes path-blocking logic into a new hasBlockedPathSegment utility that identifies blocked segments like .git, .env, node_modules, and gha-creds-*.json along with their SFN variations. Additionally, various tests and utilities have been updated to use resolveToRealPath for canonical path resolution. There are no review comments, so I have no feedback to provide.
Note: Security Review did not run due to the size of the PR.
Adds a type check 'typeof resolved === string' in robustRealpath on Windows before slicing the prefix. This prevents TypeError crashes during testing on Windows when fs.realpathSync is stubbed/mocked and returns undefined.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces robust path validation and security checks, specifically addressing NTFS 8.3 short name (SFN) bypasses and Windows long path prefixes. It centralizes path segment blocking logic into a new helper function hasBlockedPathSegment and updates AllowedPathChecker and WorkspaceContext to use it. Additionally, it replaces direct fs.realpathSync calls with resolveToRealPath across various tests and files to ensure canonical resolution. The review feedback suggests optimizing performance by hoisting inline regular expressions used for SFN pattern matching to module-level constants in both paths.ts and built-in.ts to avoid recreating them inside loops.
Note: Security Review did not run due to the size of the PR.
|
/Gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances security and path resolution robustness by centralizing blocked path segment detection and adding support for NTFS 8.3 short names (SFNs) to prevent bypasses. It introduces a centralized hasBlockedPathSegment utility to identify sensitive paths (such as .git, .env, node_modules, and gha-creds-*.json) using both standard names and SFN regex patterns. Additionally, resolveToRealPath is updated to canonically handle Windows long path prefixes, and direct calls to fs.realpathSync across various test and source files are refactored to use this centralized utility. There are no review comments, and I have no feedback to provide.
Note: Security Review did not run due to the size of the PR.
|
/Gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances path validation and security by introducing robust handling of Windows NTFS 8.3 short names (SFNs) and canonical path resolution. It centralizes path segment blocking logic into hasBlockedPathSegment in paths.ts to cover standard blocked directories (such as .git, .env, node_modules, and gha-creds-*.json) along with their SFN equivalents. Additionally, resolveToRealPath is updated to use fs.realpathSync.native on Windows and strip long path prefixes. The reviewer suggests optimizing the isSubpath check on Windows by only invoking the synchronous resolveToRealPath when a path contains a tilde (~), which is a characteristic of SFNs, thereby avoiding unnecessary filesystem I/O performance bottlenecks.
|
/Gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances path validation and resolution security, specifically addressing potential bypasses on Windows using NTFS 8.3 short names (SFNs) and long path prefixes. It centralizes path-blocking checks into a new hasBlockedPathSegment utility that detects sensitive paths (such as .git, .env, node_modules, and GitHub Actions credentials) and their SFN equivalents. Additionally, resolveToRealPath is updated to canonically handle Windows long path prefixes using fs.realpathSync.native. Extensive unit tests have been added to verify these security controls. There are no review comments, and I have no feedback to provide.
|
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. |
Summary
This PR mitigates path traversal and blocklist not allowed paths on NTFS filesystems by handling Windows short names (SFNs, e.g.
git~1,env~1,node_m~1andvscode~1) in both path normalization and the AllowedPathChecker safety engine.Details
git~,env~,node_m~,vscode~) followed by digits.fs.realpathSync.nativewhen available on win32 to guarantee canonicalization of short names to longnames prior to check.
built-in.test.tsandpaths.test.tstargeting NTFS 8.3 short name scenarios.Related Issues
Closes Bug 462382408
How to Validate
Run the core unit tests:
npm test -w @google/gemini-cli-core -- src/safety/built-in.test.ts src/utils/paths.test.ts
Verify that the tests run successfully and all test cases (including NTFS 8.3 short names and case-insensitive check scenarios) pass.
Pre-Merge Checklist