You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Security] telemetry-ingest uses service role key — bypasses RLS unnecessarily #675
supabase/functions/telemetry-ingest/index.ts:46-49 — The edge function creates a Supabase client with SUPABASE_SERVICE_ROLE_KEY, which bypasses Row Level Security entirely. This is unnecessary — RLS policies already allow anon INSERT and SELECT on telemetry_events, plus INSERT/SELECT/UPDATE on installations (for upsert).
Using the service role key means any caller (even without proper credentials) gets unrestricted database access through this endpoint, enabling telemetry data poisoning.
Impact
Medium — permits unauthenticated telemetry poisoning and write amplification. The service role key bypass is unnecessary given existing RLS policies.
Fix
PR #664 replaces the service role key with the caller-provided apikey header (anon key). Returns 401 if the header is missing. RLS enforces access control. The client (bin/gstack-telemetry-sync) already sends the anon key — no client changes needed.
Found via sqry AST-based semantic code graph analysis.
Update: While investigating Gemini's follow-up about anon_select RLS policies, we discovered that migration 002_tighten_rls.sql already drops anon_select on all three tables — so that concern is pre-addressed.
However, 002 also drops anon_update_last_seen on installations. Our fix (switching from service role key to caller's anon key) means the installations upsert now needs an UPDATE policy to work. Without it, upserts silently fail after 002 is applied.
Added migration 003_installations_upsert_policy.sql to re-add a scoped UPDATE policy for installations, enabling the upsert to work with the anon key.
Migration 003 re-opens what 002 closed. Migration 002 explicitly dropped anon_update_last_seen because it was "unrestricted on all columns." Migration 003's anon_update_tracking uses the same USING (true) WITH CHECK (true) — same permissiveness. The comment in 003 acknowledges this ("this still allows updating all columns"). Worth noting as residual risk since anon callers can now UPDATE any column on installations, not just last_seen/gstack_version/os.
The apikey header is caller-controlled. The fix trusts req.headers.get("apikey") as-is. Supabase Edge Functions receive this from the client — any value passes the if (!callerKey) check, including a service role key if one leaks. Since the anon key is public by design in Supabase (it's in the client bundle), this is fine for the threat model here. But it's not authentication — it's just "use caller's privilege level instead of god mode." The real protection is RLS, which is correct.
Neither of these block the PR — the fix is a net improvement over the current state. Just flagging for completeness.
Both observations are valid — thanks for the careful review.
Column-level restriction (addressed): You're right that migration 003 re-opened the same broad UPDATE that 002 explicitly closed. PostgreSQL supports column-level GRANT UPDATE which is a better fit than RLS for this. Updated migration 003 to:
REVOKEUPDATEON installations FROM anon;
GRANTUPDATE (last_seen, gstack_version, os) ON installations TO anon;
Now anon callers can only UPDATE the three tracking columns the edge function actually writes. Any UPDATE touching first_seen or installation_id gets a permission error at the query level.
apikey header trust: Agreed — it's privilege-level selection, not authentication. The real protection is RLS + the column-level GRANT, which is correct for this threat model. The anon key is public by design in Supabase (shipped in client bundles), so trusting the caller's key here just means "use their privilege level instead of god mode."
Fixed in commit c151fabf (PR #664, v0.15.13.0). Telemetry-ingest now uses caller-provided anon key instead of service role key. Migration 003 adds scoped column-level GRANT.
Activity
wernerkasselman-au commentedon Mar 30, 2026
Update: While investigating Gemini's follow-up about
anon_selectRLS policies, we discovered that migration002_tighten_rls.sqlalready dropsanon_selecton all three tables — so that concern is pre-addressed.However, 002 also drops
anon_update_last_seenoninstallations. Our fix (switching from service role key to caller's anon key) means theinstallationsupsert now needs an UPDATE policy to work. Without it, upserts silently fail after 002 is applied.Added migration
003_installations_upsert_policy.sqlto re-add a scoped UPDATE policy forinstallations, enabling the upsert to work with the anon key.This is included in PR #664.
Found via sqry AST-based semantic code graph analysis.
garagon commentedon Mar 30, 2026
The finding is valid —
SUPABASE_SERVICE_ROLE_KEYbypasses RLS and isn't needed here since migration 001 already grants anon INSERT on both tables.Two observations on the fix in PR #664:
Migration 003 re-opens what 002 closed. Migration 002 explicitly dropped
anon_update_last_seenbecause it was "unrestricted on all columns." Migration 003'sanon_update_trackinguses the sameUSING (true) WITH CHECK (true)— same permissiveness. The comment in 003 acknowledges this ("this still allows updating all columns"). Worth noting as residual risk since anon callers can now UPDATE any column oninstallations, not justlast_seen/gstack_version/os.The
apikeyheader is caller-controlled. The fix trustsreq.headers.get("apikey")as-is. Supabase Edge Functions receive this from the client — any value passes theif (!callerKey)check, including a service role key if one leaks. Since the anon key is public by design in Supabase (it's in the client bundle), this is fine for the threat model here. But it's not authentication — it's just "use caller's privilege level instead of god mode." The real protection is RLS, which is correct.Neither of these block the PR — the fix is a net improvement over the current state. Just flagging for completeness.
wernerkasselman-au commentedon Mar 30, 2026
Both observations are valid — thanks for the careful review.
Column-level restriction (addressed): You're right that migration 003 re-opened the same broad UPDATE that 002 explicitly closed. PostgreSQL supports column-level
GRANT UPDATEwhich is a better fit than RLS for this. Updated migration 003 to:Now anon callers can only UPDATE the three tracking columns the edge function actually writes. Any UPDATE touching
first_seenorinstallation_idgets a permission error at the query level.apikey header trust: Agreed — it's privilege-level selection, not authentication. The real protection is RLS + the column-level GRANT, which is correct for this threat model. The anon key is public by design in Supabase (shipped in client bundles), so trusting the caller's key here just means "use their privilege level instead of god mode."
Fix pushed to PR #664.
fix(security): restrict anon UPDATE to tracking columns only
fix(security): restrict anon UPDATE to tracking columns only
fix: telemetry-ingest uses anon key not service role key
garrytan commentedon Apr 13, 2026
Fixed in commit
c151fabf(PR #664, v0.15.13.0). Telemetry-ingest now uses caller-provided anon key instead of service role key. Migration 003 adds scoped column-level GRANT.