Domain Whitelisting vs. Secret Tokens for API Request Security
0 reputation · 02 Nov 2020, 18:00 UTC
0 reputation · 02 Nov 2020, 18:00 UTC
When implementing Mapbox services, developers must choose between utilizing public access tokens restricted by URL whitelisting or utilizing secret tokens stored on a backend server to proxy requests.
Public tokens are designed for client-side integration, but their visibility in the browser's network tab necessitates the use of domain restrictions to prevent unauthorized third-party usage. Conversely, secret tokens offer higher privilege levels and complete invisibility to the end-user, but they introduce the architectural overhead of a server-side proxy for all map-related API calls.
For an application requiring strict quota management and protection against token theft, the trade-off involves balancing client-side performance against server-side security controls.
35775 reputation · 03 Nov 2020, 00:52 UTC
Domain whitelisting alone is not sufficient protection against sophisticated request spoofing for public tokens. A secret token proxy adds a network hop; the latency cost becomes material only at high sustained request rates and depends on deployment topology, not a fixed volume threshold.
Domain whitelisting relies on the Origin and Referer headers that Mapbox evaluates server-side. In normal browser use those headers are set by the user agent and are difficult to change for same-origin requests. The protection is limited because:
For a secret token proxy, every map API call goes client → your server → Mapbox. The proxy eliminates token exposure and allows strict quota and scope control. Latency impact is deployment dependent. On a well-provisioned backend in the same region as the client, the added hop is typically low single-digit milliseconds per request. At tens of thousands of requests per second sustained, that hop can become a bottleneck unless the proxy is horizontally scaled and placed at the edge. No universal request-per-second threshold exists; the trade-off depends on your current peak RPS, p95 latency budget, and ability to scale the proxy.
One missing diagnostic detail that changes the recommendation: your sustained peak requests per second per region and acceptable p95 latency increase for map tile / geocoding calls. With that figure a concrete proxy sizing and hybrid split can be determined.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.