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 <noreply@trae.ai>
This commit is contained in:
huangpz6andTRAE committed 2026-11-04 10:09:15 +08:00
1 parent b38be6a7f6
commit eb770f263f
2 files changed
+9 -15

No files matched your search

+4 -8
View File
@@ -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;
}
+5 -7
View File
@@ -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++;