فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix(A03): authorize audit writes only from AuditService
davoodmehraban89 committed
Oct 19, 2026 at 18:34 UTC
f8e6196d17c78b341bfa474cb7dd88c75f62074a
1 file changed
+16
src/core/AuditService.js
+16
@@ -2,6 +2,9 @@ import { Auth } from './Auth.js';
2
import { DataScope } from './DataScope.js';
3
import { StorageService } from './StorageService.js';
4
5
+const trustedAuditRows = new WeakSet();
6
+export const isAuditServiceRow = row => !!row && trustedAuditRows.has(row);
7
+
8
const VALID_TYPES = new Set([
9
'journal_posted', 'journal_reversed', 'period_closed',
10
'commercial_journal_posted', 'draft_posted', 'draft_updated',
@@ -40,10 +43,23 @@ class AuditServiceImpl {
43
};
44
// add() cannot overwrite an earlier event and a unique commandKey makes
45
// replay fail atomically. No externally mutable audit status is stored.
46
+ trustedAuditRows.add(event);
47
await tx.add('audit_events', event);
48
return event;
49
}
50
51
+ // Historical restore is a distinct audited entry point; callers must
52
+ // validate snapshot ownership and immutable conflicts before invoking it.
53
+ async restoreHistorical(tx, row) {
54
+ if (!row || typeof row !== 'object' || Array.isArray(row) ||
55
+ !validId(row.id) || !validId(row.companyId)) {
56
+ throw new Error('رکورد تاریخچه ممیزی نامعتبر است');
57
+ }
58
+ const copy = { ...row };
59
+ trustedAuditRows.add(copy);
60
+ await tx.add('audit_events', copy);
61
+ }
62
+
63
async list({ limit = 100 } = {}) {
64
if (!Auth.isAdmin()) throw new Error('مشاهده ردپای حسابرسی فقط برای مدیر مجاز است');
65
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 500) {