Commit b731822
review fixup: close §M12 intra-batch bypass + authority_scope fallback
Addresses all 5 line-level findings from Gemini + Copilot on #31.
(1) Gemini SECURITY-HIGH — ADD+MUTATE intra-batch bypass (liveness.go:81):
Pre-fix: ApplyProgram ran checkLiveness (including §M12) against the
batch-initial state. A program that ADDed an ordinary node and then
MUTATEd a kernel-authority property on it bypassed §M12 because the
classifier saw the target missing from initial state and returned
false.
Fix: split liveness into two phases with different state-resolution
rules:
- §M11 (emitter-context) runs in preflight against batch-initial
state. Emitter references cannot depend on prior envelopes;
initial-state-check is the documented doctrine (impl-plan §2.4).
- §M12 (target-operation) runs per-envelope INSIDE the write-locked
working-state loop in ApplyProgram. By the time envelope N runs,
all nodes ADDed in envelopes 1..N-1 are visible; target
classification is correct.
New method split in kernel/liveness.go:
checkLivenessM11(env, state) — emitter-context only
checkLivenessM12(env, state) — admin-scope only
checkLiveness(env) — both against rt.state (Apply helper)
ApplyProgram preflight loop calls checkLivenessM11 only; the working-
state loop adds a checkLivenessM12 call at the top of each iteration.
(2) Gemini SECURITY-HIGH — empty AuthorityScope bypass (session_context.go:333):
Pre-fix: authorityScopeForField trusted the live property's
AuthorityScope unconditionally, even when empty. An ADD that failed to
populate the metadata left the field classified as no-authority-scope
forever.
Fix: fall through to the registry type spec when the stored scope is
empty. The registry is authoritative — trust it over potentially-
missing node metadata. Same pattern the ValidateMUTATE additive path
already uses.
(3) Gemini MEDIUM — redundant kernel exclusion (session_context.go:315):
Pre-fix: case 2 had `if scope == "kernel" && node.TypeID != "kernel"`.
The kernel-type exclusion was redundant because case 1 would have
already returned true for kernel-typed nodes.
Fix: drop the kernel check. Code reads cleaner; behavior unchanged.
(4) Copilot — misleading test name (session_context_test.go:394):
TestAdminScopeRewrite_MUTATEKernelAuthorityFieldOnKernelNode_NotAdminScope
asserted admin-scope=true (via case 1). Renamed to
...MUTATEOnKernelNode_AdminScopeViaOntologyGovernedType.
(5) Copilot — misleading precedence comment (session_context.go:236):
The ontologyGovernedTypes docstring said ADD/MUTATE "requires
superadmin capability" without noting that kernel-actor and
infrastructure-bootstrap envelopes bypass §M12 via the §M11 allowlist
upstream. Added an IMPORTANT block clarifying the precedence.
Tests (4 new):
operad.TestAdminScopeRewrite_MUTATETargetMissing_FailsClosed
operad.TestAdminScopeRewrite_EmptyStoredAuthorityScope_FallsBackToTypeSpec
kernel.TestApplyProgram_M12_IntraBatchADDThenKernelAuthorityMUTATE_Rejected
kernel.TestApplyProgram_M12_IntraBatchADDThenOwnerMUTATE_Passes
Plus the existing test rename.
21 total §M12-related tests now (9 operad unit + 12 kernel integration).
go build ./... # clean
go test ./... # all packages pass
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent a08f0fa commit b731822
5 files changed
Lines changed: 297 additions & 81 deletions
File tree
- internal
- kernel
- operad
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
31 | 28 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
40 | 41 | | |
41 | | - | |
42 | | - | |
| 42 | + | |
| 43 | + | |
43 | 44 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
48 | 64 | | |
49 | 65 | | |
50 | 66 | | |
51 | 67 | | |
52 | | - | |
53 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
54 | 71 | | |
55 | 72 | | |
56 | 73 | | |
57 | 74 | | |
58 | | - | |
59 | | - | |
60 | | - | |
| 75 | + | |
61 | 76 | | |
62 | 77 | | |
63 | | - | |
| 78 | + | |
64 | 79 | | |
65 | 80 | | |
66 | 81 | | |
| |||
71 | 86 | | |
72 | 87 | | |
73 | 88 | | |
| 89 | + | |
| 90 | + | |
74 | 91 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
86 | 119 | | |
87 | | - | |
88 | 120 | | |
89 | 121 | | |
90 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
677 | 677 | | |
678 | 678 | | |
679 | 679 | | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
680 | 769 | | |
681 | 770 | | |
682 | 771 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
194 | 193 | | |
195 | 194 | | |
196 | | - | |
| 195 | + | |
197 | 196 | | |
198 | 197 | | |
199 | 198 | | |
| |||
229 | 228 | | |
230 | 229 | | |
231 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
232 | 242 | | |
233 | 243 | | |
234 | 244 | | |
| |||
0 commit comments