Skip to content

fix(config): enforce strict permission and ownership checks on system-wide configuration paths - #29115

Merged
DavidAPierce merged 16 commits into
google-gemini:mainfrom
jesussamuel-byte:fix-system-config
Sep 4, 2026
Merged

DavidAPierce merged 16 commits into
google-gemini:mainfrom
jesussamuel-byte:fix-system-config

Conversation

@jesussamuel-byte

@jesussamuel-byte jesussamuel-byte commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Windows Security Validation: Implemented ACL verification using PowerShell in @google/gemini-cli-core (isPathSecureSync, buildWindowsAclScript, parseWindowsSecurityOutput). Confirms that unprivileged users and groups (e.g. Users, Authenticated Users, Everyone, BUILTIN\Users) do not possess Write, Modify, or FullControl permissions on system-wide configuration paths.
  • POSIX Security Validation: Checks ownership (root:root, uid 0) and file/directory permissions (S_IWGRP, S_IWOTH are unset) to prevent non-root modifications. Validates both symlinks and canonical targets.
  • Path & Directory Security Checks: Added isFileAndDirectorySecureSync to verify both the target configuration file and its enclosing parent directory.
  • CLI Settings Loading: Updated _doLoadSettings in @google/gemini-cli (loadSystemFile) to validate systemSettingsPath and systemDefaultsPath prior to loading. If insecure permissions are detected, the configuration file is skipped and a security warning is logged.
  • Caching: Added in-memory caching for synchronous security check results to prevent repetitive shell/filesystem calls during startup.
  • Unit Test Coverage: Added comprehensive test suites in packages/core/src/utils/security.test.ts and packages/cli/src/config/settings.test.ts.

Related Issues

How to Validate

  1. Run targeted unit tests for security and configuration loading:
    npx vitest run packages/core/src/utils/security.test.ts packages/cli/src/config/settings.test.ts
  2. Run full linting, formatting, and typecheck:
    npm run lint:ci && npm run typecheck
  3. Run the core and CLI test suites:
    npm test -w @google/gemini-cli -w @google/gemini-cli-core

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@jesussamuel-byte
jesussamuel-byte requested a review from a team as a code owner August 28, 2026 16:27
@github-actions github-actions Bot added the size/l A large sized PR label Aug 28, 2026
@github-actions

github-actions Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/XL

  • Lines changed: 2259
  • Additions: +2199
  • Deletions: -60
  • Files changed: 8

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Security Hardening: Implemented robust system-wide configuration security checks for both Windows and POSIX systems to prevent local privilege escalation and cross-user command execution.
  • Windows ACL Validation: Added PowerShell-based ACL verification to ensure system configuration files are not writable by unprivileged users or groups.
  • POSIX Security Checks: Added strict ownership (root:root) and permission (non-writable by group/others) validation for configuration files and directories.
  • Performance Optimization: Introduced in-memory caching for security check results to minimize filesystem and shell overhead during CLI startup.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts Outdated
Comment thread packages/core/src/utils/security.ts
Comment thread packages/core/src/utils/security.ts Outdated
@jesussamuel-byte

jesussamuel-byte commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor Author

/gemini review

1 similar comment
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts Outdated
Comment thread packages/core/src/utils/security.ts Outdated
@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Aug 28, 2026
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts Outdated
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts
Comment thread packages/core/src/utils/security.ts Outdated
Comment thread packages/core/src/utils/security.ts Outdated
Comment thread packages/core/src/utils/security.ts Outdated
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts Outdated
Comment thread packages/core/src/utils/security.ts Outdated
@jesussamuel-byte jesussamuel-byte changed the title fix(config): prevent insecure system-wide configuration loading fix(config): enforce strict permission and ownership checks on system-wide configuration paths Aug 31, 2026
@github-actions github-actions Bot added the size/xl An extra large PR label Aug 31, 2026
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts Outdated
Comment thread packages/core/src/utils/security.ts Outdated
Comment thread packages/core/src/utils/security.ts Outdated
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts Outdated
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts Outdated
Comment thread packages/core/src/utils/security.ts Outdated
Comment thread packages/core/src/utils/security.ts Outdated
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts
Comment thread packages/core/src/utils/security.ts
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts
Comment thread packages/core/src/utils/security.test.ts
Comment thread packages/core/src/utils/security.test.ts
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread packages/core/src/utils/security.ts
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts
@jesussamuel-byte

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/core/src/utils/security.ts
Comment thread packages/core/src/utils/security.test.ts
@DavidAPierce
DavidAPierce added this pull request to the merge queue Sep 4, 2026
Merged via the queue into google-gemini:main with commit 85aca16 Sep 4, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l A large sized PR size/xl An extra large PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants