RealComposer

Supabase Safe & Unsafe Practices

Direct Answer

The Supabase anon (publishable) key is safe in clients only when Row Level Security is enabled on every exposed table. The service_role (secret) key bypasses RLS entirely and must stay on a server or edge proxy, never in a mobile app, FlutterFlow project, or browser bundle.

Credentials & Where They Belong

Client safe
anon / publishable key

Safe only when RLS policies restrict what each user can read and write.

Server only
service_role / secret key

Bypasses all RLS policies with full database access.

Server only
JWT secret

Signs user tokens. Leaking it lets attackers mint any identity.

Safe Practices

  • Enable RLS on every table in exposed schemas

    Write policies using auth.uid() so each user can only touch their own rows, and test them with the anon key.

  • Keep service_role calls behind a server boundary

    Admin reads, cross-user joins, and webhook writes belong in an edge function or proxy holding the secret key.

  • Authorize from app_metadata, not user_metadata

    Users can edit their own user_metadata. Store roles in app_metadata or a protected table.

Unsafe Practices

  • Shipping the service_role key in an app

    Anyone who extracts it gets unrestricted read and write access to your whole database.

  • Leaving RLS disabled on public tables

    With RLS off, the anon key can read and modify every row through the REST API.

  • Writing policies that check client-supplied IDs

    Policies like user_id = request parameter are spoofable. Compare against auth.uid().

The RealComposer Pattern

Keep SUPABASE_SERVICE_ROLE_KEY in the vault and expose narrow, read-only pipelines (profiles, plan status) that return slimmed JSON. Clients keep using the anon key with RLS for user-scoped data, and never see the secret key.

START BUILDING FREE

Frequently Asked Questions

Q:Is it safe to expose the Supabase anon key?

Yes, if every exposed table has RLS enabled with correct policies. Without RLS, the anon key grants open access to those tables.

Q:Where should I use the Supabase service role key?

Only in trusted server or edge code, such as admin jobs, webhooks, and aggregation pipelines that must read across users.

Combine firebase auth user with supabase profile endpoint

Firebase ID token lookup and Supabase profile row merged at edge. For "combine firebase auth user with supabase profile endpoint", store FIREBASE_ACCESS_TOKEN, SUPABASE_SERVICE_ROLE_KEY in Secret Vault, call https://firestore.googleapis.com/v1/projects/{{query.projectId}}/databases/(default)/documents/{{query.collection}}/{{query.docId}} from a Worker, and let React / Flutter / Mobile hit only https://realcomposer.com/v1/workspace/combine-firebase-auth-with-supabase-profile with an rc_live_ client token.

Sub-10ms edgeView Recipe
Security & Secret Vault

Protect Supabase Service Role Key in Expo

The Supabase service_role key bypasses row level security, so it must never appear in an Expo app or OTA update. Keep the anon key in the app for normal queries and send privileged reads to a RealComposer pipeline that holds service_role in the vault and returns filtered fields.

Sub-10ms edgeView Recipe

Related Concepts