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

feat(A03): validate audit chain and backup anchor before restore

davoodmehraban89 committed Oct 20, 2026 at 08:38 UTC bb587377716367cd5d01b53659c95b61e12799ff
1 file changed +7
src/controllers/SettingsController.js
+7
@@ -185,6 +185,13 @@ class SettingsControllerImpl {
185 }
186 }
187
188 + const history = backup.data.audit_events || [];
189 + if (!Array.isArray(history)) throw new Error('سوابق ممیزی پشتیبان نامعتبر است');
190 + if (backup.auditAnchor !== undefined || history.some(row => row.eventHash !== undefined)) {
191 + const result = verifyChain(history, backup.auditAnchor ?? null);
192 + if (!result.valid) throw new Error('زنجیره ممیزی یا لنگر پشتیبان نامعتبر است');
193 + }
194 +
195 const companyId = await DataScope.companyId();
196 // Prevent an accidental merge of one company's books into another.
197 // Explicit cross-company migration is a separate, intentional operation.