My Supabase service_role key is exposed. What now?
Short answer: revoke or rotate the exposed privileged key, move its operation to trusted server code, and verify no old bundle remains live. This guide explains what to verify and what the public scan cannot prove, without logging in, changing records, or treating an inconclusive response as a pass.
What the exposed Supabase service_role key check covers
A legacy service_role key bypasses Row Level Security. If it reaches browser code, a visitor can use the same credential outside your interface, so treat it as compromised even if no misuse is visible.
The finding describes a public condition, not proof that someone has abused it. First preserve the relevant deployment details, then rotate exposed credentials or close the access path before investigating billing, logs, or affected records.
Do not confuse the legacy service_role JWT or newer sb_secret key with a publishable anon key. The privileged credential belongs only in a trusted server environment with narrowly scoped access.
Understand the evidence before changing code
Record which project, deployment, and integration used the key, then rotate it through Supabase's current key-management flow. Rotation can affect server jobs, so plan the replacement and update dependent services.
Severity reflects potential impact and reach, not certainty of exploitation. A public key can be intentionally visible; the important distinction is what the provider allows that key to do and which server-side policy still applies.
Apply the narrow, safe change
Move privileged work into a server route or Edge Function. Authenticate and authorize each request there, validate inputs, and keep the new secret out of client components, logs, and returned JSON.
export async function POST(request: Request) {
const key = process.env.SUPABASE_SECRET_KEY;
if (!key) return new Response("Not configured", { status: 503 });
// Authenticate and authorize the caller before privileged work.
}Prefer the smallest repair that restores the intended boundary. Keep public client configuration public, move privileged operations behind an authenticated server route, and make data rules depend on the authenticated owner or an explicit role.
Verify the production result
After redeploying, inspect the production JavaScript and source maps for the old credential pattern. Test the server operation as an authorized user and confirm an anonymous request cannot invoke it.
Use the snippet as a starting point, not a blind migration. Confirm the real table, environment, route, identity claim, and deployment platform first; a copied policy with the wrong owner field can block legitimate users or expose the wrong records.
Keep the issue from returning
Use separate keys or supported key scopes per environment, limit who can read them, and add a build-time secret scan. A clean source diff is not enough if the old deployment is still serving.
Verify the repair from the same public vantage point that exposed it. Check the deployed response, confirm the finding is gone, and test the intended signed-in user and an unrelated user through the normal application flow.
Limits and next steps
A public scan cannot show whether the key was used or which records may have been accessed. Review Supabase logs and rotate immediately; investigate the provider's audit history separately.
Prevent recurrence with a reviewed migration, a secret scanner, and a small regression test that runs before deploy. Store only the minimum required credential, scope it to one project, and define who can rotate it.
A public scanner cannot establish whether private records were accessed or whether an account was compromised. If a real secret shipped, revoke it with the provider and review the provider's usage and audit history.
Key facts
- Legacy service_role credentials bypass RLS.
- Newer Supabase secret keys are also server-only.
- Removing a key from source does not revoke copies already deployed or downloaded.
Questions
Can a clean exposed Supabase service_role key check prove the app is secure?
What should I do first if the finding is real?
Does ProofForge change application data?
What should I do after the repair?
Official documentation referenced
Related
Last updated 2026-11-25 · Reviewed by ProofForge · Methodology · Markdown