// docs / baas security / supabase service role exposure
Chiave di service-role Supabase esposta in JavaScript: cosa significa e come trovarla
If a Supabase service-role or secret key appears in browser JavaScript, treat it as an exposed server credential. Remove the leak, replace the affected credential, and review possible misuse. This guide separates public keys from server-only keys, explains common exposure paths, and gives a containment and verification checklist. Never paste a real key into a website, chat, or support ticket.
Cos'è la chiave di service-role
Supabase has public keys for client applications and elevated keys for trusted backend components. Legacy anon and service_role keys are JWTs; newer sb_publishable_ and sb_secret_ keys are not. A public key does not grant administrative access by itself. A service-role or secret key can bypass Row-Level Security, so it must remain server-only.
Use the key type shown in your own Supabase Dashboard to identify what was exposed. Do not paste a credential into an online decoder or use it to explore a database. Decoding a JWT payload alone does not validate its signature, current permissions, or revocation state.
The important distinction is the credential's intended context: public client configuration versus privileged backend access. You do not need to share the key value to make that distinction.
A leaked sb_secret_ key still needs containment even if a browser request is rejected. Browser-specific restrictions do not make a published server credential safe; it may be usable from other clients. Check the current Supabase key guidance for the affected key type.
Common ways server credentials reach public code
Review these exposure paths in both human-written and AI-generated code. They are examples to check, not evidence that a particular tool caused the incident or a measured ranking of leak frequency.
Pattern 1: singolo file .env con prefisso NEXT_PUBLIC_
A server secret can be exposed when it is assigned to a browser-exported environment variable. In Next.js, references to NEXT_PUBLIC_ variables can be inlined into client JavaScript at build time. Review the variables used by browser code and the actual output of your production build; changing a dashboard value does not remove an old published bundle.
Pattern 2: chiave sbagliata nella chiamata createClient
Passing a literal server credential, or returning it from a server endpoint to a browser, exposes it regardless of its variable name. In Next.js, simply referencing an unprefixed process.env.SUPABASE_SERVICE_ROLE_KEY in client code does not normally inline its value. Check explicit build configuration and server responses instead of assuming every such reference is a leak.
Pattern 3: chiave service-role hardcoded negli script di seed
A privileged credential hardcoded in a seed script, example, repository, or downloadable asset becomes public if that file is published. Keep administrative scripts outside public asset directories and load their credentials only in a controlled backend environment. Review generated files before committing or deploying them.
What a FixVibe bundle scan can tell you
FixVibe can flag suspected server credentials in JavaScript reached during a URL scan and identify the affected file. Coverage depends on what the scan reaches; do not assume that every lazy-loaded chunk, worker, external script, or authenticated page has been examined.
The scan does not use a discovered credential to authenticate to your database. A finding is evidence of potential credential exposure, not proof of successful misuse or current key validity. No finding is not a substitute for reviewing your build output and key inventory.
Exposed key: containment and verification checklist
Respond promptly, but do not assume that exposure proves data theft or that a clean scan proves no one used the key. Keep a private incident record with the affected deployment, file, and earliest known exposure time. Do not copy the credential into that record.
- Stop publishing the credential. Remove it from browser code, public configuration, and responses; contain the affected surface while preparing a corrected deployment. Do not copy a replacement key into the same leaking path.
- Replace and retire the affected key. Follow Supabase's current procedure for the key type: update legitimate backend dependencies to a replacement, verify them, and revoke or deactivate the compromised credential promptly. Creating a new key alone does not invalidate the old one. Legacy keys can have shared dependencies; do not assume a universal reset button or guaranteed invalidation time.
- Review possible misuse. Examine available database, API, authentication, and storage audit evidence from the earliest known exposure. Log retention and detail vary, and missing records do not prove that no data was accessed. Escalate sensitive-data incidents to the appropriate security and legal advisers.
- Remove remaining published copies. Review source control, build artifacts, old deployments, and caches. Coordinate any repository-history cleanup with collaborators; it does not revoke a key or remove copies held by others. Preserve appropriate incident evidence without retaining the secret.
- Verify the corrected deployment. Check the served browser assets and responses for the exposed credential, confirm in your provider account that it has been retired, and smoke-test legitimate backend operations with the replacement. Re-scan the deployed URL, then separately review RLS and access policies.
Prevenire il leak fin dall'inizio
Treat secret handling as a code-review and deployment boundary, not a naming convention alone:
- Keep elevated keys out of client configuration. Do not use browser-export prefixes such as
NEXT_PUBLIC_orVITE_for server credentials. Also review explicit bundler configuration and any API response that could expose them. - Use controlled secret storage. Keep credentials out of source control. Server-only environment variables or a secret manager can supply them at runtime; restrict access to local environment files and never publish or commit those files.
- Separate user sessions from administrative clients. Use a public key and the user's session for normal client access. Create privileged clients only for authorized backend work. In Next.js,
import 'server-only'helps prevent accidental imports into Client Components; it does not replace authorization checks. - Review changes before they leave your machine. Use a maintained secret-scanning tool and inspect generated configuration, fixtures, and sample files. A simple JWT-pattern search can flag legitimate public keys and miss other credential formats; it is not a complete security gate.
- Check what actually ships. Inspect the production browser build and served responses, including separately loaded assets where applicable. A search for the text
service_rolealone cannot prove the presence or absence of a credential. Keep credentials out of test output and logs.
Domande frequenti
How urgently should I respond to an exposed service-role key?
Treat exposure as a prompt incident-response task. There is no reliable universal safe window before misuse. Contain the leak, replace and retire the affected credential, and review available evidence without assuming either compromise or safety.
Ruotare la chiave basta, o devo assumere l'esfiltrazione di dati?
Retiring the old key prevents future use of that credential but cannot undo earlier access. Review the incident and affected data with the appropriate advisers; notification obligations depend on the facts and applicable rules, not a universal deadline in a scanner guide.
RLS può proteggermi se la chiave di service-role trapela?
RLS does not constrain access performed with an elevated service-role or secret key. Keep those credentials server-only, retire an exposed key, and retain RLS and appropriate grants for ordinary public and authenticated access.
Si applica al nuovo modello chiave pubblicabile / segreta Supabase (sb_publishable_ / sb_secret_)?
The public and server-only distinction applies to both key systems. A publishable key is intended for public clients; a secret key belongs in a trusted backend. A leaked secret key still needs retirement even if browser-specific protections reject a request.
E la chiave anon / pubblicabile — è sicura nel bundle?
Public anon and publishable keys are designed for client applications, but do not make the data public by default. Review grants, RLS policies, and authentication for the resources you expose. See the Supabase RLS scanner guide for the limits of an external check.
Prossimi passi
After containing the incident, run a FixVibe URL scan against the corrected deployment. Use the report alongside your own build and key-inventory checks, not as proof that all copies are gone. Review the Supabase RLS scanner and Supabase storage bucket security checklist for the separate access-control work.
Primary references
Read Supabase API keys and safe handling, Next.js environment variables, and Next.js server/client boundaries. Provider steps can change; use the current instructions for your project and credential type.
