فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix(holoo): gate count reads on inherited public SQL grants
Davood Mehraban committed
Nov 22, 2026 at 23:28 UTC
5493e3ee2e812a8aeba1fbb3048e86fc6e19b7b2
2 files changed
+16
scripts/holoo-lab-counts.ps1
+6
@@ -25,6 +25,11 @@ try {
25
foreach($i in @(1,3,4,5,7,8,9,11,12,13,14,15,16,17)){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
+ # Defense in depth: inherited public EXECUTE and persistent DML grants are not database-wide read-only.
29
+ # The earlier separate-connection audit is deliberately BLOCKED; this protects against future accidental relaxation.
30
+ $q.CommandText="SELECT COUNT_BIG(*) FROM sys.database_permissions WHERE grantee_principal_id=DATABASE_PRINCIPAL_ID('public') AND state_desc IN ('GRANT','GRANT_WITH_GRANT_OPTION') AND ((permission_name='EXECUTE') OR (permission_name IN ('INSERT','UPDATE','DELETE','ALTER','CONTROL','TAKE OWNERSHIP')))"
31
+ $publicRisks=[long]$q.ExecuteScalar()
32
+ if($publicRisks -ne 0){throw 'SQL same-connection inherited public privilege gate BLOCKED'}
33
$q.CommandText=$queries[$QueryId]
34
$value=[long]$q.ExecuteScalar()
35
[pscustomobject]@{database='HolooBackup_050808_LAB_20261110';queryId=$QueryId;count=$value;readOnly=$true}|ConvertTo-Json -Compress
@@ -32,3 +37,4 @@ try {
37
38
39
40
+
tests/holoo-lab-reader.test.mjs
+10
@@ -41,3 +41,13 @@ test('same-connection gate checks server-level elevated privileges',()=>{
41
assert.match(source,/HAS_PERMS_BY_NAME\(NULL,NULL,'CONTROL SERVER'\)/);
42
assert.match(source,/@\(1,3,4,5,7,8,9,11,12,13,14,15,16,17\)/);
43
});
44
+
45
+test('same-connection gate blocks inherited public EXECUTE and DML before counts',()=>{
46
+ const source=readFileSync(fileURLToPath(new URL('../scripts/holoo-lab-counts.ps1',import.meta.url)),'utf8');
47
+ const grantCheck=source.indexOf("grantee_principal_id=DATABASE_PRINCIPAL_ID('public')");
48
+ const countQuery=source.indexOf('$q.CommandText=$queries[$QueryId]');
49
+ assert.ok(grantCheck>source.indexOf('$c.Open()') && countQuery>grantCheck);
50
+ assert.match(source,/permission_name='EXECUTE'/);
51
+ assert.match(source,/permission_name IN \('INSERT','UPDATE','DELETE'/);
52
+ assert.match(source,/inherited public privilege gate BLOCKED/);
53
+});