chore(memory): BDR-138 + BLK-042 + LRN-262 — feat extract-guard

This commit is contained in:
bchanot committed 2026-11-05 14:43:49 +01:00
1 parent 0ca453f044
commit db499743ef
4 files changed
+22

No files matched your search

+6
View File
@@ -364,3 +364,9 @@ rules:
- **Real cause**: the installed gitleaks does not honour the allowlist block under the hook's invocation (rules compiled in; allowlist silently ignored).
- **Solution**: secret-shaped fixtures built at runtime by concatenation (`'AKIA' + 'I'.repeat(16)`, `'eyJ' + 'a'.repeat(20) + …`), expected strings stay literal (LRN-237); spec and NOISE.md quote shapes by reference, never a literal.
- **Status**: resolved 2026-11-03.
## BLK-042 — Package extracted into the root filesystem of a VM replaced usr-merge symlinks and overwrote system binaries [resolved] (2026-11-05)
- **Friction**: on a VM (vaas-cli ssh, no package manager), a Debian package was extracted with `dpkg -x` into the root filesystem; system binaries overwritten, usr-merge symlinks (bin, sbin, lib, lib64) replaced by real directories carrying the archive's paths.
- **Real cause**: no rule or guard named package/archive extraction into system dirs; the ssh deny rule did not cover vaas-cli ssh; extraction improvised instead of telling the user there was no package manager.
- **Solution**: `hooks/extract-guard.sh` (deny before run, quoted remote scripts re-scanned) + soft_deny line + doctrine bullet (list first, extract into a literal mktemp -d path, PATH/PYTHONPATH, no package manager → tell the user). See the extract-guard BDR.
- **Status**: resolved 2026-11-05.
+8
View File
@@ -1495,3 +1495,11 @@ Supersedes [[BDR-030]].
- **Alternatives rejected**: classic hooks (no store, no tool); gitleaks as redaction engine (rules compiled in, allowlist ignored); per-session store (lost at /clear); index cache (stale registries); option B no sub-agent capture (loses reviewer findings); option C ship as is (70 % noise per call).
- **Residuals**: cross-process writes last-writer-wins; non-Bash failures; lexical superseded reader; 40-hex Gitea tokens kept (SHA-shaped); `user:p@ss@host` partial; `key: value` pair rule over-redacts prose (`token: expected`); session root moves with /cd or a worktree; bare finish on a chore branch counts; common-phrase 4-gram collisions (every ENOENT → known LRN-056 here) → 4c.
- **Gates**: plan r1 correctness FATAL(9) → r2, confirmation CONCERNS(5) → r3; SDD Tasks 1-6 + 8 (sonnet, 7 fix rounds), 7 and 9 controller; headless proof PASS; final opus review Approved with fixes (2 Important, 13 minors, 2 rounds); verifier ECARTS(3) → ECARTS(1) (interactive /clear half, user); security PASS ×3 (coverage rounds). 36+ commits.
## BDR-138 — extract-guard: narrow text hook refusing package/archive extraction into system dirs, plus soft_deny, not a full shell parser (2026-11-05)
- **Context**: user incident 2026-11-04 (Debian package extracted on a VM overwrote system binaries); /feat on feature/extract-guard, contract `.claude/tasks/contracts/2026-11-04-extract-guard-2214.md`, plan r3.
- **Decision**: `hooks/extract-guard.sh`, PreToolUse `Bash|Monitor`, timeout 10, DENY (not ask). Watched: dpkg/dpkg-deb extract flags, tar extract (bsdtar, gtar), unzip, cpio copy-in and pass-through, recursive cp. System roots: the root dir itself and usr, etc, bin, sbin, lib*, boot, opt, var, srv, root, sys, proc, dev with subdirs; var/tmp, var/folders, HOME free. One POSIX awk scanner (bash 3.2 safe wrapper): re-tokenizes EVERY quoted word holding a blank, command substitutions, backticks, heredoc bodies (depth ≤ 3), no carrier list; detector starts at every watched tool word (covers sudo, find -exec, both vaas-cli ssh forms). Unresolvable destination (variable, substitution, glob, brace) refused; >64 KiB naming a tool refused; awk failure past prefilter refused; jq/awk/grep/sed/tr/wc missing → warn + allow. Remote follows local rules (relative or absent dest passes); quoted script inherits caller's cd (stated FP: cd to the root dir, then an ssh extract); subshell restores cd. Plus `autoMode.soft_deny` line for intent text hides; doctrine bullet in CLAUDE.global.md § Destructive tools & data loss.
- **Why**: static shell parsing never complete (plan r1 FATAL ×3, r2 FATAL(9)/(7): 30+ forms); ssh, sudo, su, eval, pipe-to-bash already denied statically, real exposed carrier = vaas-cli ssh (remote root); classifier reads intent → soft_deny covers MISSES.
- **Alternatives rejected**: fine parser with carrier/wrapper lists (r2, endless holes); doctrine + soft_deny only (no deterministic refusal); ask (inert in headless sub-agents, BDR-090); folding into withheld guard-bash.sh (BLK-022 spec would turn red).
- **Residuals**: destination built outside the text; old-style tar C letter, long-option abbreviations; tool names built by expansion; archive members escaping a safe destination; the cd-then-ssh FP; prose or a heredoc body quoting a complete extraction command into a system dir is refused too (it hit this memory write: memory bodies go through Write + --body-file, prose uses `<pkg> <dir>` placeholders).
- **Gates**: verifier ECARTS(2) → CONFORME; security PASS ×2 (4 MEDIUM then 2 MEDIUM fixed: size cap, control-byte RS, obfuscated names, globs, cpio pass-through, busybox timing); 134+ tests under gawk/mawk/busybox awk; make test green. Commits 5507972..f02fd8a, settings 42e37cb via index, docs 8d5a7bd.
+3
View File
@@ -693,3 +693,6 @@ rules:
## 2026-11-04
- 2026-11-04 — 4b memory capture built on feature/memory-capture (mod, consumers, docs, noise 83 % → errorish filter; GATE 0 MET, verifier ECARTS(1) interactive half, security PASS ×3); interactive note check + merge pending user; 4c next.
- 2026-11-04 — 4b memory capture merged into develop (dfadf8a); live proof: note once after fix: commit, NEW failure survives /clear; 4c follow-up (earlier-session milestones) in TODO; 4c next.
## 2026-11-05
- 2026-11-05: extract-guard built on feature/extract-guard (hook, soft_deny, doctrine; verifier CONFORME, security PASS); live in settings working copy; 4c paused at plan r2; merge pending user.
+5
View File
@@ -1951,3 +1951,8 @@ Rule: when editing a doctrine file under structure locks, grep the test's lock s
- **Pattern**: before shipping a rule that fires on tool output, measure its noise: sonnet ports the rule to Python (`noise.py`, stdlib, read-only, `--seed`), replays 14 days of `~/.claude/projects/<repo>/*.jsonl` + `*/subagents/*.jsonl`, prints 30 redacted samples; the controller labels useful/noise. Result 4b: 83 % noise, concentrated in sub-agents (23/25) vs main loop (2/5); candidate tightenings (`probe`, `errorish`) measured on the WHOLE corpus (81 → 60 / 27) before the gate; the user picked one, amending a gated answer.
- **Context**: 4b Task 7, LRN-047 lineage; NOISE.md holds counts and shares only (contract check forbids `excerpt:`/`command:` lines); samples stay in the job tmp.
- **Apply**: a capture or injection rule ships with its measured noise share and the numbers of the alternatives; a port claims "1:1" only while the TS rule is frozen (ours drifted twice).
## LRN-262 — A shell-text guard is never complete: re-scan every quoted word, refuse unresolvable dests, soft_deny for intent (2026-11-05)
- **Pattern**: a guard over shell command TEXT is never complete; plan challenges kept finding forms (r1: quote chars used as segment delimiters cut a quoted destination off its option; r2: multi-line quoted scripts split into orphan lines, wrappers hiding carriers, ssh value options, heredoc owner = last command on the line, here-strings read as heredocs, command substitutions cutting argv). Ship narrow: re-tokenize EVERY quoted word holding a blank (no carrier list), run the detector from every watched tool word, refuse unresolvable destinations, and put intent in an `autoMode.soft_deny` line for what text cannot show.
- **Context**: extract-guard, feature/extract-guard 2026-11-05. awk traps found by the security gate: `index(substr(txt, i))` per quote/heredoc line = quadratic (1 MB → hook timeout → command RUNS, LRN-196); `RS="\001"` + `all = all $0` drops 0x01 bytes (comment desync); busybox awk slow on per-char appends (cap 64 KiB); the prefilter must run on a de-quoted copy or split tool names skip it. The accepted FP bit its author twice: a memory heredoc quoting a complete extraction command was refused, then the `<pkg> <dir>` placeholder too (angle brackets read as redirections) until placeholders were kept as words.
- **Apply**: any PreToolUse text guard: prefilter on a de-quoted copy, size cap before parsing, linear tokenizer (forward scans), timed flood tests under gawk + mawk + busybox awk, fail closed only past the prefilter, MISSES in the header + soft_deny as net; text bodies about the guarded command go through Write + --body-file, never a heredoc in the Bash call.