mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 13:32:18 +00:00
fix(gateguard): treat .claude/settings files as restricted for subagents too (#3862)
Removing the exemption gated top-level edits, but subagent Edit/Write/MultiEdit still consult only sensitive or hard-linked targets, so an ordinary settings file bypassed the gate. Classify .claude/settings*.json as sensitive in the shared target class and cover all three subagent edit tools plus both settings file names. Co-Authored-By: TRAE <noreply@trae.ai>
This commit is contained in:
1 parent
eb770f263f
commit
dde2c8dbda
2 files changed
+43
-2
No files matched your search
@@ -297,11 +297,22 @@ function isSensitiveTarget(classPath) {
|
||||
}
|
||||
}
|
||||
|
||||
// `.claude/settings*.json` holds the switches for GateGuard and the other
|
||||
// hooks, so it must count as restricted on every edit path — including the
|
||||
// subagent paths that only deny sensitive or hard-linked targets (#3862).
|
||||
const CLAUDE_SETTINGS_PATH = /(^|\/)\.claude\/settings(?:\.([^/]+))?\.json$/;
|
||||
|
||||
function isClaudeSettingsPath(classPath) {
|
||||
return CLAUDE_SETTINGS_PATH.test(String(classPath || '').replace(/\\/g, '/').toLowerCase());
|
||||
}
|
||||
|
||||
/** Sensitive on the lexical or the real (symlink-resolved) path; any error is sensitive. */
|
||||
function isSensitiveTargetFor(filePath, data) {
|
||||
try {
|
||||
if (typeof filePath !== 'string' || !filePath) return true;
|
||||
if (isSensitiveTarget(classPathFor(filePath, data))) return true;
|
||||
const classPath = classPathFor(filePath, data);
|
||||
if (isClaudeSettingsPath(classPath)) return true;
|
||||
if (isSensitiveTarget(classPath)) return true;
|
||||
return isSensitiveRealTarget(filePath, data);
|
||||
} catch (_) {
|
||||
return true;
|
||||
|
||||
@@ -1521,7 +1521,7 @@ function runTests() {
|
||||
tool_name: 'Edit',
|
||||
tool_input: { file_path: '/workspace/app/.claude/settings.json', old_string: '{}', new_string: '{"hooks":[]}' }
|
||||
};
|
||||
const result = runHook(input);
|
||||
const result = runHook(input, { GATEGUARD_EXEMPT_GLOBS: '' });
|
||||
const output = parseOutput(result.stdout);
|
||||
assert.ok(output, 'should produce valid JSON output');
|
||||
assert.ok(output.hookSpecificOutput, 'the settings file must not bypass the gate');
|
||||
@@ -2023,6 +2023,36 @@ function runTests() {
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
// --- Test 33a: settings files stay gated on subagent Edit/Write/MultiEdit (#3862) ---
|
||||
clearState();
|
||||
if (
|
||||
test('subagent settings edits stay gated on every edit tool', () => {
|
||||
const env = { CLAUDE_SESSION_ID: '', ECC_SESSION_ID: '', GATEGUARD_EXEMPT_GLOBS: '' };
|
||||
const settingsPaths = ['/workspace/app/.claude/settings.json', '/workspace/app/.claude/settings.local.json'];
|
||||
|
||||
for (const filePath of settingsPaths) {
|
||||
const edits = [{ file_path: filePath, old_string: '{}', new_string: '{"hooks":[]}' }];
|
||||
const cases = [
|
||||
{ tool_name: 'MultiEdit', tool_input: { edits } },
|
||||
{ tool_name: 'Edit', tool_input: { ...edits[0] } },
|
||||
{ tool_name: 'Write', tool_input: { file_path: filePath, content: '{"hooks":[]}' } }
|
||||
];
|
||||
for (const toolInput of cases) {
|
||||
clearState();
|
||||
const result = runHook(
|
||||
{ ...toolInput, session_id: 'subagent-fresh-session', agent_id: 'agent-abc-123' },
|
||||
env
|
||||
);
|
||||
const output = parseOutput(result.stdout);
|
||||
assert.ok(output && output.hookSpecificOutput, `${toolInput.tool_name} ${filePath} must be denied`);
|
||||
assert.strictEqual(output.hookSpecificOutput.permissionDecision, 'deny');
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
// --- Test 33: Bash stays gated inside subagents ---
|
||||
clearState();
|
||||
if (
|
||||
|
||||
Reference in new issue
Block a user