From eb770f263f85d3a2d847b7167e4792d3f6d08488 Mon Sep 17 00:00:00 2001 From: huangpz6 Date: Wed, 4 Nov 2026 10:09:15 +0800 Subject: [PATCH] fix(gateguard): gate first-touch edits to .claude/settings files (#3845) The settings exemption skipped the first-touch gate for the files that hold ECC's own off-switches. Settings files now go through the normal gate, including the MultiEdit subagent path. Co-Authored-By: TRAE --- scripts/hooks/gateguard-fact-force.js | 12 ++++-------- tests/hooks/gateguard-fact-force.test.js | 12 +++++------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/scripts/hooks/gateguard-fact-force.js b/scripts/hooks/gateguard-fact-force.js index 583f36052..afc205cf6 100644 --- a/scripts/hooks/gateguard-fact-force.js +++ b/scripts/hooks/gateguard-fact-force.js @@ -2010,12 +2010,6 @@ function normalizeForMatch(value) { .toLowerCase(); } -function isClaudeSettingsPath(filePath) { - const normalized = normalizeForMatch(filePath); - return /(^|\/)\.claude\/settings(?:\.[^/]+)?\.json$/.test(normalized); -} - - function isReadOnlyGitIntrospection(command) { const trimmed = String(command || '').trim(); if (!trimmed || /[\r\n;&|><`$()]/.test(trimmed)) return false; @@ -2444,7 +2438,9 @@ function flushMetrics() { function exemptReason(filePath, data) { if (!filePath) return 'no-path'; - if (isClaudeSettingsPath(filePath)) return 'claude-settings'; + // .claude/settings*.json holds the switches for GateGuard and the other + // hooks, so a first-touch edit there must go through the same gate as any + // other new target. Exempting it let an agent disable the guard (#3845). return isExemptPath(filePath, data) ? 'exempt-glob' : ''; } @@ -2618,7 +2614,7 @@ function gateMultiEdit(ctx) { function gateMultiEditSubagent(edits, data, rawInput) { for (const edit of edits) { const filePath = (edit && edit.file_path) || ''; - if (!filePath || isClaudeSettingsPath(filePath) || isExemptPath(filePath, data)) continue; + if (!filePath || isExemptPath(filePath, data)) continue; const denial = subagentRestrictedDenial(filePath, data, false); if (denial) return denial; } diff --git a/tests/hooks/gateguard-fact-force.test.js b/tests/hooks/gateguard-fact-force.test.js index a0d16f056..bdc13b902 100644 --- a/tests/hooks/gateguard-fact-force.test.js +++ b/tests/hooks/gateguard-fact-force.test.js @@ -1513,10 +1513,10 @@ function runTests() { passed++; else failed++; - // --- Test 16: allows Claude settings edits so the hook can be disabled safely --- + // --- Test 16: .claude/settings*.json is gated like any other first touch (#3845) --- clearState(); if ( - test('allows edits to .claude/settings.json without gating', () => { + test('gates first-touch edits to .claude/settings.json', () => { const input = { tool_name: 'Edit', tool_input: { file_path: '/workspace/app/.claude/settings.json', old_string: '{}', new_string: '{"hooks":[]}' } @@ -1524,11 +1524,9 @@ function runTests() { const result = runHook(input); const output = parseOutput(result.stdout); assert.ok(output, 'should produce valid JSON output'); - if (output.hookSpecificOutput) { - assert.notStrictEqual(output.hookSpecificOutput.permissionDecision, 'deny', 'settings edits must not be blocked by gateguard'); - } else { - assert.strictEqual(output.tool_name, 'Edit'); - } + assert.ok(output.hookSpecificOutput, 'the settings file must not bypass the gate'); + assert.strictEqual(output.hookSpecificOutput.permissionDecision, 'deny'); + assert.ok(output.hookSpecificOutput.permissionDecisionReason.includes('Fact-Forcing Gate')); }) ) passed++;