Repository navigation
fix(config): enforce strict permission and ownership checks on system-wide configuration paths - #29115
Conversation
|
📊 PR Size: size/XL
|
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 the loading of system-wide configuration files. By implementing platform-specific security validations on both Windows and POSIX, the changes ensure that configuration files are only loaded if they are owned by trusted accounts and possess secure permissions. These measures effectively mitigate risks associated with unauthorized modifications to system settings. 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces synchronous security validation checks for system configuration files and their parent directories on both Windows and POSIX platforms, ensuring they are owned by trusted accounts and not writable by unprivileged users. The feedback highlights three critical issues: a fail-open vulnerability on Windows if the PowerShell execution fails, a POSIX bug where querying symlinks via lstat always fails due to standard 0777 permissions, and the use of an unbounded global Map for caching which should be replaced with a proper LRU cache.
ee481a0 to
f8b54a8
Compare
|
/gemini review |
1 similar comment
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces synchronous security checks for configuration files and their parent directories, integrating them into the settings loading process to prevent loading insecure system settings or defaults. It also adds comprehensive unit tests for these security checks. The review feedback highlights two critical security issues on Windows: first, hardcoded English group names (like 'Users' and 'Everyone') will fail to detect insecure permissions on localized Windows installations, which can be resolved by using language-independent SIDs; second, spawning 'powershell' without an absolute path exposes the application to binary hijacking (CWE-426), which should be mitigated by resolving the absolute path to the system PowerShell executable.
f8b54a8 to
fc06582
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces synchronous security validation for system configuration files and their parent directories on both Windows and POSIX platforms, ensuring that insecure configurations are skipped and warnings are logged. A correctness bug was identified in the caching logic of isPathSecureSync, where the cache key only uses the file path and ignores the expectedType constraint, which can lead to incorrect security check results on subsequent calls.
fc06582 to
fe3092f
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces synchronous security checks for system configuration files (system-defaults.json and settings.json) to ensure they and their parent directories are secure on both Windows and POSIX systems. The feedback recommends avoiding module-level global variables for caching, expanding the Windows PowerShell ACL permission checks to include granular rights like CreateFiles and Delete, adding -ExecutionPolicy Bypass to PowerShell invocations to prevent execution failures, and specifying a timeout for synchronous process spawning to avoid potential startup hangs.
fe3092f to
dc22f1d
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces synchronous security validation checks (isPathSecureSync and isFileAndDirectorySecureSync) to ensure system configuration files and their parent directories are secure before loading them, skipping insecure files with a warning. Feedback on these changes highlights two critical security issues: the PowerShell script on Windows uses unanchored substring matching (-match) for owner validation, which could allow unauthorized accounts with similar names to bypass the check, and the POSIX permission constants (S_IWGRP and S_IWOTH) may be undefined on non-POSIX or mocked environments, leading to a silent bypass of the permission checks.
dc22f1d to
05a1028
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces synchronous security validation checks (isPathSecureSync and isFileAndDirectorySecureSync) to ensure that system-wide configuration files and their parent directories are secure before loading them, skipping insecure files and recording warnings. It also adds extensive unit tests for these checks. The review feedback highlights three key areas for improvement: refining the fragile PowerShell output parsing to avoid false positives from unexpected stdout lines, avoiding a module-level global cache to prevent race conditions in concurrent environments, and addressing the startup latency on Windows caused by spawning PowerShell synchronously.
05a1028 to
7fe77b8
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces robust, synchronous security validation for configuration files and directories across Windows and POSIX platforms. It implements isPathSecureSync and isFileAndDirectorySecureSync to ensure that system configuration files and their parent directories are owned by trusted accounts (root/administrator) and are not writable by unprivileged users, integrating these checks into the CLI settings loading process. The review feedback highlights a security improvement opportunity in isFileAndDirectorySecureSync to resolve symbolic links first using a robust function like resolveToRealPath to prevent potential path traversal vulnerabilities, and to explicitly verify the security of the resolved target file.
0a916c2 to
114fb7c
Compare
…ration existence checks
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces robust synchronous path security validation utilities in packages/core, including Windows ACL checking via PowerShell and POSIX ownership/permission checks, and integrates them into the CLI settings loading process to prevent loading insecure system configuration files. It also adds comprehensive unit tests for these security features and updates interactive file system integration tests to reduce flakiness. The code reviewer identified a potential security bypass on Windows where stripping only the '\\?\' prefix from UNC paths (which may be prefixed with '\\?\UNC\') can result in an invalid path format. To address this, the reviewer recommends using a unified, robust path resolution function like resolveToRealPath across all validations.
… path security normalization
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces robust path security validation for system configuration files across Windows and POSIX platforms, implementing synchronous ownership and permission checks alongside caching and path normalization. The reviewer identified a critical security vulnerability in isFileAndDirectorySecureSync, which only checks the immediate parent directory. To prevent privilege escalation via grandparent directory manipulation, the reviewer recommended recursively validating all ancestor directories up to the root and provided a refactored implementation.
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 introduces robust, synchronous security validation for configuration files and their parent directories across Windows and POSIX platforms. It adds path normalization (including stripping Windows extended-length prefixes), batched PowerShell ACL checks on Windows, POSIX ownership/permission checks, and isolated caching. E2E tests and comprehensive unit tests are also added. The review feedback suggests a critical security and robustness improvement: using Base64-encoded UTF-16LE strings with the -EncodedCommand parameter instead of raw -Command in both PowerShell execution points to prevent command-line parsing, quoting, and length limitation issues on Windows.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces robust file and directory security validation mechanisms across Windows and POSIX platforms, including synchronous ownership and permission checks, Windows extended-length path prefix stripping, and integration into system settings loading. Feedback from the review highlights a security concern regarding potential binary hijacking when spawning PowerShell with unvalidated environment variables, as well as test pollution issues in the security tests caused by directly mutating the shared node:fs constants.
…oid test pollution
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces robust, cross-platform path security validation to ensure that configuration files and their parent directories are secure before loading them. It implements synchronous security checks (isPathSecureSync and isFileAndDirectorySecureSync) for both POSIX and Windows, using PowerShell on Windows to securely batch ACL checks. Additionally, it handles Windows extended-length path prefixes and adds comprehensive unit tests. The reviewer identified a security vulnerability on Windows where grandparent and higher ancestor directories are skipped during validation, potentially allowing directory-replacement or symlink-redirection attacks, and suggested checking all ancestors up to the root (excluding the drive root itself).
…e excluding drive root
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces synchronous security validation utilities and caching mechanisms to verify that configuration files and their parent directories are secure across Windows and POSIX environments. It updates the settings loading logic to skip insecure system defaults and system settings files, adds helper functions to strip Windows extended-length path prefixes, and includes comprehensive tests. Feedback on the changes highlights a high-severity issue in the PowerShell ACL script where the automatic variable $_ inside a catch block incorrectly references the thrown exception instead of the pipeline object, rendering the fallback check ineffective.
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 introduces robust security validation utilities to verify the ownership and permissions of configuration files and their ancestor directories on both Windows and POSIX systems, ensuring insecure files are skipped with warnings. It also handles Windows extended-length path prefixes and adds comprehensive unit tests. The review feedback highlights a security vulnerability in the SystemRoot validation regex, which is too permissive and could allow binary hijacking or path traversal; restricting it to standard Windows directories is recommended, along with updating the corresponding test cases.
Summary
Enforces file ownership and access control list (ACL) verification for system-wide configuration files on Windows and POSIX platforms before loading configuration settings.
Details
@google/gemini-cli-core(isPathSecureSync,buildWindowsAclScript,parseWindowsSecurityOutput). Confirms that unprivileged users and groups (e.g.Users,Authenticated Users,Everyone,BUILTIN\Users) do not possessWrite,Modify, orFullControlpermissions on system-wide configuration paths.root:root, uid 0) and file/directory permissions (S_IWGRP,S_IWOTHare unset) to prevent non-root modifications. Validates both symlinks and canonical targets.isFileAndDirectorySecureSyncto verify both the target configuration file and its enclosing parent directory._doLoadSettingsin@google/gemini-cli(loadSystemFile) to validatesystemSettingsPathandsystemDefaultsPathprior to loading. If insecure permissions are detected, the configuration file is skipped and a security warning is logged.packages/core/src/utils/security.test.tsandpackages/cli/src/config/settings.test.ts.Related Issues
How to Validate
npm run lint:ci && npm run typechecknpm test -w @google/gemini-cli -w @google/gemini-cli-corePre-Merge Checklist