سامانه صدور فاکتور و حسابداری

Identity: authorize privileged backup operations

davoodmehraban89 committed Oct 2, 2026 at 11:46 UTC a4fa96b9ac32dd6b1f2c2feaf207eb853cef248e
5 files changed +25 -2
.github/workflows/quality.yml
+3 -1
@@ -54,6 +54,8 @@ jobs:
54 run: node scripts/identity-wave5a-check.mjs
55 - name: Wave 5b offboarding/revocation invariants
56 run: node scripts/identity-wave5b-check.mjs
57 + - name: Wave 5c privileged backup authorization invariants
58 + run: node scripts/identity-wave5c-check.mjs
59 - name: Office Slice C1 invariants
60 run: node scripts/office-slice-c1-check.mjs
61 - name: Office Slice C2 invariants
@@ -91,7 +93,7 @@ jobs:
93 - name: Real DOM smoke
94 run: |
95 python3 -m http.server 4173 >/tmp/finora-http.log 2>&1 &
94 - npx playwright test scripts/dom-smoke.spec.js scripts/platform-office.spec.js scripts/enterprise-license.spec.js scripts/enterprise-role.spec.js scripts/enterprise-invitation.spec.js scripts/enterprise-org-ux.spec.js scripts/identity-wave5a.spec.js scripts/identity-wave5b.spec.js scripts/office-slice-c1.spec.js scripts/office-slice-c2.spec.js scripts/office-slice-c3.spec.js scripts/office-slice-c4.spec.js scripts/office-slice-c5.spec.js scripts/office-slice-c6.spec.js scripts/office-slice-c7.spec.js scripts/office-slice-c8.spec.js scripts/office-slice-c8-runtime.spec.js scripts/request-workflow-d2.spec.js scripts/request-workflow-d3b.spec.js scripts/request-workflow-d3c.spec.js scripts/request-workflow-d4a.spec.js scripts/taxpayer-print.spec.js scripts/pages-artifact.spec.js --reporter=line --workers=1
96 + npx playwright test scripts/dom-smoke.spec.js scripts/platform-office.spec.js scripts/enterprise-license.spec.js scripts/enterprise-role.spec.js scripts/enterprise-invitation.spec.js scripts/enterprise-org-ux.spec.js scripts/identity-wave5a.spec.js scripts/identity-wave5b.spec.js scripts/identity-wave5c.spec.js scripts/office-slice-c1.spec.js scripts/office-slice-c2.spec.js scripts/office-slice-c3.spec.js scripts/office-slice-c4.spec.js scripts/office-slice-c5.spec.js scripts/office-slice-c6.spec.js scripts/office-slice-c7.spec.js scripts/office-slice-c8.spec.js scripts/office-slice-c8-runtime.spec.js scripts/request-workflow-d2.spec.js scripts/request-workflow-d3b.spec.js scripts/request-workflow-d3c.spec.js scripts/request-workflow-d4a.spec.js scripts/taxpayer-print.spec.js scripts/pages-artifact.spec.js --reporter=line --workers=1
97
98 identity-wave5a-database:
99 runs-on: ubuntu-latest
PROJECT_STATE.md
+1
@@ -14,6 +14,7 @@ This is high-assurance accounting/ERP software. Posted financial history, tenant
14 ## Current change ledger
15 | Date | Request / decision | Status | Evidence / next action |
16 |---|---|---|---|
17 +| 2026-10-02 | Wave 5c privileged full backup/restore authorization after offboarding hardening. | **IMPLEMENTED ON BRANCH / CI PENDING** | Full organization export/restore now requires both fresh server membership revalidation and existing organization-management authority (owner or `core:configure`); restore performs the check before reading the selected file. Static + Real-DOM denial-path gates added. This is an application-layer privilege boundary over data already readable under server RLS; no new schema/RLS/auth-role change was introduced. |
18 | 2026-10-02 | Supabase security-advisor intent review for authenticated-callable SECURITY DEFINER RPCs and three private C8 no-policy tables. | **LIVE INTENT REVIEW VERIFIED / NO DDL REQUIRED** | Production `hcsixhqbyuhpshfwqpjx` reviewed read-only. All 20 public advisor-listed SECURITY DEFINER functions use `search_path=''` and enforce caller/admin/org/capability/read-scope checks appropriate to their RPC contract; warning is retained as an intentional privileged-RPC boundary rather than weakened. The three private C8 tables have RLS enabled, zero policies, and no anon/authenticated CRUD grants, confirming deliberate deny-by-default private storage behind controlled RPCs. Evidence: `docs/SECURITY_ADVISOR_INTENT_REVIEW_2026-10-02.md`. Leaked-password protection remains an external Auth-setting gap. |
19 | 2026-10-02 | Wave 5b offboarding/revocation client fail-closed remediation from Round 29. | **MERGED / MAIN CI + RELEASE + DEPLOY VERIFIED** | PR #32 merged as `e9831e4d23fceae3a30359fe2eca8743087bb6b5`. Main Quality `36982398280` SUCCESS, Security `36982398238` SUCCESS, Release gate `36982548804` SUCCESS, gated Pages `36982584408` SUCCESS. Added 30s + visibility membership revalidation, known-revocation tenant-memory/cache purge, stale `currentUser` removal, sensitive-view lock, alternate-org recovery path, no-membership sign-out, and fresh server membership gate before bulk export. Persistent two-real-user production E2E and capability-specific privileged export authorization remain NOT VERIFIED. |
20 | 2026-10-02 | Permanent project constraint: user operates from Iran and cannot use paid infrastructure, paid APIs, international-card billing, or services that require a later paid upgrade for essential operation. Railway is excluded from Finora runtime/deployment. | **ACTIVE ARCHITECTURE CONSTRAINT** | Use only genuinely no-cost capabilities for required operation; do not create paid resources or make Finora depend on a service whose essential path later requires billing. GitHub + Supabase remain current sources of truth; any future infrastructure choice must pass this zero-cost/no-billing constraint first. |
js/backup.js
+4 -1
@@ -1,5 +1,6 @@
1 async function exportDataBlob(){
2 if(typeof window.requireFreshFinoraMembership==='function'&&!await window.requireFreshFinoraMembership()){alert('خروجی‌گیری متوقف شد؛ عضویت سازمانی باید دوباره از سرور تأیید شود.');return;}
3 + if(typeof window.finoraCanManageOrganization==='function'&&!window.finoraCanManageOrganization()){alert('خروجی کامل سازمان فقط برای مالک یا عضو دارای مجوز مدیریت سازمان مجاز است.');return;}
4 const userExport={user:currentUser?.username,exportedAt:new Date().toISOString(),companies:getMyCompanies(),contacts:getMyContacts(),products:getMyProducts(),invoices:getMyInvoices(),purchases:getMyPurchases(),cheques:getMyCheques(),expenses:getMyExpenses(),payments:getMyPayments(),fiscalYears:getMyFiscalYears(),accounts:getMyAccounts(),dimensionTypes:getMyDimensionTypes(),dimensionValues:getMyDimensionValues(),accountDimensionRules:getMyAccountDimensionRules(),branches:getMyBranches(),projects:getMyGlobalProjects(),projectLinks:afOwned('projectLinks'),postingProfiles:getMyPostingProfiles(),journalVouchers:getMyJournalVouchers(),journalLines:getMyJournalLines(),journalLineDimensions:getMyJournalLineDimensions(),contracts:getMyContracts(),contractAmendments:getMyContractAmendments(),contractParties:getMyContractParties(),contractDeductions:getMyContractDeductions(),guarantees:getMyGuarantees(),guaranteeEvents:getMyGuaranteeEvents(),contractStatements:getMyContractStatements(),phase4Audit:getMyPhase4Audit(),warehouses:getMyWarehouses(),stockMovements:getMyStockMovements(),inventoryCounts:getMyInventoryCounts(),fixedAssets:getMyFixedAssets(),assetDepreciations:getMyAssetDepreciations(),currencies:getMyCurrencies(),exchangeRates:getMyExchangeRates(),costCenters:getMyCostCenters(),importBatches:getMyImportBatches(),integrationConnections:getMyIntegrationConnections(),integrationOutbox:getMyIntegrationOutbox(),phase5Audit:getMyPhase5Audit(),settings:getMySettings()};
5 const blobString="data:text/json;charset=utf-8,"+encodeURIComponent(JSON.stringify(userExport,null,2));
6 const anchor=document.createElement('a');
@@ -9,9 +10,11 @@ async function exportDataBlob(){
10 anchor.click();
11 anchor.remove();
12 }
12 -function importDataBlob(event){
13 +async function importDataBlob(event){
14 if(!requireWrite())return;
15 if(!currentUser)return;
16 + if(typeof window.requireFreshFinoraMembership==='function'&&!await window.requireFreshFinoraMembership()){event.target.value='';alert('بازیابی متوقف شد؛ عضویت سازمانی باید دوباره از سرور تأیید شود.');return;}
17 + if(typeof window.finoraCanManageOrganization==='function'&&!window.finoraCanManageOrganization()){event.target.value='';alert('بازیابی کامل سازمان فقط برای مالک یا عضو دارای مجوز مدیریت سازمان مجاز است.');return;}
18 const file=event.target.files[0];
19 if(!file)return;if(file.size>20*1024*1024){event.target.value='';alert('حجم فایل پشتیبان نباید بیشتر از ۲۰ مگابایت باشد.');return;}
20 const reader=new FileReader();
scripts/identity-wave5c-check.mjs new
+6
@@ -0,0 +1,6 @@
1 +import fs from 'node:fs';import assert from 'node:assert/strict';
2 +const backup=fs.readFileSync('js/backup.js','utf8');
3 +assert(backup.includes("!window.finoraCanManageOrganization()"),'privileged backup authorization gate missing');
4 +assert(backup.includes("async function importDataBlob"),'restore must support fresh asynchronous membership verification');
5 +assert((backup.match(/requireFreshFinoraMembership/g)||[]).length>=2,'export and restore must both revalidate membership');
6 +console.log('Wave 5c privileged backup authorization invariants passed');
scripts/identity-wave5c.spec.js new
+11
@@ -0,0 +1,11 @@
1 +const {test,expect}=require('@playwright/test');
2 +test('Wave 5c full export is denied without organization-management authority',async({page})=>{
3 + await page.goto('http://127.0.0.1:4173/index.html',{waitUntil:'domcontentloaded'});await page.waitForFunction(()=>typeof exportDataBlob==='function');
4 + const r=await page.evaluate(async()=>{let clicks=0,alerts=[];const oldCreate=document.createElement.bind(document),oldAlert=window.alert;window.requireFreshFinoraMembership=async()=>true;window.finoraCanManageOrganization=()=>false;document.createElement=(tag)=>{const el=oldCreate(tag);if(tag==='a')el.click=()=>clicks++;return el};window.alert=m=>alerts.push(String(m));try{await exportDataBlob()}finally{document.createElement=oldCreate;window.alert=oldAlert}return{clicks,alerts}});
5 + expect(r.clicks).toBe(0);expect(r.alerts.join(' ')).toContain('مجوز مدیریت سازمان');
6 +});
7 +test('Wave 5c restore is denied before reading file without organization-management authority',async({page})=>{
8 + await page.goto('http://127.0.0.1:4173/index.html',{waitUntil:'domcontentloaded'});await page.waitForFunction(()=>typeof importDataBlob==='function');
9 + const r=await page.evaluate(async()=>{currentUser={id:'u1',organizationId:'o1',subscription:{status:'active',type:'lifetime'}};let alerts=[];const oldAlert=window.alert;window.alert=m=>alerts.push(String(m));window.requireFreshFinoraMembership=async()=>true;window.finoraCanManageOrganization=()=>false;const event={target:{value:'x',files:[new File(['{}'],'backup.json',{type:'application/json'})]}};try{await importDataBlob(event);return{value:event.target.value,alerts}}finally{window.alert=oldAlert}});
10 + expect(r.value).toBe('');expect(r.alerts.join(' ')).toContain('مجوز مدیریت سازمان');
11 +});