سامانه صدور فاکتور و حسابداری
Document SECURITY DEFINER hardening evidence
davoodmehraban89 committed
Sep 30, 2026 at 07:48 UTC
5ff343aa024d24bd05c020a3e8545aa284099120
1 file changed
+35
docs/SECURITY_DEFINER_HARDENING_2026-09-30.md
new
+35
@@ -0,0 +1,35 @@
1
+# Finora — SECURITY DEFINER hardening evidence
2
+
3
+Date: 2026-09-30
4
+Production project: `hcsixhqbyuhpshfwqpjx`
5
+Migration: `20260930041735_harden_public_security_definer_rpc_grants_search_path`
6
+
7
+## Scope
8
+This change hardens the seven public `SECURITY DEFINER` helpers currently reported by the Supabase security advisor:
9
+
10
+- `admin_cancel_license(uuid)`
11
+- `admin_extend_license(uuid, integer)`
12
+- `admin_set_company_limit(uuid, integer)`
13
+- `admin_set_license(uuid, text, integer, text)`
14
+- `admin_set_license_modules(uuid, text[])`
15
+- `has_active_license()`
16
+- `is_admin()`
17
+
18
+## Applied controls
19
+- Every function now has an empty `search_path`.
20
+- `EXECUTE` is explicitly revoked from `PUBLIC` and `anon`.
21
+- `EXECUTE` is explicitly granted only to `authenticated` and `service_role` because these functions are intentionally part of the authenticated application RPC surface.
22
+- The five administrative mutators retain their internal `public.is_admin()` authorization check before mutation.
23
+- No license or financial data was changed by the hardening migration.
24
+
25
+## Verification
26
+Live production catalog verification after migration showed all seven functions with `search_path=""`, `anon_exec=false`, `authenticated=true`, and `service_role=true`.
27
+
28
+A transactional negative test impersonated an authenticated non-admin user and attempted all five administrative mutators. Every call raised SQLSTATE `42501` (`forbidden`); the transaction was rolled back. `public.is_admin()` returned `false` for the same test principal.
29
+
30
+## Advisor disposition
31
+The Supabase advisor still reports seven `authenticated_security_definer_function_executable` warnings. This is expected because the functions remain intentionally callable by signed-in application users and the advisor flags exposure, not a proven authorization bypass. The warning is therefore **reviewed but not silently closed**.
32
+
33
+For a future zero-warning architecture, move privileged license mutation behind a non-exposed/private execution boundary (for example a server/Edge Function that performs explicit authorization) and remove authenticated Data API execution of the public definer mutators. That is an architectural change and must be regression-tested before rollout.
34
+
35
+Leaked-password protection remains a separate open P1 item.