EthioDeploy
DocsPricingDomainsBlogToolsChangelog

Blog/Fix deploy errors

Leaked Supabase service_role key: what to do now

BS
Brook SolomonPublished November 24, 2026
Share on XShare on LinkedIn
service_role

THE SHORT ANSWER

A leaked service_role key gives anyone full access to your database, because it bypasses Row Level Security. Act in this order: create a new secret key (sb_secret_) and move your server code to it, switch browser code to a publishable key, deactivate the legacy anon and service_role keys under Settings > API Keys, then revoke the legacy JWT secret, since that secret is what makes the old key valid. Read your logs before they expire (one day on the Free plan), turn on RLS for every exposed table, and move the code that needed the key to a server so it never reaches the bundle again. Removing it from git history comes last and doesn't undo the leak.

How bad is a leaked service_role key?

As bad as it gets for a Supabase project. Supabase's docs: “A secret key bypasses every Row Level Security policy you have.” The legacy service_role key and the new sb_secret_ keys both use the service_role Postgres role, which has bypassrls. Anyone holding one can read, change and delete every row in every table the API exposes.

First work out which kind you leaked:

Looks likeWhat it isPublic?
sb_publishable_...Publishable keyYes, by design
sb_secret_...Secret keyNo
eyJ... with "role": "anon"Legacy anon key (a JWT)Yes, by design
eyJ... with "role": "service_role"Legacy service_role key (a JWT)No

The legacy keys are JWTs, so the role is inside the token. The leaked API key scanner decodes Supabase JWTs it finds on a live site and reads that role claim: service_role is reported as an exposed secret, anon as public by design. It flags sb_secret_ keys too.

Rotate before you touch the code. Deleting the key from your repo or your bundle does nothing about copies people already have.

Step 1: create a new secret key and swap it in

Supabase's rotation guide has the same three steps for both key types: create a new secret key, replace the leaked key everywhere, then retire the leaked one. Fix whatever leaked the key first, or the new one leaks the same way.

  1. In the dashboard, open Settings > API Keys and create a new secret key. If you were on the legacy keys, create a publishable key as well.
  2. Put the secret key in every server-side component that used the old key: your backend, Edge Functions, cron jobs. Put the publishable key in browser and mobile code in place of the legacy anon key.
  3. Check the two places that behave differently with the new keys. Database Webhooks and pg_net calls that sent service_role as Authorization: Bearer need the new key in the apikey header, because secret keys aren't JWTs. Edge Functions with the built-in verify_jwt check only understand the legacy keys.

Supabase recommends a separate secret key for each backend component: “If one component leaks its key, you only rotate that one.”

Step 2: delete the leaked key or turn off the legacy keys

Wait until everything uses the new key, unless someone is using the leaked one right now. Then the guide says to retire it immediately and accept that anything you missed breaks.

  • A leaked sb_secret_ key: delete it under Settings > API Keys. Deleting a secret key can't be undone.
  • A leaked legacy service_role key: you can't revoke it on its own. Deactivate the legacy keys (both anon and service_role) in the same section. Deactivation is reversible, but if a client breaks afterwards, move that client to a new key; turning the legacy keys back on restores the leaked one.

The same steps through the Management API, with a personal access token in an env var:

# turn off the legacy anon and service_role keys
curl -X PUT "https://api.supabase.com/v1/projects/$PROJECT_REF/api-keys/legacy?enabled=false" \
  -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN"

# delete one secret key by id (list them with GET .../api-keys)
curl -X DELETE "https://api.supabase.com/v1/projects/$PROJECT_REF/api-keys/$KEY_ID" \
  -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN"

If your sb_secret_ key was pushed to a public GitHub repo, check the project before you start: Supabase wrote in January 2026 that it automatically revokes secret keys detected in public GitHub repositories and notifies the project owner. A backend that suddenly gets 401s may be the first sign.

Step 3: revoke the legacy JWT secret

This step applies only to a leaked legacy key. The legacy anon and service_role keys “are not only API keys, but are also valid JSON Web Tokens, signed by the legacy JWT secret”. Anything that still trusts that secret, such as your own code verifying Supabase JWTs, can still accept the leaked token. Revoking the secret ends that.

  1. On the JWT Signing Keys page, click Migrate JWT secret. Supabase says this “does not cause downtime” and creates a standby asymmetric key.
  2. Rotate to the new key. With signing keys, “no users will be forcefully signed out”: existing access tokens stay valid until they expire. Turn off verify_jwt on Edge Functions first if they use it.
  3. Make sure the legacy anon and service_role keys are disabled (step 2); the docs require that before the next step.
  4. Revoke the legacy JWT secret. Normally you wait about 1 hour 15 minutes so access tokens signed with it expire, but the docs allow revoking right away during an active security incident.

Supabase is retiring the legacy anon and service_role keys by the end of 2026, so this migration is coming anyway.

Step 4: check the logs for what someone did with it

