mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-13 23:01:09 -07:00
Add Folder Trust Support To Hooks (#15325)
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
|
||||
import { spawn } from 'node:child_process';
|
||||
import type { HookConfig } from './types.js';
|
||||
import { HookEventName } from './types.js';
|
||||
import { HookEventName, ConfigSource } from './types.js';
|
||||
import type { Config } from '../config/config.js';
|
||||
import type {
|
||||
HookInput,
|
||||
HookOutput,
|
||||
@@ -39,7 +40,11 @@ const EXIT_CODE_NON_BLOCKING_ERROR = 1;
|
||||
* Hook runner that executes command hooks
|
||||
*/
|
||||
export class HookRunner {
|
||||
constructor() {}
|
||||
private readonly config: Config;
|
||||
|
||||
constructor(config: Config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a single hook
|
||||
@@ -51,6 +56,23 @@ export class HookRunner {
|
||||
): Promise<HookExecutionResult> {
|
||||
const startTime = Date.now();
|
||||
|
||||
// Secondary security check: Ensure project hooks are not executed in untrusted folders
|
||||
if (
|
||||
hookConfig.source === ConfigSource.Project &&
|
||||
!this.config.isTrustedFolder()
|
||||
) {
|
||||
const errorMessage =
|
||||
'Security: Blocked execution of project hook in untrusted folder';
|
||||
debugLogger.warn(errorMessage);
|
||||
return {
|
||||
hookConfig,
|
||||
eventName,
|
||||
success: false,
|
||||
error: new Error(errorMessage),
|
||||
duration: 0,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.executeCommandHook(
|
||||
hookConfig,
|
||||
|
||||
Reference in New Issue
Block a user