Skip to content

fix(security): enforce case-insensitive sensitive path blocklist and vscode hitl#27966

Open
luisfelipe-alt wants to merge 2 commits into
google-gemini:mainfrom
luisfelipe-alt:bugfix/WT-engineer_460843894
Open

fix(security): enforce case-insensitive sensitive path blocklist and vscode hitl#27966
luisfelipe-alt wants to merge 2 commits into
google-gemini:mainfrom
luisfelipe-alt:bugfix/WT-engineer_460843894

Conversation

@luisfelipe-alt

Copy link
Copy Markdown
Contributor

Summary

This PR implements a 100% robust, production-grade security fix for the case-insensitivity bypass and prompt injection vulnerability in Gemini CLI. It enforces a strict, case-insensitive blocklist for sensitive directories/files (.git, .env, node_modules) and ensures that any modifications to .vscode/ configuration files always require explicit user confirmation (Human-in-the-Loop), even in automated modes like autoEdit or YOLO.

Details

  • Case-Insensitive Segment Blocklist in WorkspaceContext: Updated isPathWithinWorkspace in packages/core/src/utils/workspaceContext.ts to split resolved paths into segments and check them case-insensitively against ['.git', '.env', 'node_modules'].
  • Case-Insensitive Segment Blocklist in AllowedPathChecker: Updated AllowedPathChecker in packages/core/src/safety/built-in.ts to enforce the same case-insensitive segment blocklist check, returning SafetyCheckDecision.DENY if matched.
  • Mandatory HITL Confirmation for .vscode/ Configuration Files: Updated AllowedPathChecker to detect if a path is inside .vscode/ (case-insensitively) and return SafetyCheckDecision.ASK_USER, which downgrades the policy engine's decision to ASK_USER (requiring explicit user confirmation) even in automated modes like autoEdit or YOLO.
  • Comprehensive Regression Tests: Added unit tests to packages/core/src/utils/workspaceContext.test.ts and packages/core/src/safety/built-in.test.ts to verify the fix.

Related Issues

How to Validate

  1. Run the specific unit tests to verify that the security fixes and regression tests are working perfectly:
    npx vitest run packages/core/src/utils/workspaceContext.test.ts packages/core/src/safety/built-in.test.ts
  2. Verify that all 56 tests pass successfully.
  3. Run the TypeScript type checker to ensure everything compiles perfectly:
    npm run typecheck

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:
    • Linux
      • npm run

@luisfelipe-alt luisfelipe-alt requested a review from a team as a code owner June 16, 2026 19:15
@github-actions github-actions Bot added the size/m A medium sized PR label Jun 16, 2026
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 203
  • Additions: +192
  • Deletions: -11
  • Files changed: 4

@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 introduces critical security enhancements to the Gemini CLI by hardening path validation logic. By enforcing case-insensitive checks on sensitive directory segments and requiring explicit user approval for modifications to IDE configuration files, the changes mitigate potential vulnerabilities related to path traversal and unauthorized configuration tampering in automated execution environments.

Highlights

  • Case-Insensitive Security Blocklist: Implemented a robust, case-insensitive check for sensitive directories and files ('.git', '.env', 'node_modules') in both the workspace context and the path checker to prevent security bypasses.
  • Mandatory Human-in-the-Loop (HITL) for .vscode: Enforced a requirement for explicit user confirmation when modifying files within '.vscode/', ensuring that automated modes cannot silently alter configuration settings.
  • Regression Testing: Added comprehensive unit tests to verify the new security constraints and ensure that sensitive paths are correctly blocked regardless of casing.
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 implements case-insensitive blocklist checks for sensitive paths (like .git, .env, and node_modules) and requires user confirmation (ASK_USER) for .vscode configuration files. The review highlights critical security issues, including a sandbox bypass where .vscode paths outside the workspace incorrectly trigger ASK_USER instead of DENY, and a Windows trailing character bypass (e.g., .git or .vscode.). The feedback suggests validating workspace allowance before checking blocked segments, handling trailing spaces/dots, using a unified path resolution function (resolveToRealPath), and adding regression tests to verify these edge cases.

Comment thread packages/core/src/safety/built-in.ts
Comment thread packages/core/src/utils/workspaceContext.ts
Comment thread packages/core/src/safety/built-in.test.ts Outdated
@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Jun 16, 2026
@luisfelipe-alt luisfelipe-alt force-pushed the bugfix/WT-engineer_460843894 branch from 93adb5c to a00ecfd Compare June 16, 2026 19:39
@luisfelipe-alt

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 case-insensitive blocklist checks for sensitive paths (such as .git, .env, and node_modules) and requires explicit user confirmation for .vscode configuration files. It also adds comprehensive regression tests to verify these security controls. The review feedback highlights potential bypasses on Windows via NTFS Alternate Data Streams (e.g., .vscode::$DATA) and suggests stripping stream identifiers during segment cleaning, as well as using a unified path resolution function like resolveToRealPath to ensure consistent validation across components.

Comment thread packages/core/src/safety/built-in.ts Outdated
Comment thread packages/core/src/utils/workspaceContext.ts Outdated
@luisfelipe-alt luisfelipe-alt force-pushed the bugfix/WT-engineer_460843894 branch from e4b65ea to 617d084 Compare June 16, 2026 19:55
@luisfelipe-alt

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 implements case-insensitive blocklist checks for sensitive paths (such as .git, .env, and node_modules) and requires explicit user confirmation (ASK_USER) for modifying .vscode configuration files within the workspace. The feedback suggests refactoring the path validation logic to use asynchronous file system operations instead of synchronous ones to avoid blocking the event loop, and ensuring consistent path resolution.

Comment thread packages/core/src/safety/built-in.ts
@luisfelipe-alt luisfelipe-alt force-pushed the bugfix/WT-engineer_460843894 branch from 4a50962 to e2f2eb2 Compare June 16, 2026 21:30
@luisfelipe-alt

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 implements a case-insensitive blocklist for sensitive paths (such as ".git", ".env", and "node_modules") and adds special handling for ".vscode" configuration files to prevent security bypasses, including Windows trailing characters and NTFS Alternate Data Streams. It also refactors safelyResolvePath to use asynchronous file system operations and adds comprehensive regression tests. There are no review comments, and I have no feedback to provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m A medium sized 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.

1 participant