سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 14:30 UTC
docs: verify direct Supabase access and record server audit
davoodmehraban89 committed
Sep 28, 2026 at 20:21 UTC
4e9f12e891887ccf2c33b251c5cbed9bdfd46689
6 files changed
+219
-15
PROJECT_STATUS.md
+8
-1
@@ -11,7 +11,14 @@ verification found real defects, so the completion claim was reopened.
11
- Preserved: original financial records, server configuration, main branch/release boundary.
12
- Not claimed: authenticated production E2E, database transaction/immutability
13
enforcement, complete cheque accounting, controlled ledger restore or migration.
14
-- Supabase target `hcsixhqbyuhpshfwqpjx` is not available in the current connection.
14
+- Supabase target `hcsixhqbyuhpshfwqpjx` is reachable by its exact ID. The earlier
15
+ unavailable claim was incorrect: project-list discovery omitted it, but direct
16
+ metadata and SQL reads succeeded. The observed SQL role is read-only; see the
17
+ [connection and server audit](docs/PHASE_3_CONNECTION_AUDIT.md).
18
+- Live metadata confirms owner/license RLS, but not accounting-specific server
19
+ invariants or a posting/reversal RPC. Phase 3 is still not accepted.
20
+- Dependency review remains blocked by repository Dependency graph configuration;
21
+ its gate has not been disabled.
22
- Recovery changes are prepared on `fix/phase3-behavioral-verification`; production
23
acceptance is withheld. See the latest Git commit/PR for publication evidence.
24
docs/PHASE_3_CONNECTION_AUDIT.md
new
+88
@@ -0,0 +1,88 @@
1
+# Phase 3 connection and server audit
2
+
3
+Verified: 2026-09-28, approximately 16:48 UTC. This is a read-only audit, not a
4
+production migration, authenticated application test or completed Phase 3 release.
5
+
6
+## Canonical targets and actual access
7
+
8
+| Component | Verified target | Result |
9
+| --- | --- | --- |
10
+| GitHub | `davoodmehraban89/Factor-easy` | Authenticated account matches owner; draft PR #6 remains open |
11
+| Main branch | `8761d21189d9c4058c3019ea6e42d4103fc83556` | Not changed by this recovery |
12
+| Recovery branch | `fix/phase3-behavioral-verification` | Published client patch at `8209c6f13eb6389260c8528744e5e282d1dd90f3` |
13
+| Supabase | `hcsixhqbyuhpshfwqpjx` | Direct project lookup: Finora, ACTIVE_HEALTHY; metadata and SQL reads succeed |
14
+| Supabase SQL session | `supabase_read_only_user` | `transaction_read_only=on`; CREATE on public is false |
15
+
16
+Both required plugins are installed and working for these verified operations.
17
+The project and organization lists omit the target, while exact-ID lookup works.
18
+The cause is unknown; absence from the list must not be treated as proof of denied
19
+access. No new OAuth connection, write access or permission change is claimed.
20
+Historical context identifies GitHub Pages for Factor-easy; Cloudflare deployment
21
+details from Finora-Invoice belong to a different project.
22
+
23
+## Reproducible server findings
24
+
25
+Run `scripts/sql/phase3-server-audit.sql` against the exact project. It selects
26
+system metadata only and was executed successfully through the official connector.
27
+No customer financial rows, profile identities, tokens or keys are included.
28
+
29
+- `public.records` has RLS enabled. SELECT requires owner identity; INSERT,
30
+ UPDATE and DELETE require owner identity plus an active license. UPDATE includes
31
+ both USING and WITH CHECK. These are access checks, not accounting checks.
32
+- The Phase 3 collections are allowed by `records_collection_check`; migration
33
+ `20260928145306 allow_phase3_double_entry_collections` exists among 12 migrations.
34
+- Other records constraints restrict ID format and JSON size and enforce the owner
35
+ FK and `(owner_id, collection, id)` primary key. No voucher balance, fiscal/company,
36
+ account/dimension, posted-history, source revision or voucher-number constraint
37
+ was found in this table's inspected metadata.
38
+- The only records index is `records_pkey`. The only user trigger is
39
+ `records_touch`, calling a function that updates `updated_at`.
40
+- All seven public functions were inspected: three admin license RPCs, the new-user
41
+ trigger helper, two owner-role/license helpers and the timestamp helper. None is
42
+ an accounting posting or reversal transaction RPC.
43
+- Both anon and authenticated have table-level DML privileges. RLS still applies;
44
+ the inspected policies target authenticated only. These grants alone do NOT mean
45
+ anonymous data access, and no anonymous/authenticated exploit was executed.
46
+
47
+Conclusion: the inspected records write boundary does not enforce the client
48
+ledger invariants. Combined with separate client sync chunks, this is a release
49
+gap requiring a transactional server API and protected direct-write path.
50
+
51
+## Advisor warnings, not confirmed exploits
52
+
53
+Security advisors report five authenticated-callable SECURITY DEFINER functions.
54
+The admin RPC bodies do check `is_admin()`, so the warning alone is not proof of
55
+privilege escalation. The role/license helpers support current RLS and must not
56
+be blindly revoked. Review the [advisor guidance](https://supabase.com/docs/guides/database/database-linter?lint=0029_authenticated_security_definer_function_executable)
57
+with actual function grants and authenticated tests before changing them.
58
+
59
+Advisors also report [leaked-password protection disabled](https://supabase.com/docs/guides/auth/password-security#password-strength-and-leaked-password-protection).
60
+Auth settings were not changed in this audit.
61
+
62
+## GitHub CI evidence and remaining administration task
63
+
64
+On the client patch commit `8209c6f`:
65
+
66
+- [Quality checks succeeded](https://github.com/davoodmehraban89/Factor-easy/actions/runs/36452460077).
67
+- [CodeQL JavaScript succeeded](https://github.com/davoodmehraban89/Factor-easy/actions/runs/36452459920/job/109030340507).
68
+- [Dependency review failed](https://github.com/davoodmehraban89/Factor-easy/actions/runs/36452459920/job/109030340206): Dependency review is not supported under the repository's current configuration; the log asks for Dependency graph to be enabled.
69
+
70
+The connected GitHub interface does not expose repository administration writes.
71
+The [security analysis setting](https://github.com/davoodmehraban89/Factor-easy/settings/security_analysis)
72
+was not changed, and the failing gate was not suppressed. These historical results
73
+are tied to that exact SHA; subsequent commits must have their own CI checked.
74
+
75
+## Next safe implementation boundary
76
+
77
+1. Use a verified writable development environment for schema/API implementation;
78
+ preserve the observed read-only production diagnostic connection.
79
+2. Test atomic source/voucher/line/dimension posting, reversal, immutable history,
80
+ owner/company and fiscal locks, numbering/source concurrency and idempotency.
81
+3. Integrate durable server acknowledgments into the client and prevent the generic
82
+ records-sync path from bypassing ledger rules. Test rollback and interrupted sync.
83
+4. Complete cheque lifecycle and authenticated browser/device acceptance.
84
+5. Resolve repository security configuration and verify all gates before rollout.
85
+
86
+The user has authorized normal commits and pushes. No repeated approval for those
87
+is needed. This does not turn a read-only SQL role into a writer, authorize paid
88
+resources without cost confirmation, or justify mutating production to probe access.
docs/PHASE_3_REDESIGN_VERIFICATION.md
+14
-6
@@ -25,8 +25,10 @@ or proof of database transaction/security guarantees.
25
26
### Open acceptance blockers
27
28
-1. The configured Supabase project `hcsixhqbyuhpshfwqpjx` is not listed by the
29
- current official connection. No substitute project was queried or changed.
28
+1. Direct metadata/SQL reads of `hcsixhqbyuhpshfwqpjx` now succeed despite its
29
+ absence from project-list discovery. The SQL session is read-only. A writable
30
+ development environment is required for server implementation and integration
31
+ tests; no substitute database was used. See PHASE_3_CONNECTION_AUDIT.md.
32
2. `saveDatastore` schedules asynchronous sync; `jeAtomic` is only an in-memory
33
rollback boundary. The generic 200-record upsert chunks are not a financial
34
transaction. Posting, reversal, numbering, idempotency, fiscal/company checks,
@@ -37,6 +39,8 @@ or proof of database transaction/security guarantees.
39
4. Controlled ledger restore, legacy cutover/reconciliation, and authenticated
40
device/browser E2E remain unverified. Import may not introduce/overwrite journal
41
records; unchanged existing journal backup content is allowed as a no-op.
42
+5. PR Dependency review failed on repository Dependency graph configuration;
43
+ Quality checks and CodeQL alone do not make the entire security workflow green.
44
45
No production data or schema was changed during this recovery. The patch does
46
not represent completion of Phase 3 or permission to claim release acceptance.
@@ -79,10 +83,10 @@ Implemented:
83
9. A locked fiscal year rejects new posting.
84
10. Trial balance is derived only from posted/reversed ledger history, never from draft lines.
85
82
-## Historical production-persistence report (not reverified in this recovery)
86
+## Production-persistence evidence
87
Supabase project: hcsixhqbyuhpshfwqpjx
88
85
-The prior report states that the records constraint was extended for:
89
+Metadata inspection at 2026-09-28 16:48 UTC confirmed the records constraint allows:
90
- postingProfiles
91
- journalVouchers
92
- journalLines
@@ -111,7 +115,8 @@ Final Phase 3 integration verifies automatic balanced posting for newly created
115
116
The trial balance includes both the reversed original and its posted opposite entry. Their balances cancel; excluding the original incorrectly leaves an opposite balance. Reversing a reversal is rejected until a complete reversal-chain workflow exists.
117
114
-The current recovery did not reverify the production collections or journal counts because the configured project is unavailable to the connector.
118
+The recovery now verifies production collection metadata and rules through direct
119
+read-only access. Customer rows and journal counts were not queried by this audit.
120
121
122
## Historical CI/deployment evidence — 2026-09-28 (not acceptance)
@@ -123,6 +128,9 @@ Release gates on that head:
128
- Pages build and deployment: success (run 36441163803)
129
- Security checks: success (run 36441164870)
130
126
-The prior report claimed migration `20260928145306 allow_phase3_double_entry_collections`, RLS and advisor verification. Those database claims could not be independently reverified during recovery. RLS ownership alone would not prove balanced or immutable accounting.
131
+Migration `20260928145306 allow_phase3_double_entry_collections` and RLS were
132
+independently verified in the later connection audit. Current advisors returned
133
+warnings, not a clean security acceptance. The inspected records rules enforce
134
+owner/license access but not balanced or immutable accounting.
135
136
Phase 3 remains OPEN. Historical cutover and reconciliation belong to Phase 6, but transaction integrity and the core treasury acceptance gaps must not be deferred merely to close Phase 3.
docs/PROJECT_LOG.md
+26
-2
@@ -1,5 +1,29 @@
1
# Project log
2
3
+## 2026-09-28 — Connection recovery and live server audit
4
+
5
+User authorized ongoing commits/pushes and relevant tool use without repeated
6
+permission questions. GitHub identity and PR #6 were verified. Both GitHub and
7
+Supabase plugins are already installed; no extra connector was needed for reads.
8
+
9
+Correction: the earlier access blocker was inferred from an incomplete project
10
+list. Direct lookup of `hcsixhqbyuhpshfwqpjx` and metadata SQL succeeded. Its
11
+organization differs from the organization returned by list discovery; the reason
12
+for the inconsistent results is unknown. This does not prove an OAuth change.
13
+
14
+Observed SQL role: `supabase_read_only_user`; transaction read-only; no CREATE on
15
+public. No write/DDL, role escalation, production mutation or credential extraction
16
+was attempted. Phase 3 collection migration and owner/license RLS are verified.
17
+No server accounting validation trigger, ledger uniqueness index or public
18
+transactional accounting RPC was found. An executable metadata-only audit query
19
+and evidence report are included; no customer rows or identities are published.
20
+
21
+Next: use a writable development environment for transactional server work,
22
+then verify concurrency, rollback and authenticated E2E before production rollout.
23
+Dependency graph configuration remains a separate repository administration issue.
24
+See docs/PHASE_3_CONNECTION_AUDIT.md; the old unavailable statement below records
25
+the earlier conclusion and is superseded by this entry.
26
+
27
## 2026-09-28 — Phase 3 recovery
28
29
Owner: coordinating implementer. Independent integration QA and server/persistence
@@ -23,7 +47,7 @@ current roadmap/status/handoff documentation.
47
Scope exclusion: no rewrite of the ERP, no new Phase 4-6 implementation, no
48
production migration, no change to auth/RLS or public release acceptance.
49
26
-Blocker: configured Supabase project not present in current official connection.
27
-Next: reconnect exact project, verify database rules and implement/test server
50
+Historical blocker (corrected above): configured project absent from list discovery.
51
+Historical next step: reconnect exact project, verify database rules and implement/test server
52
transaction boundary before phase acceptance. Continue complete cheque accounting
53
and authenticated E2E after that boundary is established.
docs/handoff/LATEST_HANDOFF.md
+25
-6
@@ -11,6 +11,9 @@ Status: client recovery patch tested; Phase 3 remains IN PROGRESS / NOT ACCEPTED
11
Read PROJECT_STATUS.md, docs/SIX_PHASE_ROADMAP.md and
12
docs/PHASE_3_REDESIGN_VERIFICATION.md. Do not repeat old four-phase numbering.
13
Resolve the actual remote branch/commit and PR before making status claims.
14
+The user explicitly authorizes ordinary implementation, commits and pushes without
15
+repeated confirmation. Actual permission boundaries, paid resources and unsafe
16
+production mutations still require their appropriate protected workflow.
17
18
## Work performed
19
@@ -54,18 +57,34 @@ Independent review found reversal-chain and date-validation issues; both were
57
reproduced and repaired. The reviewer could not deliver a final whole-diff verdict
58
because its execution hit a usage limit; do not claim independent final approval.
59
57
-## Real blocker / next action
60
+## Connection correction / next action
61
59
-Restore official access to the exact configured Supabase project
60
-`hcsixhqbyuhpshfwqpjx`. The available connection listed other project IDs only;
61
-no alternate project was queried or substituted. No credentials should be pasted
62
-into chat. No production database write or permission change was attempted.
62
+On 2026-09-28 at 16:48 UTC, direct access to the configured Supabase project
63
+`hcsixhqbyuhpshfwqpjx` succeeded. Do not repeat the earlier unavailable claim:
64
+`list_projects` and `list_organizations` omitted the target, but `get_project`,
65
+table/migration inspection and metadata SQL succeeded. The discrepancy's cause
66
+is not established. No alternate database, credential or connection was substituted.
67
64
-Then inspect target policies/triggers/functions and implement/test a transactional
68
+The SQL session returned `supabase_read_only_user`, `transaction_read_only=on`,
69
+and no CREATE privilege on public. No write access is claimed or bypassed.
70
+See [the live metadata audit](../PHASE_3_CONNECTION_AUDIT.md) and the reusable
71
+`scripts/sql/phase3-server-audit.sql`. The migration allowing Phase 3 collection
72
+names was verified, but no accounting-specific trigger/constraint or public
73
+posting/reversal RPC was found. Only owner/license RLS protects records.
74
+
75
+Implement and test, in a verified writable development environment, a transactional
76
posting/reversal API with owner/company checks, fiscal locks, immutable history,
77
source uniqueness, revision/idempotency and numbering concurrency. Existing
78
generic 200-record upserts are NOT a database transaction; jeAtomic only protects
79
in-memory state. Authenticated device E2E and complete cheque lifecycle remain open.
80
+Do not weaken a read-only role, use another project's database, or write production
81
+financial records to test access. No credentials should be pasted into chat.
82
+
83
+PR #6 contains the recovery patch. Quality checks and CodeQL passed on `8209c6f`;
84
+Dependency review failed because Dependency graph is not enabled/supported for
85
+the repository's current configuration. Repository administration is not exposed
86
+by the connected GitHub tools; this setting was not changed and the check was not
87
+disabled. See the audit for exact run and settings links.
88
89
Controlled ledger restore and historical cutover require staging, reconciliation,
90
backup and rollback. Never rewrite historical records as a convenience migration.
scripts/sql/phase3-server-audit.sql
new
+58
@@ -0,0 +1,58 @@
1
+-- Read-only, metadata-only diagnostic. Run against the exact configured project:
2
+-- hcsixhqbyuhpshfwqpjx. Do not infer access denial from list_projects alone.
3
+-- No customer rows, auth tokens, keys or server-side files are selected.
4
+select jsonb_build_object(
5
+ 'checked_at', now(),
6
+ 'query_role', current_user,
7
+ 'transaction_read_only', current_setting('transaction_read_only'),
8
+ 'can_create_public', has_schema_privilege(current_user, 'public', 'CREATE'),
9
+ 'records_rls', (
10
+ select c.relrowsecurity from pg_class c
11
+ join pg_namespace n on n.oid = c.relnamespace
12
+ where n.nspname = 'public' and c.relname = 'records'
13
+ ),
14
+ 'records_role_privileges', (
15
+ select jsonb_agg(jsonb_build_object(
16
+ 'role', role_name,
17
+ 'select', has_table_privilege(role_name, 'public.records', 'SELECT'),
18
+ 'insert', has_table_privilege(role_name, 'public.records', 'INSERT'),
19
+ 'update', has_table_privilege(role_name, 'public.records', 'UPDATE'),
20
+ 'delete', has_table_privilege(role_name, 'public.records', 'DELETE')
21
+ ) order by role_name)
22
+ from (values ('anon'), ('authenticated')) roles(role_name)
23
+ ),
24
+ 'records_policies', (
25
+ select coalesce(jsonb_agg(jsonb_build_object(
26
+ 'name', policyname, 'roles', roles, 'command', cmd,
27
+ 'using', qual, 'check', with_check
28
+ ) order by policyname), '[]'::jsonb)
29
+ from pg_policies where schemaname = 'public' and tablename = 'records'
30
+ ),
31
+ 'records_constraints', (
32
+ select coalesce(jsonb_agg(jsonb_build_object(
33
+ 'name', conname, 'definition', pg_get_constraintdef(oid)
34
+ ) order by conname), '[]'::jsonb)
35
+ from pg_constraint where conrelid = 'public.records'::regclass
36
+ ),
37
+ 'records_indexes', (
38
+ select coalesce(jsonb_agg(jsonb_build_object(
39
+ 'name', indexname, 'definition', indexdef
40
+ ) order by indexname), '[]'::jsonb)
41
+ from pg_indexes where schemaname = 'public' and tablename = 'records'
42
+ ),
43
+ 'records_triggers', (
44
+ select coalesce(jsonb_agg(jsonb_build_object(
45
+ 'name', tgname, 'definition', pg_get_triggerdef(oid)
46
+ ) order by tgname), '[]'::jsonb)
47
+ from pg_trigger where tgrelid = 'public.records'::regclass and not tgisinternal
48
+ ),
49
+ 'public_functions', (
50
+ select coalesce(jsonb_agg(jsonb_build_object(
51
+ 'name', p.proname,
52
+ 'arguments', pg_get_function_identity_arguments(p.oid),
53
+ 'security_definer', p.prosecdef
54
+ ) order by p.proname, p.oid), '[]'::jsonb)
55
+ from pg_proc p join pg_namespace n on n.oid = p.pronamespace
56
+ where n.nspname = 'public' and p.prokind = 'f'
57
+ )
58
+) as phase3_server_audit;