diff --git a/scripts/lib/gateguard-target-class.js b/scripts/lib/gateguard-target-class.js index 4269d7a63..b51ab226f 100644 --- a/scripts/lib/gateguard-target-class.js +++ b/scripts/lib/gateguard-target-class.js @@ -300,7 +300,7 @@ 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$/; +const CLAUDE_SETTINGS_PATH = /(^|\/)\.claude\/settings[^/]*\.json$/; function isClaudeSettingsPath(classPath) { return CLAUDE_SETTINGS_PATH.test(String(classPath || '').replace(/\\/g, '/').toLowerCase()); diff --git a/tests/lib/gateguard-target-class.test.js b/tests/lib/gateguard-target-class.test.js index de5fcf9ff..4d68b52a2 100644 --- a/tests/lib/gateguard-target-class.test.js +++ b/tests/lib/gateguard-target-class.test.js @@ -617,6 +617,24 @@ test('settings files stay sensitive when .claude is the project root', () => { } }); +test('every .claude/settings*.json variant counts as restricted', () => { + const root = tempProject(); + try { + withProjectDir(root, () => { + const data = { cwd: root }; + const at = rel => path.join(root, rel); + // A dash suffix (settings-dev.json) used to slip past the pattern, so a + // subagent could edit it while settings.json stayed gated. + for (const name of ['settings.json', 'settings.local.json', 'settings-dev.json', 'settings.ci.json']) { + assert.strictEqual(isSensitiveTargetFor(at(`.claude/${name}`), data), true, name); + } + assert.strictEqual(isSensitiveTargetFor(at('.claude/notes.json'), data), false); + }); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } +}); + test('a symlink alias to .claude/settings.json is sensitive through the real path', () => { const root = tempProject(); try {