فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix(holoo): disallow caller supplied audit evidence
Davood Mehraban committed
Nov 22, 2026 at 21:39 UTC
323a9154a2a0a48847be9468d40a286588051766
2 files changed
+34
-17
src/holoo-query-boundary.cjs
+12
-8
@@ -1,16 +1,20 @@
1
'use strict';
2
const { evaluateHolooWrite } = require('./holoo-write-policy.cjs');
3
-// Explicit SQL boundary for future adapters. Never accepts arbitrary SQL from callers.
3
+// This boundary accepts only fixed reads; audit evidence must come from the trusted composition root.
4
const QUERIES = Object.freeze({
5
invoiceCount: 'SELECT COUNT_BIG(*) AS count FROM dbo.FACTURE',
6
lineCount: 'SELECT COUNT_BIG(*) AS count FROM dbo.FACTART',
7
documentCount: 'SELECT COUNT_BIG(*) AS count FROM dbo.SANAD'
8
});
9
-async function executeHolooLabRead({ database, audit, queryId, executor } = {}) {
10
- const decision = evaluateHolooWrite({ operation: 'read', database, audit });
11
- if (!decision.allowed) throw new Error(decision.reason);
12
- if (!Object.hasOwn(QUERIES, queryId)) throw new Error('Unapproved Holoo read query');
13
- if (typeof executor !== 'function') throw new Error('Read executor is required');
14
- return executor({ database, sql: QUERIES[queryId], readOnly: true });
9
+function createHolooLabReader({ loadAudit, executor } = {}) {
10
+ if (typeof loadAudit !== 'function' || typeof executor !== 'function') throw new Error('Trusted audit loader and read executor required');
11
+ return async function executeHolooLabRead({ database, queryId } = {}) {
12
+ if (database !== 'HolooBackup_050808_LAB_20261110') throw new Error('Unapproved Holoo database');
13
+ if (typeof queryId !== 'string' || !Object.hasOwn(QUERIES, queryId)) throw new Error('Unapproved Holoo read query');
14
+ const audit = await loadAudit();
15
+ const decision = evaluateHolooWrite({ operation: 'read', database, audit });
16
+ if (!decision.allowed) throw new Error(decision.reason);
17
+ return executor({ database, sql: QUERIES[queryId], readOnly: true });
18
+ };
19
}
16
-module.exports = { executeHolooLabRead };
20
+module.exports = { createHolooLabReader };
tests/holoo-query-boundary.test.mjs
+22
-9
@@ -2,22 +2,35 @@
2
import assert from 'node:assert/strict';
3
import { createRequire } from 'node:module';
4
const require = createRequire(import.meta.url);
5
-const { executeHolooLabRead } = require('../src/holoo-query-boundary.cjs');
5
+const { createHolooLabReader } = require('../src/holoo-query-boundary.cjs');
6
const database = 'HolooBackup_050808_LAB_20261110';
7
const audit = { database, schemaVersion: 1, tables: ['FACTART','FACTURE','SANAD'].map(table => ({table,primaryKeys:1})), procedureConcurrencySignals: ['InsertInFacture','InsertInFactureCode'].map(name => ({name,allocatesNumberWithoutVisibleLock:true})), readOnlyAudit: true, complete: true, productionWriteGate: { status:'NO-GO',productionWritesAuthorized:false } };
8
-test('approved read calls executor with fixed SELECT only', async () => {
8
+test('approved read calls trusted audit loader then fixed SELECT executor', async () => {
9
const calls=[];
10
- const result=await executeHolooLabRead({database,audit,queryId:'invoiceCount',executor: async x => {calls.push(x);return 42;}});
11
- assert.equal(result,42);
12
- assert.deepEqual(calls,[{database,sql:'SELECT COUNT_BIG(*) AS count FROM dbo.FACTURE',readOnly:true}]);
10
+ const read=createHolooLabReader({loadAudit:async()=>{calls.push('audit');return audit;},executor:async x=>{calls.push(x);return 42;}});
11
+ assert.equal(await read({database,queryId:'invoiceCount'}),42);
12
+ assert.deepEqual(calls,['audit',{database,sql:'SELECT COUNT_BIG(*) AS count FROM dbo.FACTURE',readOnly:true}]);
13
});
14
-test('arbitrary SQL cannot reach executor', async () => {
14
+test('arbitrary SQL cannot reach loader or executor', async () => {
15
let calls=0;
16
- for(const queryId of ['DELETE FROM dbo.FACTURE','invoiceCount; DROP TABLE dbo.FACTURE','__proto__',undefined]) await assert.rejects(executeHolooLabRead({database,audit,queryId,executor:async()=>{calls++;}}));
16
+ const read=createHolooLabReader({loadAudit:async()=>{calls++;return audit;},executor:async()=>{calls++;}});
17
+ for(const queryId of ['DELETE FROM dbo.FACTURE','invoiceCount; DROP TABLE dbo.FACTURE','__proto__',undefined,{}]) await assert.rejects(read({database,queryId}));
18
assert.equal(calls,0);
19
});
19
-test('invalid audit or production target never reaches executor', async () => {
20
+test('production target and invalid trusted audit never reach executor', async () => {
21
let calls=0;
21
- for(const params of [{database:'Holoo1',audit},{database,audit:null},{database,audit:{...audit,productionWriteGate:{status:'GO',productionWritesAuthorized:true}}}]) await assert.rejects(executeHolooLabRead({...params,queryId:'invoiceCount',executor:async()=>{calls++;}}));
22
+ const read=createHolooLabReader({loadAudit:async()=>null,executor:async()=>{calls++;}});
23
+ await assert.rejects(read({database:'Holoo1',queryId:'invoiceCount'}));
24
+ await assert.rejects(read({database,queryId:'invoiceCount',audit}));
25
assert.equal(calls,0);
26
});
27
+test('caller cannot substitute audit evidence', async () => {
28
+ let calls=0;
29
+ const read=createHolooLabReader({loadAudit:async()=>({}),executor:async()=>{calls++;}});
30
+ await assert.rejects(read({database,queryId:'invoiceCount',audit}));
31
+ assert.equal(calls,0);
32
+});
33
+test('missing trusted dependencies fail closed', () => {
34
+ assert.throws(()=>createHolooLabReader({executor:async()=>42}));
35
+ assert.throws(()=>createHolooLabReader({loadAudit:async()=>audit}));
36
+});