Do this the same day. Supabase keeps logs for a short time:

PlanLog retention
Free1 day
Pro7 days
Team28 days
Enterprise90 days

Open Logs and query the API Gateway source. The documented gateway fields don't record which key a request used, so look for traffic that isn't yours: unfamiliar IPs, writes and deletes you didn't make, tables your app never touches.

select
  timestamp,
  log_attributes['request.method'] as method,
  log_attributes['request.path'] as path,
  log_attributes['response.status_code'] as status,
  log_attributes['request.headers.cf_connecting_ip'] as ip
from logs
where source = 'edge_logs'
  and log_attributes['request.method'] in ('POST', 'PATCH', 'DELETE')
order by timestamp desc
limit 200;

Group by ip and path to see who did the most. Check the Auth logs for users you didn't create and Storage for files you didn't upload. If data was read or changed, restore from a backup and decide whether you need to tell your users.

Step 5: check Row Level Security

RLS didn't protect you from the leaked key; the secret role skips it. It is what protects you from the publishable key that is meant to be in your browser code. Supabase's rule is short: “Enable RLS on every table in an exposed schema.” A table without it “is readable and writable by any role with a grant on it”.

-- tables in public without RLS
select tablename
from pg_tables
where schemaname = 'public' and rowsecurity = false;

alter table public.orders enable row level security;

Once RLS is on, the publishable key sees nothing until you add policies. The Security Advisor (under Advisors in the dashboard, or supabase db advisors) reports 0013_rls_disabled_in_public and 0023_sensitive_columns_exposed as errors.

This is also where many leaks start: a query fails because of RLS, and the quick fix is to swap in the service_role key. Write the policy instead, or move that query to the server.

Step 6: get the key out of the bundle and git history

A key reaches the browser when it's in a variable your build tool inlines (NEXT_PUBLIC_, VITE_, EXPO_PUBLIC_) or pasted into a component. Move every call that needs the secret key into server code: a Route Handler or Server Action, an Edge Function, or your API. Keep the key in an environment variable without a public prefix, rebuild, redeploy and scan the live site again. Supabase notes that a secret key used from a browser gets a 401, but that doesn't stop anyone from using a copied key with curl.

// app/api/admin/users/route.ts (server only)
import { createClient } from "@supabase/supabase-js";

const admin = createClient(process.env.SUPABASE_URL!, process.env.SUPABASE_SECRET_KEY!);

export async function GET() {
  // check the caller is an admin before this line
  const { data, error } = await admin.auth.admin.listUsers();
  if (error) return Response.json({ error: error.message }, { status: 500 });
  return Response.json(data.users.map((u) => ({ id: u.id, email: u.email })));
}

Git history comes last, after the key is dead. GitHub's docs say the first step is to “revoke and/or rotate that secret”, and that rewriting history doesn't reach other people's clones or forks. If you still want it gone:

# expressions.txt holds the leaked key, one per line
git filter-repo --sensitive-data-removal --replace-text ../expressions.txt

Then force-push as GitHub's guide describes. GitHub Support can remove cached views and pull request references. For the related build-time problem, see NEXT_PUBLIC_ env variables and Vite env variables.

How do you keep it server-side on EthioDeploy?

Your backend and your front end can run on EthioDeploy, so the code that needs the secret key has a server to live on. Add the key under Environment Variables with a name that has no public prefix, such as SUPABASE_SECRET_KEY or SUPABASE_SERVICE_ROLE_KEY. The add form suggests “Runtime only” for names like these, and a runtime-only variable is kept out of the build, so it can't be inlined into a bundle. It never suggests that for a NEXT_PUBLIC_ or VITE_ name, because those exist to reach the browser.

After you redeploy, run the leaked API key scanner on the live URL. It reads the page's HTML and up to 25 JavaScript files from the same domain (15 MB in total), the same files a visitor downloads, and shows any key it finds masked; nothing is stored. It can't see pages behind a login or code that only loads after a click, so a clean result means no known key pattern was found, not that the app is secure.

Questions

Create a new secret key in Settings > API Keys, move your server code to it, then deactivate the legacy anon and service_role keys and revoke the legacy JWT secret. Change the code that leaked the key only after the old key stops working.

Not on its own. The legacy service_role key is a JWT signed by the project's legacy JWT secret. You replace it with a new secret key (sb_secret_), deactivate the legacy keys, and revoke the legacy JWT secret through the JWT signing keys migration.

Not if you migrate to JWT signing keys first. Supabase says rotating signing keys signs nobody out, because access tokens that haven't expired stay valid. Waiting about 1 hour 15 minutes before revoking the legacy secret lets one-hour tokens expire.

Yes, the anon key and the publishable key are meant for browser code. Your data is protected by Row Level Security, so every table in an exposed schema needs RLS enabled and policies for what logged-out and logged-in users may do.

No. Clones, forks and anyone who already copied the key keep it. Revoke or rotate the key first; rewriting history with git filter-repo is cleanup afterwards.

