Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit a65f53c

Browse files
Fix analytics RLS policies
Revoke public access to analytics views and enable RLS.
1 parent 18d4baf commit a65f53c

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

supabase/functions/subscribe-newsletter/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ const handler = async (req: Request): Promise<Response> => {
254254
console.error("Error in subscribe-newsletter function:", error);
255255
return new Response(
256256
JSON.stringify({
257-
error: "Failed to subscribe to newsletter",
258-
details: error.message
257+
error: "Failed to subscribe to newsletter"
259258
}),
260259
{
261260
status: 500,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- Security hardening migration: enforce RLS and restrict analytics views
2+
3+
-- 1) Ensure RLS is enabled on sensitive tables (idempotent)
4+
ALTER TABLE public.newsletter_subscribers ENABLE ROW LEVEL SECURITY;
5+
ALTER TABLE public.contact_submissions ENABLE ROW LEVEL SECURITY;
6+
ALTER TABLE public.security_events ENABLE ROW LEVEL SECURITY;
7+
ALTER TABLE public.analytics_daily ENABLE ROW LEVEL SECURITY;
8+
ALTER TABLE public.analytics_page_visits ENABLE ROW LEVEL SECURITY;
9+
10+
-- 2) Remove any legacy permissive public read policies on analytics base tables
11+
DROP POLICY IF EXISTS "Allow public read access for analytics_daily" ON public.analytics_daily;
12+
DROP POLICY IF EXISTS "Allow public read access for analytics_page_visits" ON public.analytics_page_visits;
13+
14+
-- 3) Restrict direct access to analytics views
15+
REVOKE SELECT ON TABLE public.analytics_public FROM anon, authenticated;
16+
REVOKE SELECT ON TABLE public.analytics_summary FROM anon, authenticated;
17+
REVOKE SELECT ON TABLE public.analytics_public FROM PUBLIC;
18+
REVOKE SELECT ON TABLE public.analytics_summary FROM PUBLIC;
19+
20+
-- 4) Ensure execute access on controlled SECURITY DEFINER functions for aggregated analytics
21+
GRANT EXECUTE ON FUNCTION public.get_analytics_daily(date, date) TO public;
22+
GRANT EXECUTE ON FUNCTION public.get_analytics_page_visits(date, date) TO public;

0 commit comments

Comments
 (0)