Skip to content

My Mapbox key leaked. What do I do?

Short answer

A public pk. token in your map is expected. Add URL restrictions so other sites can't use it on your bill. A secret sk. token must never be in client code: create a replacement on your Access Tokens page, swap it in, and delete the leaked token. Check Statistics for usage you don't recognize.

Last updated 2026-11-25 · Reviewed by ProofForge

Is it this key?

Format: Public pk. (public by design, restrict by URL). Secret sk. (server only, shown once). Temporary tk.

Blast radius: Public tokens are billed when used. Secret tokens can carry write scopes (uploads, styles, datasets, token management).

The first 10 minutes

WhenDoHow
0–3 minIdentifypk. means restrict. sk. means rotate now.
3–6 minRotateAccess Tokens page → create a new token with the same minimal scopes. Swap it into your app or server, then delete the old token.
6–8 minRestrictAdd URL restrictions to public tokens used on the web.
8–10 minCheck usageReview Statistics for the token and look for usage spikes.

Stop the next leak

  • Keep the key in a server-side env var. Never use a VITE_, NEXT_PUBLIC_ or EXPO_PUBLIC_ variable or hard-code it in frontend code.
  • Call the provider from your backend or an edge function, and add .env* to .gitignore.
  • Re-scan the live site after every deploy. Keys also leak through JS bundles, source maps and exposed .env or .git paths.

Check your live app

A free, read-only public-surface scan. It cannot diagnose private sessions or every cause described above.

Read-only. No writes or row contents.

FAQ

Do I need to rotate my pk. token?

Not unless it's being abused. Add URL restrictions.

Can I see a secret token again?

No. Secret tokens are shown once, so create a new one.

Does the default public token support URL restrictions?

Create your own scoped public tokens for production and restrict those.

Sources

Related

Read as Markdown · Scan methodology