From 66cc1331ae4d08e0fd281102687e3eaa6ae586a6 Mon Sep 17 00:00:00 2001 From: githubscum <65476409+githubscum@users.noreply.github.com> Date: Fri, 4 Sep 2026 08:46:57 -0500 Subject: [PATCH] CORE (signing sitting): tripwire for KNOWN-LIMITS 35, session id on gate receipts gatedAction() already carries an informational side-channel for exactly this shape of field: meta.ruleId and meta.heldMs reach the receipt without ever entering canonicalizeRequest or verifyApproval. meta.sessionId does not exist yet, though the value is available at every call site in bin/hook-pre-tool-use.js (parsed.sessionId is already computed and already threaded onto one receipt type, the both-layers-permissive policy-warn case) and simply is not forwarded to gatedAction's meta. This ships a tripwire, not the fix: three assertions proving the gap against the live source (two live gatedAction() calls showing sessionId dropped on both denied and approved paths, one static-source check counting the three bare `meta = { ruleId, heldMs }` sites in the hook). All three currently pass against today's code. KNOWN-LIMITS 35 is amended to point at the exact three-part fix recipe, named in the test file's own docstring, rather than left as a paragraph nobody can act on without re-deriving the call sites. The actual fix (src/gate/index.js, bin/hook-pre-tool-use.js) was attempted first per Lotor rule 1 and denied unsigned by the gate (self-mod, request 0e2c4bda on the src/gate edit) -- correct outcome, not reshaped, not routed around. It queues for Isaac's signing sitting alongside the other core items already stacked (limit 63's parts widening, limit 34's two-part fix, limit 64's digest-on-session-open, limit 65's pin-body coverage). 944/944 (941 baseline on main + 3 new). Co-Authored-By: Claude Sonnet 5 --- KNOWN-LIMITS.md | 15 ++ ...nown-limits-35-session-attribution.test.js | 166 ++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 test/known-limits-35-session-attribution.test.js diff --git a/KNOWN-LIMITS.md b/KNOWN-LIMITS.md index 5090606..5f66154 100644 --- a/KNOWN-LIMITS.md +++ b/KNOWN-LIMITS.md @@ -1220,6 +1220,21 @@ change to `src/gate`, which is one signature per edit and belongs in a reviewed sitting rather than riding along with a view. Until then, denials are a timeline and not a per-session fact. +**NARROWED, not closed (2026-09-04, lotor lane).** `gatedAction()` already carries +an informational side-channel for exactly this shape of field: `meta.ruleId` and +`meta.heldMs` reach the receipt without ever entering `canonicalizeRequest` or +`verifyApproval`, so they cannot be forged into an approval and cost nothing to add. +`meta.sessionId` does not exist yet, but the precedent it would follow is already +shipped and tested. Confirmed by reading, not reasoning: `bin/hook-pre-tool-use.js` +already computes `sessionId` from `payload.session_id` and already threads it onto +one receipt type (`policy-warn`, the `both-layers-permissive` case) — the value is +in hand at every one of the three `gatedAction()` call sites, it is simply not +passed. The three-part fix is named verbatim, with file and approximate line +numbers, in `test/known-limits-35-session-attribution.test.js`, which ships a +tripwire proving the gap against the live source (three assertions, all passing +against today's code) rather than describing it in prose alone. **Core. Queues for +the signing sitting**, same as the rest of this file's open core items. + ## 36. An approved receipt records the tool, never the target Found 2026-07-26 building the autograph ratio, by reading `src/gate/index.js:209`. diff --git a/test/known-limits-35-session-attribution.test.js b/test/known-limits-35-session-attribution.test.js new file mode 100644 index 0000000..55e968e --- /dev/null +++ b/test/known-limits-35-session-attribution.test.js @@ -0,0 +1,166 @@ +/** + * KNOWN-LIMITS 35 — a gate decision carries no session id, so a denial cannot + * be attributed. + * + * This is a TRIPWIRE, not a regression guard: it asserts the CURRENT + * defective state (gatedAction() silently drops meta.sessionId; the hook + * never passes it) so that fixing the gap fails this test loudly instead of + * fixing something nobody is watching (the entry-25 lesson, applied to a + * confession instead of a heading). + * + * meta.ruleId and meta.heldMs already prove the pattern this fix follows: + * "informational only, never signed" fields carried on `meta` and copied + * onto the receipt without entering canonicalizeRequest/verifyApproval. + * sessionId belongs in that same family. + * + * WHEN LIMIT 35 IS FIXED, three things change together and this file must be + * updated in the SAME PR, not deleted: + * 1. src/gate/index.js: all three `chain.append({ type: 'gated-action', ... })` + * call sites (denied / stale-or-mismatch / approved) gain + * `sessionId: meta.sessionId || null,` alongside the existing `ruleId` + * and `heldMs` lines. + * 2. bin/hook-pre-tool-use.js: the three `const meta = { ruleId, heldMs };` + * sites (as of this writing, around lines 932, 958, 995) become + * `const meta = { ruleId, heldMs, sessionId: parsed.sessionId };` — + * `parsed.sessionId` is already computed at line ~109 and already used + * for the `both-layers-permissive` policy-warn receipt at line ~773, so + * no new plumbing is needed to obtain it, only to pass it through. + * 3. Every assertion below that currently reads `undefined`/`false` inverts + * to read the real session id / `true`. + * + * Both halves are core (src/gate, bin/hook-*) per the lane's charter and + * queue for Isaac's signing sitting; this file ships without them. + */ + +import { describe, it, beforeEach } from 'node:test'; +import assert from 'node:assert'; +import fs from 'node:fs'; +import path from 'node:path'; +import os from 'node:os'; +import crypto from 'node:crypto'; +import { gatedAction } from '../src/gate/index.js'; +import { canonicalizeRequest } from '../src/gate/sign.js'; + +function generateTestKeypair() { + const { publicKey, privateKey } = crypto.generateKeyPairSync('ed25519', { + privateKeyEncoding: { type: 'pkcs8', format: 'jwk' }, + publicKeyEncoding: { type: 'spki', format: 'jwk' } + }); + return { + pubB64: publicKey.x, + privKeyObj: crypto.createPrivateKey({ key: privateKey, format: 'jwk' }) + }; +} + +function createTestApprovalToken(actionRequest, keypair) { + const canonical = canonicalizeRequest(actionRequest); + const nonce = crypto.randomBytes(12).toString('base64url'); + const timestamp = Date.now(); + const signData = { request: canonical, nonce, timestamp }; + const signBuf = Buffer.from(JSON.stringify(signData, Object.keys(signData).sort()), 'utf8'); + const sig = crypto.sign(null, signBuf, keypair.privKeyObj); + return { request: canonical, nonce, timestamp, signature: sig.toString('hex') }; +} + +function createMockChain() { + const entries = []; + let seq = 0; + return { + entries, + append(payload) { + const entry = { seq: seq++, timestamp: Date.now(), payload, hash: crypto.randomBytes(32).toString('hex') }; + entries.push(entry); + return entry; + } + }; +} + +function createTempTestDir() { + return fs.mkdtempSync(path.join(os.tmpdir(), 'lotor-gate-sessionid-test-')); +} + +function setupTestKey(baseDir, pubB64) { + const keysDir = path.join(baseDir, 'keys'); + fs.mkdirSync(keysDir, { recursive: true }); + const fp = crypto.createHash('sha256').update(Buffer.from(pubB64, 'base64')).digest('hex').slice(0, 32); + fs.writeFileSync(path.join(keysDir, 'approval.pub'), `ed25519:${pubB64}:fingerprint:${fp}\n`); +} + +describe('KNOWN-LIMITS 35 tripwire — gate receipts carry no session id (yet)', () => { + let testDirs = []; + + beforeEach(() => { testDirs = []; }); + + it('DENIED receipt drops meta.sessionId today (fix: carry it, per ruleId/heldMs precedent)', () => { + const baseDir = createTempTestDir(); + testDirs.push(baseDir); + const keypair = generateTestKeypair(); + setupTestKey(baseDir, keypair.pubB64); + const chain = createMockChain(); + + const actionRequest = { action: 'delete-everything', params: {} }; + const meta = { ruleId: 'some-rule', heldMs: 12, sessionId: 'sess-abc123' }; + + const result = gatedAction(actionRequest, null, chain, baseDir, meta); + assert.strictEqual(result.decision, 'denied'); + + const receipt = chain.entries[chain.entries.length - 1].payload; + // Controls: the sibling informational fields DO already survive today. + assert.strictEqual(receipt.ruleId, 'some-rule', 'control: ruleId already threads through meta'); + assert.strictEqual(receipt.heldMs, 12, 'control: heldMs already threads through meta'); + // The tripwire: sessionId does not, even though it was supplied. + assert.strictEqual(receipt.sessionId, undefined, + 'TRIPWIRE: gatedAction() does not yet copy meta.sessionId onto the denial receipt (KNOWN-LIMITS 35). ' + + 'If this now fails, the core fix landed — invert this assertion to sess-abc123 and update the docstring above.'); + }); + + it('APPROVED receipt drops meta.sessionId today (same gap, opposite decision path)', () => { + const baseDir = createTempTestDir(); + testDirs.push(baseDir); + const keypair = generateTestKeypair(); + setupTestKey(baseDir, keypair.pubB64); + const chain = createMockChain(); + + const actionRequest = { action: 'safe-action', params: {} }; + const token = createTestApprovalToken(actionRequest, keypair); + const meta = { ruleId: 'another-rule', heldMs: 5, sessionId: 'sess-def456' }; + + const result = gatedAction(actionRequest, token, chain, baseDir, meta); + assert.strictEqual(result.decision, 'approved'); + + const receipt = chain.entries[chain.entries.length - 1].payload; + assert.strictEqual(receipt.ruleId, 'another-rule', 'control: ruleId already threads through on approval too'); + assert.strictEqual(receipt.sessionId, undefined, + 'TRIPWIRE: approved receipts also drop meta.sessionId today. ' + + 'If this now fails, invert to sess-def456 — both decision paths must carry it, not just denial.'); + }); + + it('the hook never passes sessionId in meta, though it already has the value in hand', () => { + // Static-source check, not a live hook invocation: proves the SECOND half + // of the gap (the caller, not just the callee) without needing to spawn + // the actual CLI hook binary. `parsed.sessionId` is computed once near + // the top of the file and reused for the both-layers-permissive + // policy-warn receipt — so the value is available, just not forwarded to + // gatedAction's meta. + const hookPath = path.join(process.cwd(), 'bin', 'hook-pre-tool-use.js'); + const src = fs.readFileSync(hookPath, 'utf8'); + + // Control: the file does compute a session id and does use it elsewhere. + assert.match(src, /const sessionId = typeof payload\.session_id/, + 'control: the hook already extracts session_id from the payload'); + assert.match(src, /sessionId: parsed\.sessionId,/, + 'control: parsed.sessionId is already threaded onto at least one receipt (policy-warn)'); + + // Every `const meta = { ruleId, heldMs };` construction site feeding + // gatedAction() is missing sessionId. If a future edit adds it to even + // one but not all three, this count assertion catches the partial fix + // too — it should go to zero, not stay at a smaller nonzero number. + const bareMetaSites = (src.match(/const meta = \{ ruleId, heldMs \};/g) || []).length; + assert.strictEqual(bareMetaSites, 3, + `TRIPWIRE: found ${bareMetaSites} site(s) building meta without sessionId (expected 3 today). ` + + 'If this is now 0, all call sites were fixed — delete this assertion and the two above should ' + + 'also now be inverted in the same PR. If it is between 1 and 2, the fix is PARTIAL: some gate ' + + 'decisions would be attributable and others silently would not, which is worse than the ' + + 'uniform gap this test currently documents.'); + }); +});