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

fix(A03): deny direct audit writes in all transaction mutation APIs

davoodmehraban89 committed Oct 19, 2026 at 18:35 UTC 470044c134dfc9d8be6a4527919f2c0667247662
1 file changed +12 -4
src/core/StorageService.js
+12 -4
@@ -1,3 +1,5 @@
1 +import { isAuditServiceRow, AuditService } from './AuditService.js';
2 +
3 // ============================================================
4 // StorageService — IndexedDB wrapper
5 // v5: جدول‌های حسابداری دوبل و مهاجرت سازگار با نسخه‌های قبلی
@@ -234,6 +236,11 @@ class StorageServiceImpl {
236 req.onerror = () => rej(req.error);
237 });
238 const os = (name) => tx.objectStore(name);
239 + const guardAudit = (store, row) => {
240 + if (store === 'audit_events' && !isAuditServiceRow(row)) {
241 + throw new Error('ثبت مستقیم رویداد ممیزی مجاز نیست؛ از AuditService استفاده کنید');
242 + }
243 + };
244
245 const api = {
246 get: (s, id) => wrap(os(s).get(id)),
@@ -241,13 +248,13 @@ class StorageServiceImpl {
248 getAllByIndex: (s, index, key) => wrap(os(s).index(index).getAll(key)).then(r => r || []),
249 count: (s) => wrap(os(s).count()),
250 // Audit/correction history may be appended, never overwritten.
244 - put: (s, obj) => { this._touch(obj); return wrap(
251 + put: (s, obj) => { guardAudit(s, obj); this._touch(obj); return wrap(
252 APPEND_ONLY_STORES.has(s) ? os(s).add(obj) : os(s).put(obj)
253 ).then(() => obj); },
247 - putRaw: (s, obj) => { if (!obj.id) obj.id = this.uid(); return wrap(
254 + putRaw: (s, obj) => { guardAudit(s, obj); if (!obj.id) obj.id = this.uid(); return wrap(
255 APPEND_ONLY_STORES.has(s) ? os(s).add(obj) : os(s).put(obj)
256 ).then(() => obj); },
250 - add: (s, obj) => { if (!obj.id) obj.id = this.uid(); return wrap(os(s).add(obj)).then(() => obj); },
257 + add: (s, obj) => { guardAudit(s, obj); if (!obj.id) obj.id = this.uid(); return wrap(os(s).add(obj)).then(() => obj); },
258 delete: (s, id) => APPEND_ONLY_STORES.has(s)
259 ? Promise.reject(new Error('حذف مستقیم سابقه ممیزی یا اصلاح سند مجاز نیست'))
260 : wrap(os(s).delete(id)).then(() => undefined),
@@ -440,7 +447,8 @@ class StorageServiceImpl {
447 throw new Error('بازنویسی سابقه ممیزی یا اصلاح سند از پشتیبان مجاز نیست');
448 }
449 } else {
443 - await tx.add(store, { ...item });
450 + if (store === 'audit_events') await AuditService.restoreHistorical(tx, item);
451 + else await tx.add(store, { ...item });
452 }
453 }
454 } else {