fix(policy): allow loading policy files via symbolic links#20289
fix(policy): allow loading policy files via symbolic links#20289berzrPTH wants to merge 5 commits intogoogle-gemini:mainfrom
Conversation
Summary of ChangesHello @berzrPTH, 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 policy loading mechanism by introducing support for symbolic links, ensuring that policy files referenced through symlinks are correctly discovered and processed. It also significantly improves the robustness of the file reading process by implementing per-file error handling, allowing the system to continue loading other valid policy files even if some are unreadable, and providing comprehensive error reporting. 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for symbolic links when loading policy files, which is a good feature enhancement. The refactoring of readPolicyFiles to gracefully handle file read errors by returning both successfully read files and a list of errors is a solid improvement for robustness.
My review includes two critical security-related points:
- In
packages/core/src/policy/integrity.ts, file read errors are silently ignored during the integrity hash calculation. This could lead to a user unknowingly accepting a weaker set of policies if a file becomes unreadable. I've suggested logging these errors to make this situation visible, aligning with the rule to log detailed errors for debugging. - In
packages/core/src/policy/toml-loader.ts, following symbolic links without validation introduces a path traversal vulnerability. A malicious symlink could cause the application to read sensitive files from outside the intended policy directory. I've recommended adding a check to ensure symlinks point to files within the policy directory, which aligns with rules on resolving symbolic links and sanitizing file paths to prevent path traversal vulnerabilities.
cca29bc to
2bea4f4
Compare
@gemini-code-assist Please review. |
There was a problem hiding this comment.
Code Review
This pull request introduces support for symbolic links in policy file loading and enhances error handling, including a valuable path traversal check for workspace policies. However, it introduces two high-severity security issues: a prototype property access bypass and a Time-of-Check to Time-of-Use (TOCTOU) race condition in the symlink validation. Furthermore, a pre-existing critical vulnerability in the policy integrity hashing logic, allowing hash collisions via a null-byte separator, needs urgent attention. There's also an opportunity to improve performance and error handling within the file reading loop. Addressing these security and performance concerns is crucial.
2bea4f4 to
ec3af46
Compare
|
@gemini-code-assist Please review. |
ec3af46 to
ded335e
Compare
There was a problem hiding this comment.
Code Review
This pull request enhances policy file discovery by adding support for symbolic links. However, it introduces a high-severity path traversal vulnerability because the crucial security check to prevent symlinks from pointing outside the policy directory is only applied to 'workspace' policies. This check must be extended to all policy tiers to prevent attackers from reading arbitrary files. Additionally, while the implementation includes a security check for workspace policies and improves robustness by gracefully handling file read errors, there's a performance optimization needed for fs.realpath(baseDir) to avoid repeated asynchronous I/O operations.
|
Open for discussion and review. The PR is now ready for review. |
ca55508 to
1ce06aa
Compare
|
@kschaab PTAL. Rebased and fixed the test. |
Update readPolicyFiles to include symbolic links in the directory scan by checking `entry.isSymbolicLink()`. Add defensive error handling within the file-reading loop to prevent a single unreadable file from crashing the entire directory load.
…ding Refactor `readPolicyFiles` to return a result object containing both successfully read files and a list of errors. This enables the policy engine to load all valid rules while explicitly tracking and reporting failures (e.g., broken symlinks) instead of silently skipping them or aborting the entire tier load. Update callers in `toml-loader.ts` and `integrity.ts` to handle the new return signature.
Harden security by verifying that symbolic links in the 'workspace' tier resolve to paths within the intended policy directory. This mitigates potential data exfiltration risks from malicious repositories while maintaining flexibility for user-owned global policies.
Update the PolicyIntegrityManager to pass the policy scope down to the loader, ensuring that the correct security rules (like symlink restrictions) apply during hashing. Implement a clean lookup mapping for scopes and add explicit logging for any unreadable policy files discovered during the integrity check to improve debuggability.
…ment The change is required following the introduction of path traversal protection in readPolicyFiles, which uses fs.realpath to resolve policy paths.
1ce06aa to
e781e7b
Compare
|
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 have updated our contribution policy (see Discussion #17383). We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'. This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community! |
|
Since the commit was automatically closed. I may just keep the branch as is. |
Summary
Policy files (*.toml) discovered via directory scanning were previously
filtered using strictly
entry.isFile(), silently ignoring valid filesthat were symlinks.
This commit updates the directory filter to include symbolic links.
Furthermore, it refactors the file reading loop inside
readPolicyFilesto return an object containing both successfully read files and any
accumulated read errors. This ensures that a single unreadable file
(e.g., a broken symlink or an unreadable directory ending in .toml)
gracefully reports its error instead of throwing an exception and
causing the entire policy directory to be skipped.
Details
Changes:
isSymbolicLink()infs.readdirfilter for policy files.try...catchtoreadPolicyFilesfor robust loading.readPolicyFilesreturn type to{ files, errors }to passerrors without breaking the directory loading loop.
readPolicyFilesintoml-loader.tsandintegrity.tsto accommodate the new signature.Related Issues
#20281
How to Validate
Pass the test:
npm test -w @google/gemini-cli-core -- src/policy/toml-loader.test.tsPre-Merge Checklist
- [ ] Updated relevant documentation and README (if needed)- [ ] Added/updated tests (if needed)- [ ] Noted breaking changes (if any)Misc.
I'm relatively new to the TypeScript and the change is developed by me and Gemini CLI. Any guidance would be greatly appreciated.