Skip to main content
HighSecretsOWASP A07:2021CWE-798

How to fix: Mapbox secret token in source

sk.* Mapbox tokens grant upload / dataset access. Use pk.* for client.

Why it matters

An exposed Mapbox sk.* (secret) token grants write access to your datasets, styles, and tilesets: an attacker can modify or delete your map data, upload malicious content, and incur charges on your account. Public tokens (pk.*) are fine in browsers; secret tokens must stay server-side.

sk.* Mapbox tokens grant upload / dataset access. Use pk.* for client.

How to fix it

  1. 1Revoke the sk.* token in Mapbox Account → Tokens
  2. 2Use pk.* (public) tokens in client-side code
  3. 3Restrict the pk.* token by URL to prevent abuse by other sites

Code examples

Correct token usage: public token in browser

TypeScript
// Browser: use the public token (pk.*), restricted by URL
import mapboxgl from 'mapbox-gl';

mapboxgl.accessToken = process.env.NEXT_PUBLIC_MAPBOX_TOKEN!;  // pk.* token

// Server-only operations (uploads, dataset edits): use sk.* from env
// const secretToken = process.env.MAPBOX_SECRET_TOKEN;  // never NEXT_PUBLIC_*

References

Detected automatically by VulnRadar. The check id is secret-mapbox-secret-token, stable across every scan so you can filter or diff on it.

See every secrets check

Questions

How severe is Mapbox secret token in source?
VulnRadar rates this high severity in the secrets category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id secret-mapbox-secret-token, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Mapbox secret token in source map to?
It maps to CWE-798. In the OWASP Top 10 it falls under A07:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for mapbox secret token in source

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: Mapbox secret token in source | VulnRadar