Split into frontend and backend keys for Google Maps API usage#848
Conversation
| Dev/staging apps must not reach real external services. `fly-migrate.sh --secrets` enforces this automatically: | ||
|
|
||
| **Shared secrets** (copied to any app): `APP_KEY`, `AWS_*` (Tigris), `SENTRY_LARAVEL_DSN`, `MAPBOX_TOKEN`, `GOOGLE_API_CONSOLE_KEY`, `CALENDAR_HASH`, `SUPPORT_EMAIL_ADDRESS`, `REPAIRDIRECTORY_URL` | ||
| **Shared secrets** (copied to any app): `APP_KEY`, `AWS_*` (Tigris), `SENTRY_LARAVEL_DSN`, `MAPBOX_TOKEN`, `GOOGLE_MAPS_FRONTEND_KEY` , `GOOGLE_MAPS_BACKEND_KEY` , `CALENDAR_HASH`, `SUPPORT_EMAIL_ADDRESS`, `REPAIRDIRECTORY_URL` |
There was a problem hiding this comment.
I'd prefer to have different keys for different environments, as it's easier to manage keys, but this is fine for now.
|
Residual concern: HTTP referrer is unreliableHTTP referrer restrictions on the frontend key are imperfect. Modern browsers frequently strip or modify the Referer header in cross-origin requests for privacy reasons (depending on Referrer-Policy, browser version, and extensions), so a key restricted this way may still be usable from other origins. Alternative: full server-side proxy (no frontend key at all)A stronger approach is to eliminate the frontend key entirely by proxying the Google Places Autocomplete and Geocoding calls through authenticated Laravel endpoints:
Both endpoints sit behind the existing This works cleanly for restarters.net because:
Google's own security guidance confirms: for the Maps JavaScript API the key is inherently visible in source, but the Places and Geocoding APIs have REST interfaces that can be called server-side — keeping the expensive, per-request APIs completely off the frontend. This PR implements the key-split as a straightforward improvement. The full proxy approach would be a follow-on. |



We were using the same API key for both the client-side and server-side.
Google says 'Never use the same API key for client-side (mobile app, web app) and server-side applications.' (Google Maps Platform best practices: Restricting API keys – Google Maps Platform)
This allows us to restrict backend key via server IP address, and frontend key by HTTP referrer.