سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 08:00 UTC
test(phase1a): fail CI on any SECURITY DEFINER unsafe search_path or PUBLIC/anon execute
davoodmehraban89 committed
Oct 16, 2026 at 16:41 UTC
36ec4c9f1e5b08baad95aec651f1f318d5dad479
1 file changed
+26
supabase/tests/phase1a_stage1_all_definer_security.sql
new
+26
@@ -0,0 +1,26 @@
1
+-- Read-only SECURITY DEFINER audit in disposable Supabase CLI.
2
+-- Fail for ANY public/private SECURITY DEFINER routine with an unsafe path
3
+-- OR executable by PUBLIC/anon. This scans historic functions too.
4
+\set ON_ERROR_STOP on
5
+DO $check$
6
+DECLARE x record;n integer:=0;
7
+BEGIN
8
+ FOR x IN
9
+ SELECT n.nspname||'.'||p.proname||'('||pg_get_function_identity_arguments(p.oid)||')' AS routine,
10
+ NOT EXISTS(SELECT 1 FROM unnest(coalesce(p.proconfig,ARRAY[]::text[])) cfg
11
+ WHERE cfg IN ('search_path=','search_path=""')) AS bad_path,
12
+ has_function_privilege('anon',p.oid,'EXECUTE') AS anon_exec,
13
+ EXISTS(SELECT 1 FROM aclexplode(coalesce(p.proacl,acldefault('f',p.proowner))) a
14
+ WHERE a.grantee=0 AND a.privilege_type='EXECUTE') AS public_exec
15
+ FROM pg_proc p JOIN pg_namespace n ON n.oid=p.pronamespace
16
+ WHERE n.nspname IN ('public','private') AND p.prosecdef
17
+ LOOP
18
+ IF x.bad_path OR x.anon_exec OR x.public_exec THEN
19
+ RAISE WARNING 'FINORA_SECURITY_DEFECT routine=% bad_path=% anon_exec=% public_exec=%',
20
+ x.routine,x.bad_path,x.anon_exec,x.public_exec;
21
+ n:=n+1;
22
+ END IF;
23
+ END LOOP;
24
+ IF n>0 THEN RAISE EXCEPTION 'FINORA_SECURITY_DEFINER_AUDIT_FAILED violations=%',n;END IF;
25
+ RAISE NOTICE 'FINORA_SECURITY_DEFINER_AUDIT_PASS zero unsafe defs and anon/public grants';
26
+END $check$;