Geocoding performed server-side at creation, not client-side with exposed key
Why it matters
A geocoding API key embedded in client-side JavaScript is visible to any user who opens DevTools — this is CWE-522 (Insufficiently Protected Credentials) and an OWASP A05:2021 (Security Misconfiguration) violation. Exposed keys can be harvested and used by third parties to run geocoding requests against your quota, resulting in unexpected billing spikes or service denial when you hit rate limits. For Google Maps API keys, quota theft has caused five-figure surprise bills. CWE-200 (Exposure of Sensitive Information) applies because the key itself represents privileged access to a paid API service.
Severity rationale
Critical because an exposed geocoding API key enables quota theft and service disruption with zero authentication required — any user can extract the key from the browser.
Remediation
Move all geocoding calls to a server-side API route. The client never receives the API key — it only calls your own backend endpoint.
// src/app/api/geocode/route.ts (Next.js App Router)
export async function POST(req: Request) {
const { address } = await req.json();
const apiKey = process.env.GOOGLE_GEOCODING_API_KEY; // server-only env var
const res = await fetch(
`https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(address)}&key=${apiKey}`
);
const data = await res.json();
if (!data.results?.[0]) {
return Response.json({ error: 'Address not found' }, { status: 400 });
}
const { lat, lng } = data.results[0].geometry.location;
return Response.json({ lat, lng });
}
Ensure GOOGLE_GEOCODING_API_KEY is never prefixed with NEXT_PUBLIC_ — any NEXT_PUBLIC_ variable is bundled into client code. Compare with directory-map-location.geocoding.api-keys-restricted — server-side geocoding eliminates key exposure, but the key should still be restricted in Google Cloud Console.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Map & Location Integration Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-522 — Insufficiently Protected Credentials — geocoding API key exposed in client-side code
- cwe · CWE-200 — Exposure of Sensitive Information to an Unauthorized Actor
- owasp:2021 · A05 — Security Misconfiguration — API key accessible in browser bundle
Taxons
History
- 2026-04-18·v1.0.0·Initial import from directory-map-location·automated