فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix(holoo): verify SQL permissions on count query connection
Davood Mehraban committed
Nov 22, 2026 at 22:13 UTC
ff00a6525903933dca52d4fe825b711bcfe91cb6
2 files changed
+28
-1
scripts/holoo-lab-counts.ps1
+17
-1
@@ -13,5 +13,21 @@ if($permission.status -ne 'PASS' -or -not $permission.leastPrivilegeReadOnly){th
13
$queries=@{invoiceCount='SELECT COUNT_BIG(*) FROM dbo.FACTURE';lineCount='SELECT COUNT_BIG(*) FROM dbo.FACTART';documentCount='SELECT COUNT_BIG(*) FROM dbo.SANAD'}
14
Add-Type -AssemblyName System.Data
15
$c=New-Object System.Data.SqlClient.SqlConnection('Server=ARAM\TNC;Database=HolooBackup_050808_LAB_20261110;Integrated Security=True;Connection Timeout=5;Application Name=FinoraHolooLabCounts;ApplicationIntent=ReadOnly')
16
-try {$c.Open();$q=$c.CreateCommand();$q.CommandTimeout=15;$q.CommandText=$queries[$QueryId];$value=[long]$q.ExecuteScalar();[pscustomobject]@{database='HolooBackup_050808_LAB_20261110';queryId=$QueryId;count=$value;readOnly=$true}|ConvertTo-Json -Compress} finally {$c.Dispose()}
16
+try {
17
+ $c.Open()
18
+ $q=$c.CreateCommand();$q.CommandTimeout=15
19
+ # Recheck effective privileges on the SAME connection that will run the count.
20
+ $q.CommandText="SELECT DB_NAME(),IS_MEMBER('db_owner'),HAS_PERMS_BY_NAME('dbo.FACTURE','OBJECT','SELECT'),HAS_PERMS_BY_NAME('dbo.FACTURE','OBJECT','INSERT'),HAS_PERMS_BY_NAME('dbo.FACTURE','OBJECT','UPDATE'),HAS_PERMS_BY_NAME('dbo.FACTURE','OBJECT','DELETE'),HAS_PERMS_BY_NAME('dbo.FACTART','OBJECT','SELECT'),HAS_PERMS_BY_NAME('dbo.FACTART','OBJECT','INSERT'),HAS_PERMS_BY_NAME('dbo.FACTART','OBJECT','UPDATE'),HAS_PERMS_BY_NAME('dbo.FACTART','OBJECT','DELETE'),HAS_PERMS_BY_NAME('dbo.SANAD','OBJECT','SELECT'),HAS_PERMS_BY_NAME('dbo.SANAD','OBJECT','INSERT'),HAS_PERMS_BY_NAME('dbo.SANAD','OBJECT','UPDATE'),HAS_PERMS_BY_NAME('dbo.SANAD','OBJECT','DELETE'),IS_MEMBER('db_datawriter'),IS_MEMBER('db_ddladmin')"
21
+ $r=$q.ExecuteReader()
22
+ try {
23
+ if(-not $r.Read()){throw 'SQL same-connection privilege gate BLOCKED'}
24
+ if($r.GetString(0) -ne 'HolooBackup_050808_LAB_20261110'){throw 'SQL same-connection database gate BLOCKED'}
25
+ foreach($i in @(1,3,4,5,7,8,9,11,12,13,14,15)){if($r.IsDBNull($i) -or $r.GetInt32($i) -ne 0){throw 'SQL same-connection privilege gate BLOCKED'}}
26
+ foreach($i in @(2,6,10)){if($r.IsDBNull($i) -or $r.GetInt32($i) -ne 1){throw 'SQL same-connection SELECT gate BLOCKED'}}
27
+ } finally {$r.Close()}
28
+ $q.CommandText=$queries[$QueryId]
29
+ $value=[long]$q.ExecuteScalar()
30
+ [pscustomobject]@{database='HolooBackup_050808_LAB_20261110';queryId=$QueryId;count=$value;readOnly=$true}|ConvertTo-Json -Compress
31
+} finally {$c.Dispose()}
32
+
33
tests/holoo-lab-reader.test.mjs
+11
@@ -23,3 +23,14 @@ test('count SQL is gated by effective permission audit before connection',()=>{
23
assert.match(source,/leastPrivilegeReadOnly/);
24
assert.match(source,/SQL least-privilege gate BLOCKED/);
25
});
26
+
27
+test('SQL execution rechecks all three tables on the same connection',()=>{
28
+ const source=readFileSync(fileURLToPath(new URL('../scripts/holoo-lab-counts.ps1',import.meta.url)),'utf8');
29
+ const open=source.indexOf('$c.Open()');
30
+ const permission=source.indexOf('SQL same-connection privilege gate BLOCKED');
31
+ const query=source.indexOf('$q.CommandText=$queries[$QueryId]');
32
+ assert.ok(open>=0 && permission>open && query>permission);
33
+ for(const table of ['FACTURE','FACTART','SANAD']) assert.match(source,new RegExp(`dbo\\.${table}`));
34
+ assert.match(source,/IS_MEMBER\('db_datawriter'\)/);
35
+ assert.match(source,/IS_MEMBER\('db_ddladmin'\)/);
36
+});