feat(hooks): additionalContext injection advisory + filter-before lever (v5.10 B5) [skip-docs]
HKV now flags hooks that build hookSpecificOutput.additionalContext from un-grepped command output as an INFO advisory (weight 0, never severity-bearing — excluded from the self-audit nonInfo set). That field enters Claude's context every time the hook fires (plain stdout on exit 0 does not), so an unfiltered payload is a recurring per-turn token cost. - New lib scanners/lib/hook-additional-context.mjs: pure assessHookAdditionalContext (unit-tested, no IO) + IO wrapper assessHookContextForRepo (walk hooks->scripts). Heuristic: additionalContext + verbose-prone capture (cat/git log/execSync/…) && no filter (grep/head/jq/.slice). Deliberately low precision -> advisory only. - HKV: emits the advisory inline on scripts it already reads (after the M5 verbose check). Additive, info severity -> frozen v5.0.0 + SC-5 snapshots untouched. - feature-gap: new filterHookLeverFinding companion, fires ONLY when >=1 chatty hook is detected — surfaces the filter-before-Claude-reads lever (CC filter-test-output.sh). Silent otherwise (opportunity, not noise). - docs: README HKV + GAP scanner rows; scanner-internals.md HKV row + full B5 implementation note. CLAUDE.md kept lean ([skip-docs]); B5 fully documented in README + scanner-internals. Mechanism verified 2026-06-23 against code.claude.com/docs context-window.md (additionalContext enters context; plain stdout does not). Suite 1239 -> 1254 green. Version/badges/CHANGELOG wait for the v5.10 release cut. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
8f7e196046
commit
d2c45a3bb8
11 changed files with 468 additions and 4 deletions
|
|
@ -101,6 +101,46 @@ describe('HKV scanner — verbose hook output (v5 M5)', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('HKV scanner — additionalContext injection advisory (v5.10 B5)', () => {
|
||||
it('flags a hook that injects unfiltered command output into additionalContext (info advisory)', async () => {
|
||||
resetCounter();
|
||||
const path = resolve(FIXTURES, 'hooks-additional-context');
|
||||
const discovery = await discoverConfigFiles(path);
|
||||
const result = await scan(path, discovery);
|
||||
const f = result.findings.find(
|
||||
x => x.scanner === 'HKV' && /additional_context_unfiltered=true/.test(x.evidence || ''),
|
||||
);
|
||||
assert.ok(f, `expected additionalContext advisory; got: ${result.findings.map(x => x.title).join(' | ')}`);
|
||||
assert.equal(f.severity, 'info', `expected info (advisory), got ${f.severity}`);
|
||||
// The chatty.sh script (SessionStart) is the one flagged, not filtered.sh.
|
||||
assert.match(f.file || '', /chatty\.sh$/);
|
||||
// Precision caveat must be disclosed in the description (low-precision advisory).
|
||||
assert.match(f.description || '', /every time|enters Claude's context|advisory/i);
|
||||
});
|
||||
|
||||
it('does NOT flag the filtered (grep|head) sibling hook', async () => {
|
||||
resetCounter();
|
||||
const path = resolve(FIXTURES, 'hooks-additional-context');
|
||||
const discovery = await discoverConfigFiles(path);
|
||||
const result = await scan(path, discovery);
|
||||
const filtered = result.findings.find(
|
||||
x => x.scanner === 'HKV' && /additional_context_unfiltered=true/.test(x.evidence || '') && /filtered\.sh$/.test(x.file || ''),
|
||||
);
|
||||
assert.equal(filtered, undefined, `filtered.sh should not be flagged; got id=${filtered?.id}`);
|
||||
});
|
||||
|
||||
it('does NOT flag a quiet hook with no additionalContext', async () => {
|
||||
resetCounter();
|
||||
const path = resolve(FIXTURES, 'hooks-quiet');
|
||||
const discovery = await discoverConfigFiles(path);
|
||||
const result = await scan(path, discovery);
|
||||
const f = result.findings.find(
|
||||
x => x.scanner === 'HKV' && /additional_context_unfiltered=true/.test(x.evidence || ''),
|
||||
);
|
||||
assert.equal(f, undefined, `expected no additionalContext advisory; got id=${f?.id}`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('HKV scanner — CC 2.1.152 MessageDisplay event (Batch 1 false-positive fix)', () => {
|
||||
// The pre-write path-guard blocks committing settings.json/hooks.json, so
|
||||
// this suite materializes a hermetic temp fixture at runtime.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue