فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
feat(holoo): evaluate inherited public permission blockers from LAB inventory
Davood Mehraban committed
Nov 22, 2026 at 23:44 UTC
62aa1003bee6911fbc8c43e8e34010b3e555e7e7
2 files changed
+48
src/holoo-readonly-risk-evaluator.cjs
new
+17
@@ -0,0 +1,17 @@
1
+'use strict';
2
+const LAB='HolooBackup_050808_LAB_20261110';
3
+const DML=new Set(['INSERT','UPDATE','DELETE','MERGE','TRUNCATE','ALTER','CONTROL','TAKE OWNERSHIP']);
4
+function evaluateReadOnlyRisk(inventory){
5
+ if(!inventory || inventory.identity?.database_name!==LAB || inventory.readOnlyInventory!==true) throw new Error('Untrusted or non-LAB inventory');
6
+ if(!Array.isArray(inventory.databasePermissions) || !Array.isArray(inventory.databaseRoleMemberships) || !Array.isArray(inventory.serverRoleMemberships)) throw new Error('Incomplete inventory');
7
+ const publicGrants=inventory.databasePermissions.filter(p=>p.principal_name==='public' && ['GRANT','GRANT_WITH_GRANT_OPTION'].includes(p.state_desc));
8
+ const mutationGrants=publicGrants.filter(p=>DML.has(p.permission_name));
9
+ const executeGrants=publicGrants.filter(p=>p.permission_name==='EXECUTE');
10
+ const blockers=[];
11
+ if(mutationGrants.length) blockers.push({code:'PUBLIC_MUTATION_GRANTS',count:mutationGrants.length,targets:[...new Set(mutationGrants.map(p=>p.object_name||p.class_desc||'UNKNOWN'))].sort()});
12
+ if(executeGrants.length) blockers.push({code:'PUBLIC_EXECUTE_GRANTS',count:executeGrants.length});
13
+ blockers.push({code:'PROPOSED_IDENTITY_NOT_VERIFIED',detail:'Current administrator inventory cannot prove effective permissions of an unprovisioned Windows identity'});
14
+ blockers.push({code:'WINDOWS_GROUP_AND_OWNERSHIP_PATHS_UNVERIFIED',detail:'Inherited group rights, ownership chaining, and indirect calls require independent validation'});
15
+ return {database:LAB,status:'NO-GO',databaseWideReadOnlyProven:false,publicExecuteGrantCount:executeGrants.length,publicMutationGrantCount:mutationGrants.length,blockers,sqlChangesPerformed:false};
16
+}
17
+module.exports={evaluateReadOnlyRisk};
tests/holoo-readonly-risk-evaluator.test.mjs
new
+31
@@ -0,0 +1,31 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import {createRequire} from 'node:module';
4
+import {fileURLToPath} from 'node:url';
5
+import {spawnSync} from 'node:child_process';
6
+const require=createRequire(import.meta.url);
7
+const {evaluateReadOnlyRisk}=require('../src/holoo-readonly-risk-evaluator.cjs');
8
+const lab='HolooBackup_050808_LAB_20261110';
9
+const fixture=(permissions=[])=>({identity:{database_name:lab},readOnlyInventory:true,databasePermissions:permissions,databaseRoleMemberships:[],serverRoleMemberships:[]});
10
+test('rejects wrong database or incomplete evidence',()=>{
11
+ assert.throws(()=>evaluateReadOnlyRisk({}),/Untrusted/);
12
+ assert.throws(()=>evaluateReadOnlyRisk({...fixture(),identity:{database_name:'Holoo1'}}),/non-LAB/);
13
+ assert.throws(()=>evaluateReadOnlyRisk({...fixture(),databasePermissions:null}),/Incomplete/);
14
+});
15
+test('public mutation and execute grants block read-only certification',()=>{
16
+ const report=evaluateReadOnlyRisk(fixture([{principal_name:'public',state_desc:'GRANT',permission_name:'INSERT',object_name:'dbo.dtproperties'},{principal_name:'public',state_desc:'GRANT',permission_name:'EXECUTE',object_name:'dbo.dt_setpropertybyid'}]));
17
+ assert.equal(report.status,'NO-GO');assert.equal(report.publicMutationGrantCount,1);assert.equal(report.publicExecuteGrantCount,1);
18
+ assert.ok(report.blockers.some(x=>x.code==='PUBLIC_MUTATION_GRANTS'));
19
+});
20
+test('empty catalog does not prove safety of a proposed identity',()=>{
21
+ const report=evaluateReadOnlyRisk(fixture());
22
+ assert.equal(report.databaseWideReadOnlyProven,false);
23
+ assert.ok(report.blockers.some(x=>x.code==='PROPOSED_IDENTITY_NOT_VERIFIED'));
24
+});
25
+test('real LAB inventory yields explainable blockers', {skip:process.platform!=='win32'||process.env.HOLOO_SQL_INTEGRATION!=='1'},()=>{
26
+ const script=fileURLToPath(new URL('../scripts/holoo-lab-principal-inventory.ps1',import.meta.url));
27
+ const result=spawnSync('powershell.exe',['-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-File',script,'-Json'],{encoding:'utf8',timeout:30000,maxBuffer:4*1024*1024});
28
+ assert.equal(result.status,0,result.stderr);
29
+ const report=evaluateReadOnlyRisk(JSON.parse(result.stdout));
30
+ assert.equal(report.publicExecuteGrantCount,31);assert.equal(report.publicMutationGrantCount,3);assert.equal(report.status,'NO-GO');
31
+});