The NEXT_PUBLIC_MAPBOX_TOKEN environment variable is intentionally exposed to the client-side code. This is the correct implementation for Mapbox GL JS and is expected behavior.
Mapbox tokens are designed to be public and used in client-side applications. They are not sensitive secrets like database passwords or API keys for server-side services.
To properly secure your Mapbox token:
-
URL Restrictions: In your Mapbox account dashboard, restrict the token to specific URLs:
http://localhost:*(for development)https://yourdomain.com(for production)
-
Scope Restrictions: Limit the token to only the APIs you need:
- Maps API (required)
- Geocoding API (required for address lookup)
- Disable other APIs you don't use
-
Token Rotation: Regularly rotate your tokens and update them in your environment variables.
- Go to your Vercel project settings
- Navigate to Environment Variables
- Add
NEXT_PUBLIC_MAPBOX_TOKENwith your Mapbox public token - The
NEXT_PUBLIC_prefix is required for client-side access in Next.js
The following API keys should remain server-side only:
ASSEMBLYAI_API_KEY- Used only in the Python transcription serviceOPENWEATHER_API_KEY- Used only in the weather service- Redis connection details - Used only in backend services
- Never commit API keys to version control
- Use different tokens for development and production
- Monitor token usage in your provider dashboards
- Set up alerts for unusual API usage
- Regularly audit and rotate API keys
If you discover a security vulnerability, please report it to the project maintainers privately.