Sources

Checked on November 24, 2026:

  • Supabase: Understanding API keys
  • Supabase: Rotate a leaked or compromised API key
  • Supabase: Migrating to new API keys
  • Supabase: JWT signing keys
  • Supabase: Logs
  • Supabase: Advanced log filtering
  • Supabase: Log field reference
  • Supabase: Row Level Security
  • Supabase: Database advisors
  • Supabase blog: Security retro 2025
  • PostgreSQL: pg_tables
  • GitHub: Removing sensitive data from a repository

Push a repo. Get a URL.

  • Leaked API key scanner
  • Environment variables on EthioDeploy
  • Deploy a Lovable app
  • Deploy a Next.js app
Start free

Join the EthioDeploy Telegram

Release notes as they ship, plus deploy help from the team and other developers.

Join on Telegram
BS
WRITTEN BYBrook SolomonFounder, EthioDeploy

Brook Solomon founded EthioDeploy and builds its deploy pipeline, build servers and AI coding agent. The posts here come from errors seen in real deploys on the platform.

All posts by Brook →
On this page
  • How bad is a leaked service_role key?
  • Step 1: create a new secret key and swap it in
  • Step 2: delete the leaked key or turn off the legacy keys
  • Step 3: revoke the legacy JWT secret
  • Step 4: check the logs for what someone did with it
  • Step 5: check Row Level Security
  • Step 6: get the key out of the bundle and git history
  • How do you keep it server-side on EthioDeploy?
  • Questions
  • Sources
0% read

Keep reading

  • engines.node

    Fix deploy errorsNov 24, 2026

    "The engine node is incompatible": fix Node version mismatches on deploy

    The error means the Node version running your install is outside a range in engines.node, either your own package.json or a dependency's. Yarn 1 stops on it by default; npm only warns unless engine-strict is on; pnpm warns for your project and fails for dependencies when engine-strict is set. Fix it by choosing the Node version on the build machine; loosening the check only hides the problem. Set engines.node to a bounded range such as "24.x", and check how your host reads it. Heroku and Vercel read engines.node, Render reads NODE_VERSION, .node-version and .nvmrc before it, and nixpacks reads NIXPACKS_NODE_VERSION before everything else and only knows whole majors. Run node -v in your build command to see what you actually got.

  • ERR_TOO_MANY_REDIRECTS

    Fix deploy errorsNov 24, 2026

    ERR_TOO_MANY_REDIRECTS behind a proxy: causes and fixes

    ERR_TOO_MANY_REDIRECTS behind a proxy almost always means your app thinks an HTTPS request is HTTP and redirects it to HTTPS, forever. The proxy ended TLS and forwarded plain HTTP with an X-Forwarded-Proto: https header the app ignores. Tell the framework to trust its proxy: app.set("trust proxy", 1) in Express, SECURE_PROXY_SSL_HEADER in Django, trustProxies in Laravel, config.assume_ssl in Rails, AUTH_TRUST_HOST for Auth.js. If Cloudflare sits in front with SSL set to Flexible, change it to Full (strict). The other common loop is two layers redirecting in opposite directions, such as www to apex in one and apex to www in the other.

  • exit 137

    Fix deploy errorsNov 24, 2026

    Container killed with exit code 137: OOM or SIGKILL?

    Exit code 137 is 128 + 9: the process was killed with SIGKILL. In a container that usually means it went over its memory limit and the kernel's OOM killer stopped it, but docker kill and a docker stop that ran out of patience give 137 too. Check with docker inspect: State.OOMKilled is true only for a memory kill. Then make the app fit: cap Node's heap below the container limit with --max-old-space-size, run fewer Python workers or recycle them with max_requests, stream large data instead of loading it, and give the build its own memory budget, separate from the running app.

EthioDeploy

Agentic first development and deployment, started in Ethiopia, built for developers everywhere.

Telegram community
Product
PricingAI coding agentAgent mode docsDomainsCLIFree backend hostingHosting in EthiopiaChangelog
Deploy guides
Next.jsNode.jsPythonSvelteKitTanStack StartAstroNuxtReact RouterHonoStrapiPayload CMSDjangoFastAPIFlaskStreamlitExpressNestJSLaravelRailsGoSpring BootASP.NET CoreTelegram botDiscord botWhatsApp botLovableBoltReplitv0Google AI StudioBase44Firebase StudioClaude Code & Cursor
Compare
vs Herokuvs Vercelvs Rendervs Railwayvs Fly.iovs Netlifyvs KoyebHeroku alternativesVercel alternativesNetlify alternativesRender alternativesRailway alternativesFly.io alternativesReplit alternativesPythonAnywhere alternativesDigitalOcean App Platform alternativesGlitch alternatives
Resources
DocsBlogFree toolsAboutSupportContactllms.txt
© 2026 EthioDeployPay by card in USD or bank transfer in ETBTermsPrivacy