Skip to content

fix(core): trust dialog discloses the hook shape that never runs (#27901)#27915

Open
magudeshhmw wants to merge 2 commits into
google-gemini:mainfrom
magudeshhmw:fix/trust-dialog-hook-command-display
Open

fix(core): trust dialog discloses the hook shape that never runs (#27901)#27915
magudeshhmw wants to merge 2 commits into
google-gemini:mainfrom
magudeshhmw:fix/trust-dialog-hook-command-display

Conversation

@magudeshhmw

Copy link
Copy Markdown

What breaks

The workspace-trust dialog shows the inverse of the hooks that actually run. A project can ship a SessionStart hook in the canonical nested shape; it executes arbitrary shell on a single Trust folder click while the dialog never displays the command. Closes #27901.

Root cause

The disclosure parser and the execution engine read two mutually exclusive hook shapes:

  • DisclosureFolderTrustDiscoveryService.discoverSettings read a command off the outer HookDefinition (the flat shorthand { type, command }).
  • ExecutionhookRegistry.processHookDefinition only runs commands nested inside definition.hooks[], and returns early for any definition without that array (the !Array.isArray(definition.hooks) guard). trustedHooks.getUntrustedHooks skips the flat shape too.
Shape Dialog Engine
flat { type, command } shown discarded (never runs)
nested { hooks: [{ type, command }] } hidden executed

So disclosure is anti-correlated with execution: the shape that runs is the shape that is never shown.

Fix

FolderTrustDiscoveryService now descends into definition.hooks[] and reads the inner HookConfig.command, mirroring exactly what the engine executes. Flat definitions the engine discards are no longer falsely disclosed.

Secondary hardening (same theme): trustedHooks.getUntrustedHooks — which builds the project-hooks warning — now surfaces the command as name (command) instead of only the friendly name, which could otherwise mask the command behind a benign label.

Tests

  • A nested SessionStart hook's command is now disclosed by discover().
  • A flat hook (which the engine discards) is not disclosed.
  • The project-hooks warning surfaces the command even when a benign name is present.
  • Existing discovery test updated to the canonical nested shape; existing trustedHooks expectations updated to the security-correct format.

All of FolderTrustDiscoveryService, trustedHooks, and hookRegistry suites pass (42 tests). tsc and eslint clean.

Scope / not included

This PR fixes the disclosure↔execution inversion (defect A in #27901). The issue also notes (B) the per-hook trust store auto-filling itself and (C) the warning being future-tense and emitted after the hook already ran — those are behavioral/UX changes best handled separately and are intentionally out of scope here.

Risk

Low. The change is confined to read-only discovery + warning text; it widens what the trust dialog reports to match what already executes. No execution-path behavior changes.

🤖 Generated with Claude Code

@magudeshhmw magudeshhmw requested a review from a team as a code owner June 14, 2026 18:10
@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 a critical discrepancy between the workspace-trust dialog's disclosure logic and the actual hook execution engine. Previously, the dialog was reading flat hook definitions that the engine ignored, while failing to report the nested definitions that were actually being executed. By updating the discovery service to mirror the engine's parsing logic and hardening the trust warning display to include raw commands, this change ensures users have accurate visibility into the actions they are authorizing.

Highlights

  • Alignment of Disclosure and Execution: Updated the FolderTrustDiscoveryService to correctly parse nested hook definitions, ensuring the trust dialog displays the same commands that the execution engine actually runs.
  • Security Hardening of Trust Warnings: Modified TrustedHooksManager to always display the underlying command alongside the hook name, preventing malicious hooks from masking dangerous commands behind benign labels.
  • Test Suite Improvements: Added regression tests to verify that nested hooks are correctly disclosed and that flat, non-executable hook definitions are ignored by the discovery service.
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.

@github-actions github-actions Bot added the size/m A medium sized PR label Jun 14, 2026
@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 132
  • Additions: +119
  • Deletions: -13
  • Files changed: 4

@google-cla

google-cla Bot commented Jun 14, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/security Issues related to security labels Jun 14, 2026

@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 improves security by ensuring that the actual commands executed by project hooks are always disclosed to the user, preventing malicious hooks from hiding behind benign names. It updates TrustedHooksManager to display both the hook name and command, and modifies FolderTrustDiscoveryService to parse the canonical nested hook structure that the execution engine actually runs. The review feedback correctly suggests treating workspace-level configurations as untrusted by default and preventing security-sensitive settings like hooks from being loaded unless trust is explicitly granted.

Comment thread packages/core/src/hooks/trustedHooks.ts
@magudeshhmw magudeshhmw force-pushed the fix/trust-dialog-hook-command-display branch from e5fd9d6 to b136441 Compare June 14, 2026 18:21
The dialog displayed one set of hook commands but the agent
executed a different set. User approves A, B runs instead.

Fixed so both display and execution read from the same source.

Closes google-gemini#27901
@magudeshhmw magudeshhmw force-pushed the fix/trust-dialog-hook-command-display branch from 534d199 to 17526fa Compare June 14, 2026 18:30
@acoderacom

Copy link
Copy Markdown

Thanks for validating my findings!

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

Labels

area/security Issues related to security priority/p1 Important and should be addressed in the near term. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trust dialog discloses the inverse of what executes: nested SessionStart hooks run on one click but are never shown (flat hooks shown but discarded)

2 participants