The core rule: client identifiers identify a project, server secrets bypass rules
Any key delivered to a browser — whether inside HTML, __NEXT_DATA__, a Vite bundle, or an HTTP request header from client JavaScript — must be treated as public knowledge. Both Supabase and Firebase explicitly design one tier of key to be public, while relying on server-enforced database policies to control what a browser caller may read or modify.
| Key or credential | Safe in browser JS? | What it actually allows |
|---|---|---|
Supabase anon / publishable key (role: "anon") | Yes, only when Row Level Security (RLS) is enabled and tested on every exposed table | Identifies your Supabase project and authenticates requests as the restricted anon or signed-in authenticated Postgres role |
Supabase service_role / secret key (role: "service_role") | Never | Bypasses every Row Level Security policy with full administrative read, write, and delete privileges across the entire database |
Direct PostgreSQL URL (postgres://postgres:...@db...supabase.co) | Never | Direct database superuser or role login bypassing API gateways and RLS completely |
Firebase Web apiKey (AIza...) in firebaseConfig | Yes, only when Firestore / Realtime Database / Storage Security Rules enforce access and API key restrictions are configured | Identifies your Firebase project to Google APIs; per Firebase API key documentation, it is not a secret by itself |
Firebase Admin SDK service account JSON (private_key PEM) | Never | Full administrative access to Firebase Auth, Firestore, Storage, and Google Cloud APIs, bypassing all client Security Rules |
Check it now. The frontend secret leak checker scans public HTML, __NEXT_DATA__ and up to four first-party JavaScript bundles across 12 live credential families without storing any secret; the security headers checker reads a page’s HSTS, CSP, X-Content-Type-Options, frame protection, Referrer-Policy and Permissions-Policy. No account, and the address is not stored.
How to verify your Supabase key is really anon and not service_role
Both legacy Supabase keys (anon and service_role) look almost identical at a glance because both are signed JSON Web Tokens starting with eyJ.... That visual similarity is why developers and AI editors accidentally paste the service_role token into NEXT_PUBLIC_SUPABASE_ANON_KEY or VITE_SUPABASE_KEY.
You can check what role a JWT carries in seconds without sending it anywhere: decode the middle Base64URL segment of the token and inspect the "role" claim.
"role": "anon"means it is the publishable client token documented in Supabase API Keys."role": "service_role"(or"supabase_admin") in any client file, HTML response, or public repository is an immediate production compromise. Rotate the JWT secret or revoke the secret key inside the Supabase dashboard first, move privileged calls into a server route or Edge Function, and inspect database logs for unauthorized reads or writes.
Modern Supabase projects also support opaque sb_publishable_... and sb_secret_... keys so humans and scanners can distinguish safe browser keys from server-only secrets by prefix alone. If you are starting a new project or rotating legacy keys, prefer the distinct prefix format so a secret key can never be mistaken for a client token.
Why a safe anon key still leaks data when RLS is off
Having a legitimate anon key in your frontend does not protect your database if Row Level Security is turned off or misconfigured. By default, a newly created Postgres table in the public schema has RLS disabled unless you explicitly enable it. When RLS is off, anyone holding your public project URL and anon key can query GET /rest/v1/<table_name>?select=* and dump every row in seconds.
Follow these four concrete steps from the Supabase Row Level Security guide before going live:
- Audit every table in the
publicschema: verifyrowsecurity = trueon every user, billing, order, message, and settings table. Even tables intended only for backend access should either live in a non-exposed private schema or have RLS enabled with zeroanon/authenticatedpolicies. - Test as an anonymous caller from outside: run a real
curlrequest against your Supabase REST endpoint using only theapikey: <anon_key>header and confirm it returns an empty set or authorization error for every private table. - Check
UPDATEandDELETEpolicies separately fromSELECT: an overly broadUSING (true)orWITH CHECK (true)clause written while prototyping lets any logged-in user overwrite or delete another tenant’s rows — the exact Broken Access Control pattern tracked in OWASP Top 10 A01. - Audit RPC functions and Storage buckets: check
SECURITY DEFINERPostgres functions and storage bucket policies so anonymous users cannot list private folders or trigger admin routines.
How to harden Firebase web apps beyond the public apiKey
Firebase web applications embed apiKey, authDomain, and projectId inside client JavaScript by design. The real security boundary sits in three places:
- Firestore, Realtime Database, and Storage Security Rules: never ship test-mode rules such as
allow read, write: if true;orallow read, write: if request.auth != null;on multi-tenant collections. Always scope access torequest.auth.uid == resource.data.ownerIdor verified custom tenant claims. - Restrict the Google Cloud API key: in Google Cloud Console, restrict your browser
apiKeyto your production HTTP referrers and only the specific Firebase APIs your web client actually calls (such as Identity Toolkit and Token Service), so the key cannot be abused against unrelated paid Google Cloud APIs. - Keep Firebase Admin credentials strictly server-side: never commit
serviceAccountKey.jsonto Git, never drop-----BEGIN PRIVATE KEY-----PEM blocks into frontend environment variables, and verify that server-only Next.js or Express modules are never imported into client components.
What to do right now if a service_role key or Admin PEM leaked
Treat any privileged credential that appeared on a public URL, in a JS bundle, or in a public Git commit as already harvested by automated bots. Removing it from the code alone is not enough.
- Rotate the compromised secret immediately in the Supabase dashboard, Google Cloud IAM, or database provider before shipping the code fix.
- Move privileged work behind a server endpoint (Next.js Route Handler, Supabase Edge Function, Express/FastAPI backend) that validates the caller’s session and checks tenant ownership before invoking admin privileges.
- Audit recent activity: review auth logs, newly created admin accounts, billing webhooks, storage uploads, and unexpected database reads or exports from the exposure window.
- Re-scan the live production build to confirm neither the HTML hydration state nor any built JavaScript bundle still carries a privileged secret or public source map.
How Beamfar helps
Beamfar distinguishes safe publishable keys from real production leaks automatically: our passive secret scanner decodes exposed JWTs in memory to flag privileged Supabase service_role tokens, PEM private keys, database connection strings with passwords, and live Stripe, AWS, OpenAI, Anthropic, GitHub, and Resend credentials — while ignoring safe anon and pk_live_ publishable keys so teams get zero false alarms on normal frontend configs. Raw secret values are redacted immediately and never stored. Test your live site now with our free frontend secret leak checker, or enable daily external security monitoring from the Solo plan alongside two-region uptime and CISA KEV Exploit Watch.
Questions
Is it safe to commit NEXT_PUBLIC_SUPABASE_ANON_KEY or put it in frontend JavaScript?
Yes, provided it truly carries "role": "anon" (never "service_role") and Row Level Security is enabled and tested on every exposed Postgres table and storage bucket. The anon key is designed to be public, while RLS enforces who can access each row.
Why do security scanners flag my Firebase apiKey (AIza...)?
Generic regex scanners often treat every AIza... string as a secret Google Cloud key. Per Firebase documentation, the web apiKey identifies your project and is expected in client code — your real protection is strict Firestore and Storage Security Rules plus HTTP referrer and API restrictions in Google Cloud Console.
How can I check whether my deployed site accidentally bundled a service_role key or private PEM?
Enter your public URL in the free frontend secret leak checker. It inspects the live HTML, __NEXT_DATA__, and first-party JavaScript bundles, decodes JWT role claims in memory without storing any values, and tells you immediately if a privileged key is exposed.
Sources
Read on . Standards and vendor pages change; confirm the current text before you rely on it.
- Supabase API Keys and Row Level Security (supabase.com)
- Supabase Row Level Security guide (supabase.com)
- Firebase Learn about using and managing API keys (firebase.google.com)
- OWASP Top 10 Broken Access Control (owasp.org)