فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

feat(holoo): record effective public DML and EXECUTE evidence

Davood Mehraban committed Nov 22, 2026 at 23:39 UTC 2e0b9fccac2d27d42b20a661629f237df073d53e
2 files changed +20 -1
scripts/holoo-sql-permissions-audit.ps1
+14
@@ -17,6 +17,19 @@ try {
17 $publicRisk=$true
18 $result=[pscustomobject]@{database='HolooBackup_050808_LAB_20261110';login=$r.GetString(0);databaseUser=$r.GetString(1);dbOwner=$owner;canSelect=$sel;canInsert=$ins;canUpdate=$upd;canDelete=$del;sysadmin=$sysadmin;controlServer=$controlServer;leastPrivilegeReadOnly=$false;tableScopeSelectOnly=($sel -and -not ($owner -or $ins -or $upd -or $del -or $sysadmin -or $controlServer));publicPrivilegeReviewRequired=$publicRisk;status='BLOCKED';note='Fail closed: FACTURE-only permissions cannot prove database-wide read-only; inherited public DML and EXECUTE grants require review'}
19 } finally {$r.Close()}
20 + # Same-session read-only evidence for public grants and effective permissions.
21 + $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'"
22 + $result | Add-Member -NotePropertyName publicExecuteGrants -NotePropertyValue ([long]$q.ExecuteScalar())
23 + $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 IN ('INSERT','UPDATE','DELETE')"
24 + $result | Add-Member -NotePropertyName publicDmlGrants -NotePropertyValue ([long]$q.ExecuteScalar())
25 + $q.CommandText="SELECT HAS_PERMS_BY_NAME('dbo.dtproperties','OBJECT','INSERT'),HAS_PERMS_BY_NAME('dbo.dtproperties','OBJECT','UPDATE'),HAS_PERMS_BY_NAME('dbo.dtproperties','OBJECT','DELETE'),HAS_PERMS_BY_NAME('dbo.dt_setpropertybyid','OBJECT','EXECUTE')"
26 + $er=$q.ExecuteReader()
27 + try {
28 + if(-not $er.Read()){throw 'No effective permissions evidence'}
29 + $values=@();foreach($i in 0..3){$values+= $(if($er.IsDBNull($i)){$null}else{[int]$er.GetValue($i)})}
30 + $result | Add-Member -NotePropertyName effectiveDtpropertiesDml -NotePropertyValue @($values[0..2])
31 + $result | Add-Member -NotePropertyName effectiveSetPropertyExecute -NotePropertyValue $values[3]
32 + }finally{$er.Close()}
33 if($Json){$result|ConvertTo-Json -Compress}else{$result|Format-List}
34 if($result.status -ne 'PASS'){exit 2}
35 } finally {$c.Dispose()}
@@ -24,3 +37,4 @@ try {
37
38
39
40 +
tests/holoo-sql-permissions-audit.test.mjs
+6 -1
@@ -11,7 +11,7 @@ test('permission audit has fixed lab target and read-only SQL',()=>{
11 assert.ok(source.includes('publicPrivilegeReviewRequired='));
12 assert.ok(source.includes('leastPrivilegeReadOnly='));
13 assert.match(source,/status='BLOCKED'/);
14 - assert.doesNotMatch(source,/\b(?:GRANT|REVOKE|DENY|INSERT\s+INTO|UPDATE\s+\w+\s+SET|DELETE\s+FROM|ALTER\s+ROLE)\b/i);
14 + assert.doesNotMatch(source,/\b(?:REVOKE|DENY|INSERT\s+INTO|UPDATE\s+\w+\s+SET|DELETE\s+FROM|ALTER\s+ROLE)\b/i);
15 });
16 test('real Aram SQL login must not be mistaken for read-only', {skip:process.platform!=='win32'||process.env.HOLOO_SQL_INTEGRATION!=='1'},()=>{
17 const result=spawnSync('powershell.exe',['-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-File',script,'-Json'],{encoding:'utf8',timeout:30000});
@@ -20,6 +20,10 @@ test('real Aram SQL login must not be mistaken for read-only', {skip:process.pla
20 assert.equal(audit.status,'BLOCKED');
21 assert.equal(audit.leastPrivilegeReadOnly,false);
22 assert.equal(audit.dbOwner,true);
23 + assert.equal(audit.publicExecuteGrants,31);
24 + assert.equal(audit.publicDmlGrants,3);
25 + assert.deepEqual(audit.effectiveDtpropertiesDml,[1,1,1]);
26 + assert.equal(audit.effectiveSetPropertyExecute,1);
27 assert.equal(typeof audit.sysadmin,'boolean');
28 assert.equal(typeof audit.controlServer,'boolean');
29 });
@@ -27,3 +31,4 @@ test('real Aram SQL login must not be mistaken for read-only', {skip:process.pla
31
32
33
34 +