Conversation
…links gracefully Updates the policy TOML loader to correctly follow symlinked files and directories. This ensures that users can symbolically link policies across workspaces or fallback paths without the loader failing. Key changes: - Refactored readPolicyFiles to follow symlinks using fs.realpath. - Added recursion for symlinked directories with a visitedPaths tracker to prevent infinite circular traversal. - Added error handling within the directory scanning loop to catch and ignore ENOENT errors, ensuring that broken symlinks do not silently abort the loading of other valid policies in the same directory. - Added comprehensive unit tests for standard symlink behavior, circular symlink protection, and broken symlink resilience. - Updated mocked fs calls in tests to support realpath.
|
Size Change: +468 B (0%) Total Size: 34.1 MB
ℹ️ View Unchanged
|
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 significantly enhances the policy TOML loader by introducing robust support for symbolic links. It ensures that policy files and directories can be correctly resolved and loaded even when they are symlinked, which is crucial for flexible workspace configurations. The changes prevent common issues like infinite loops from circular symlinks and gracefully handle non-existent targets, making the policy loading mechanism more resilient and user-friendly. 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 introduces support for symlinks and recursive directory traversal when loading policy files. It includes circularity detection to prevent infinite loops and updates the test suite to cover these new scenarios. A security concern was raised regarding the potential for path traversal or local file inclusion (LFI) because symlinks are followed without verifying if the target resides within an allowed boundary, which could lead to the exposure of sensitive system files.
| const entryStats = await fs.stat(entryPath); | ||
|
|
||
| if (entryStats.isDirectory()) { | ||
| // Recursive call | ||
| results.push(...(await readPolicyFiles(entryPath, visitedPaths))); | ||
| } else if (entryStats.isFile() && entry.name.endsWith('.toml')) { | ||
| const content = await fs.readFile(entryPath, 'utf-8'); | ||
| results.push({ path: entryPath, content }); |
There was a problem hiding this comment.
The readPolicyFiles function follows symbolic links when scanning for policy files and does not verify if the link target is within the intended directory. A malicious repository could include a symlink named with a .toml extension (e.g., exploit.toml) that points to a sensitive file on the user's machine (such as ~/.ssh/id_rsa or ~/.bash_history). When a user runs the tool within such a repository, the tool will attempt to read and parse the linked file. If the file is not a valid TOML, the resulting error message—which is emitted to the user's terminal—may contain portions of the sensitive file's content, leading to information exposure.
To mitigate this, consider restricting symlink following for workspace-level policies, or implement a check to ensure the target of a symlink is within an allowed boundary (e.g., the same directory or the project root).
Summary
Updates the policy TOML loader to correctly follow symlinked files and directories. This ensures that users can symbolically link policies across workspaces or fallback paths without the loader failing.
Key changes:
Related Issues
Fixes #20281, #21031
How to Validate
To validate locally using this branch, the following test case should work assuming you already have policy files in ~/.gemini/policies:
ln -s ~/tmp/redirected/policies ~/.gemini/policiesnpm run startAdditional tests to run is symlinking a policy file, creating nested symlinks, and creating a cycle of symlinks (symlinking the parent real path inside itself).
Pre-Merge Checklist