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

fix(A03): prevent normal IndexedDB writes from rewriting or deleting audit history

davoodmehraban89 committed Oct 16, 2026 at 22:16 UTC 56a98da45f7a9cf662c7a4b7d10a264f8ed9c80a
1 file changed +15 -4
src/core/StorageService.js
+15 -4
@@ -240,10 +240,17 @@ class StorageServiceImpl {
240 getAll: (s) => wrap(os(s).getAll()).then(r => r || []),
241 getAllByIndex: (s, index, key) => wrap(os(s).index(index).getAll(key)).then(r => r || []),
242 count: (s) => wrap(os(s).count()),
243 - put: (s, obj) => { this._touch(obj); return wrap(os(s).put(obj)).then(() => obj); },
244 - putRaw: (s, obj) => { if (!obj.id) obj.id = this.uid(); return wrap(os(s).put(obj)).then(() => obj); },
243 + // Audit/correction history may be appended, never overwritten.
244 + put: (s, obj) => { this._touch(obj); return wrap(
245 + APPEND_ONLY_STORES.has(s) ? os(s).add(obj) : os(s).put(obj)
246 + ).then(() => obj); },
247 + putRaw: (s, obj) => { if (!obj.id) obj.id = this.uid(); return wrap(
248 + APPEND_ONLY_STORES.has(s) ? os(s).add(obj) : os(s).put(obj)
249 + ).then(() => obj); },
250 add: (s, obj) => { if (!obj.id) obj.id = this.uid(); return wrap(os(s).add(obj)).then(() => obj); },
246 - delete: (s, id) => wrap(os(s).delete(id)).then(() => undefined),
251 + delete: (s, id) => APPEND_ONLY_STORES.has(s)
252 + ? Promise.reject(new Error('حذف مستقیم سابقه ممیزی یا اصلاح سند مجاز نیست'))
253 + : wrap(os(s).delete(id)).then(() => undefined),
254 clear: (s) => wrap(os(s).clear()).then(() => undefined)
255 };
256
@@ -294,7 +301,8 @@ class StorageServiceImpl {
301 async put(store, obj) {
302 if (globalThis.FINORA?.License && !['users', 'settings', 'logs'].includes(store)) globalThis.FINORA.License.assertWritable();
303 this._touch(obj);
297 - await this._exec(store, 'readwrite', s => s.put(obj));
304 + await this._exec(store, 'readwrite',
305 + s => APPEND_ONLY_STORES.has(store) ? s.add(obj) : s.put(obj));
306 return obj;
307 }
308
@@ -307,6 +315,9 @@ class StorageServiceImpl {
315 }
316
317 async delete(store, id) {
318 + if (APPEND_ONLY_STORES.has(store)) {
319 + throw new Error('حذف مستقیم سابقه ممیزی یا اصلاح سند مجاز نیست');
320 + }
321 if (globalThis.FINORA?.License && !['users', 'settings', 'logs'].includes(store)) globalThis.FINORA.License.assertWritable();
322 await this._exec(store, 'readwrite', s => s.delete(id));
323 }