@davoodmehraban89 / Factor-easy / commits / 56ec0b0
Fork 0

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

Security: record Supabase privileged RPC intent review

* Security: document privileged RPC intent review * State: verify Wave 5b protected-main rollout

davoodmehraban89 committed Oct 2, 2026 at 11:43 UTC 56ec0b042a573711dcf8bd18cc7545280462f610
2 files changed +36 -3
PROJECT_STATE.md
+4 -3
@@ -14,7 +14,8 @@ 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 5b offboarding/revocation client fail-closed remediation from Round 29. | **IMPLEMENTED ON BRANCH / CI PENDING** | 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. Static + Real-DOM regression gates added. Persistent two-real-user production E2E and capability-specific privileged export authorization remain NOT VERIFIED. |
17 +| 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. |
18 +| 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. |
19 | 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. |
20 | 2026-10-02 | Gmail/GitHub failure review: latest Wave 5a Quality run failed only because the disposable PostgreSQL harness lacked Supabase roles `anon`/`authenticated`; Security latest run is green. | **TEST HARNESS VERIFIED** | Added the two no-login Supabase compatibility roles to the disposable identity DB bootstrap. Wave 5a identity DB gate passed on PR head and main Quality `36980655736`; the earlier failure was harness-only. |
21 | 2026-10-02 | Second CI retest showed the safety-check regex itself was over-escaped. | **REGEX FIX VERIFIED** | Normalized regex literals to match the workflow labels/variable gate exactly; main Security `36980655725` passed Release/QA safety + CodeQL. |
@@ -73,10 +74,10 @@ Posted accounting history is immutable and balanced; tenant isolation is enforce
74 ## NOT VERIFIED / external boundary
75 Automatic background scheduling for SLA scans; delivery/dispatch consumers for D3c outbox intents; authenticated two-real-user production browser E2E with a persistent legitimate non-owner member; automatic external invitation email delivery; owner-approved accounting cutover; real Persian OCR accuracy/provider; qualified digital signature; physical printer; live external adapters; GitHub Dependency graph/enforceable dependency review; leaked-password protection; PostgreSQL upgrade; CodeQL v4 migration; external BPM/provider integration remain outside verified scope.
76
76 -The connected Supabase production target is `hcsixhqbyuhpshfwqpjx` (`Finora`). Live migration history now includes C8, D1–D4a, request security Waves 1–4, `request_wave4b_scheduler_outbox_delivery` version `20261002072526`, and `identity_wave5a_bootstrap` version `20261002075156`. Read-only production reconciliation after Wave 4b confirmed both scheduler evidence tables, stable destination-command/dead-letter outbox columns, and scheduler/claim/complete/fail/replay RPC contracts exist. Security advisor still reports 3 private C8 tables with RLS but no policies, 20 authenticated-callable SECURITY DEFINER functions requiring intent-by-intent review, and leaked-password protection disabled.
77 +The connected Supabase production target is `hcsixhqbyuhpshfwqpjx` (`Finora`). Live migration history now includes C8, D1–D4a, request security Waves 1–4, `request_wave4b_scheduler_outbox_delivery` version `20261002072526`, and `identity_wave5a_bootstrap` version `20261002075156`. Read-only production reconciliation after Wave 4b confirmed both scheduler evidence tables, stable destination-command/dead-letter outbox columns, and scheduler/claim/complete/fail/replay RPC contracts exist. Security advisor still reports 3 private C8 tables with RLS but no policies and 20 authenticated-callable SECURITY DEFINER functions; live intent review on 2026-10-02 verified these as deliberate deny-by-default private storage and guarded privileged RPC boundaries, respectively. Leaked-password protection remains disabled.
78
79 ## Exact next executable work
79 -1. Continue Wave 5 offboarding/session-revocation remediation plus persistent legitimate non-owner E2E, and close the remaining authenticated SECURITY DEFINER intent review without weakening required tenant/capability checks.
80 +1. Finish Wave 5 offboarding/session-revocation verification on protected main, then execute persistent legitimate non-owner E2E when a second durable test identity is available without weakening tenant/capability checks.
81 2. Keep D4c destination consumers disabled until a real destination adapter enforces `destination_command_key` idempotency and its authorization/audit behavior is adversarially verified; automatic scheduler invocation remains a separate operational verification.
82 3. Resolve remaining platform-security gaps: formalize the three private C8 no-policy contracts, enable leaked-password protection when supported by the connected Auth control surface, and keep Dependency Review marked unavailable until Dependency Graph is enabled.
83
docs/SECURITY_ADVISOR_INTENT_REVIEW_2026-10-02.md new
+32
@@ -0,0 +1,32 @@
1 +# Supabase Security Advisor Intent Review — 2026-10-02
2 +
3 +Target: `hcsixhqbyuhpshfwqpjx` (Finora, ACTIVE_HEALTHY). Review mode: read-only production catalog/function inspection. No DDL or production data mutation was performed.
4 +
5 +## Result
6 +
7 +The advisor reports 20 `public` SECURITY DEFINER functions executable by `authenticated`. This is an intentional RPC boundary, not blanket table access. Live definitions were inspected individually. Every listed function has `SET search_path TO ''`; mutating functions authenticate the caller and enforce either global admin, organization owner/configure capability, module entitlement, target membership, or record-read scope before privileged writes. Read helpers return caller-scoped authorization/entitlement state.
8 +
9 +### Reviewed public RPC groups
10 +
11 +- Global license administration: `admin_cancel_license`, `admin_extend_license`, `admin_set_company_limit`, `admin_set_license`, `admin_set_license_modules`, `admin_set_user_limit`. Each gates mutation through `public.is_admin()`; parameter bounds and existence/current-count checks are present where applicable.
12 +- Caller authorization helpers: `is_admin()` and `has_active_license()`. Both derive state from `auth.uid()` / caller organization membership and do not accept a target identity.
13 +- Office automation: `office_act_on_referral`, `office_archive_search`, `office_classify_correspondence`, `office_link_correspondence`, `office_mark_correspondence_read`, `office_refer_correspondence_v2`, `office_referral_work_queue`. Live definitions bind organization, entitlement, active membership/capability and record visibility as appropriate; referral actions additionally bind the target user/member.
14 +- Enterprise invitations/capacity: `organization_accept_invitation`, `organization_capacity_summary`, `organization_create_invitation`, `organization_expire_invitations`, `organization_revoke_invitation`. Acceptance is authenticated, token-hash bound, expiry checked, email-bound and seat/license gated; management calls require owner/configure authority.
15 +
16 +The warning is therefore retained and documented rather than “fixed” by removing the privilege needed for the RPC contract or by converting functions to invoker semantics without equivalent access paths. Any future new SECURITY DEFINER RPC must repeat the same explicit intent review.
17 +
18 +## Private C8 no-policy tables
19 +
20 +Live catalog verification for `private.office_workflow_events`, `private.office_workflow_instances`, and `private.office_workflow_policy_versions` shows: RLS enabled, policy count 0, and no SELECT/INSERT/UPDATE/DELETE privilege for `authenticated`; `anon` also has no SELECT. This is deliberate deny-by-default private storage behind controlled RPCs. Adding permissive RLS policies merely to silence the advisor would weaken the boundary.
21 +
22 +## Remaining advisor gap
23 +
24 +Leaked-password protection is still disabled in Supabase Auth. It is an external Auth configuration gap and was not changed by SQL. Enable it only through a supported connected Auth control surface; do not simulate it with application-side password lists or paid external services.
25 +
26 +## Acceptance
27 +
28 +- Production target identity rechecked before review.
29 +- No anon access was introduced.
30 +- No authenticated table CRUD was introduced for the private C8 tables.
31 +- No privileged RPC authorization check was weakened.
32 +- No paid infrastructure or external service dependency was added.