فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
feat(A03): reject full backups with mismatched audit head anchors
davoodmehraban89 committed
Oct 20, 2026 at 08:43 UTC
5b141583835978daa590a9655458e3c79e932401
1 file changed
+17
src/core/StorageService.js
+17
@@ -444,6 +444,23 @@ class StorageServiceImpl {
444
}
445
}
446
447
+ if (json.auditAnchors !== undefined) {
448
+ if (!json.auditAnchors || typeof json.auditAnchors !== 'object' || Array.isArray(json.auditAnchors)) {
449
+ throw new Error('لنگرهای ممیزی پشتیبان نامعتبر است');
450
+ }
451
+ const companyIds = new Set((json.data.audit_events || []).map(row => row.companyId));
452
+ if (Object.keys(json.auditAnchors).length !== companyIds.size) {
453
+ throw new Error('لنگرهای ممیزی پشتیبان ناقص است');
454
+ }
455
+ for (const companyId of companyIds) {
456
+ const rows = json.data.audit_events.filter(row => row.companyId === companyId)
457
+ .sort((a,b) => (a.chainIndex ?? 0) - (b.chainIndex ?? 0));
458
+ if (!verifyChain(rows, json.auditAnchors[companyId]).valid) {
459
+ throw new Error('زنجیره ممیزی یا لنگر پشتیبان کامل نامعتبر است');
460
+ }
461
+ }
462
+ }
463
+
464
await this.transaction(STORES, async tx => {
465
const auditRows = (json.data.audit_events || []).filter(item => !!item);
466
for (const companyId of new Set(auditRows.map(row => row.companyId))) {