fix(core): prevent infinite recursion in symlink resolution#21750
fix(core): prevent infinite recursion in symlink resolution#21750
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 the robustness and security of the path resolution mechanism by introducing safeguards against infinite recursion in symlink structures. It ensures that the application can gracefully handle malicious or circular symlinks without crashing or hanging, thereby improving system stability and preventing potential denial-of-service scenarios. Highlights
Changelog
Activity
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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Thank you for linking an issue! This pull request has been automatically reopened. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly addresses a potential infinite recursion vulnerability in symlink resolution by tracking visited paths. The implementation is sound and includes a good unit test to verify the fix. I have one suggestion regarding test hygiene to prevent mock pollution in the test suite, which will improve the long-term maintainability of the tests.
|
Size Change: +413 B (0%) Total Size: 26 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request introduces a crucial security fix to prevent infinite recursion when resolving symbolic links, addressing a potential denial-of-service vulnerability. The implementation correctly uses a visited set for cycle detection, and the new unit test effectively validates this behavior. However, the current implementation is vulnerable to a bypass on case-insensitive filesystems (Windows/macOS) due to a case-sensitive recursion check, which could allow a malicious symlink structure to trigger a Denial of Service. This highlights the importance of robust and consistent path resolution, as outlined in our security rules for path handling. A high-severity suggestion is provided to ensure effective cycle detection on case-insensitive filesystems, aligning with the need for utility functions to internally validate path inputs and prevent path traversal vulnerabilities.
|
/patch preview |
|
✅ Patch workflow(s) dispatched successfully! 📋 Details:
🔗 Track Progress: |
|
🚀 Patch PR Created! 📋 Patch Details:
📝 Next Steps:
🔗 Track Progress: |
|
🚀 Patch Release Started! 📋 Release Details:
⏳ Status: The patch release is now running. You'll receive another update when it completes. 🔗 Track Progress: |
|
✅ Patch Release Complete! 📦 Release Details:
🎉 Status: Your patch has been successfully released and published to npm! 📝 What's Available:
🔗 Links: |
Summary
This PR adds infinite recursion protection to the
resolveToRealPathutility. It prevents the process from hanging or crashing when encountering malicious or circular symlink structures thatfs.realpathSyncmight not handle robustly in all environments.Details
robustRealpathto track visited paths using aSet.Erroris thrown with a descriptive message.packages/core/src/utils/paths.test.tsthat mocks a malicious symlink structure to verify the recursion detection.Related Issues
Fixes a security vulnerability related to symlink path validation.
#21489
How to Validate
npm test -w @google/gemini-cli-core -- src/utils/paths.test.tsshould prevent infinite recursion on malicious symlink structurespasses.Pre-Merge Checklist