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

fix(A06): authorize sensitive backup and wipe actions in controller

* fix(A06): enforce admin authorization before backup export and data wipe * test(A06): verify non-admin backup export and wipe are denied without data loss

davoodmehraban89 committed Oct 14, 2026 at 22:30 UTC 6c263d9b53a9239594c6e678f8cd6c4c9654e447
2 files changed +39
src/controllers/SettingsController.js
+2
@@ -28,6 +28,7 @@ class SettingsControllerImpl {
28 // بکاپ‌گیری
29 // ============================================================
30 async exportBackup() {
31 + if (!Auth.isAdmin()) throw new Error('تهیه فایل پشتیبان فقط توسط مدیر مجاز است');
32 const user = Auth.current();
33 if (!user) throw new Error('کاربر یافت نشد');
34
@@ -161,6 +162,7 @@ class SettingsControllerImpl {
162 // پاک کردن همه‌ی داده‌ها
163 // ============================================================
164 async wipeAll() {
165 + if (!Auth.isAdmin()) throw new Error('حذف اطلاعات فقط توسط مدیر مجاز است');
166 await StorageService.clearAll();
167 // sessionStorage و localStorage تمیز
168 sessionStorage.clear();
tests/backup-admin-authorization.test.mjs new
+37
@@ -0,0 +1,37 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import 'fake-indexeddb/auto';
4 +import { StorageService } from '../src/core/StorageService.js';
5 +import { Auth } from '../src/core/Auth.js';
6 +import { CompanyService } from '../src/core/CompanyService.js';
7 +import { SettingsController } from '../src/controllers/SettingsController.js';
8 +
9 +test('A06: ordinary users cannot export company backup data', async () => {
10 + await StorageService.clearAll();
11 + await StorageService.put('companies', { id: 'c1', name: 'Company' });
12 + await StorageService.put('contacts', { id: 'secret-customer', companyId: 'c1', name: 'Private' });
13 + CompanyService.activeCompanyId = 'c1';
14 + Auth.currentUser = { id: 'staff', role: 'user', companyIds: ['c1'], username: 'staff' };
15 + await assert.rejects(SettingsController.exportBackup(), /فقط توسط مدیر/);
16 + assert.equal((await StorageService.get('contacts', 'secret-customer')).name, 'Private');
17 +});
18 +
19 +test('A06: ordinary users cannot erase company or global data', async () => {
20 + await StorageService.clearAll();
21 + await StorageService.put('companies', { id: 'c1', name: 'Company' });
22 + await StorageService.put('contacts', { id: 'important-customer', companyId: 'c1', name: 'Keep' });
23 + Auth.currentUser = { id: 'staff', role: 'user', companyIds: ['c1'], username: 'staff' };
24 + await assert.rejects(SettingsController.wipeAll(), /فقط توسط مدیر/);
25 + assert.ok(await StorageService.get('companies', 'c1'));
26 + assert.equal((await StorageService.get('contacts', 'important-customer')).name, 'Keep');
27 +});
28 +
29 +test('A06: administrator retains authorized export capability', async () => {
30 + await StorageService.clearAll();
31 + await StorageService.put('companies', { id: 'c1', name: 'Company' });
32 + CompanyService.activeCompanyId = 'c1';
33 + Auth.currentUser = { id: 'manager', role: 'admin', username: 'manager' };
34 + const backup = await SettingsController.exportBackup();
35 + assert.equal(backup.scope, 'company');
36 + assert.equal(backup.companyId, 'c1');
37 +});