Skip to content

fix(google-maps): static maps proxy, color mode, and bug fixes - #587

Merged
harlan-zw merged 5 commits into
mainfrom
fix/google-maps-improvements
Jan 18, 2026
Merged

fix(google-maps): static maps proxy, color mode, and bug fixes#587
harlan-zw merged 5 commits into
mainfrom
fix/google-maps-improvements

Conversation

@harlan-zw

@harlan-zwharlan-zw commented Jan 18, 2026

Copy link
Copy Markdown
Collaborator

🔗 Linked issue

Resolves#380, #83, #539, #540
Supersedes #516

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Google Maps had several pain points: CORS issues with static map placeholders when using crossOriginEmbedderPolicy, no way to switch map styles based on color mode, and MarkerClusterer types breaking builds when the package wasn't installed.

Added a server-side static maps proxy that serves images from same origin (fixing CORS) with caching to reduce API costs. The proxy keeps the API key server-side only and validates referer headers to prevent abuse. Added mapIds prop to switch between light/dark Map IDs reactively when color mode changes. Replaced top-level type imports with inline types so MarkerClusterer is truly optional. Also fixed PinElement memory leak and importLibrary cache not retrying on failure.

// Static maps proxy - API key stays server-side
scripts: {googleStaticMapsProxy: {enabled: true,cacheMaxAge: 3600}}
<!-- Color mode support -->
<ScriptGoogleMaps :map-ids="{ light: 'LIGHT_ID', dark: 'DARK_ID' }" />

@vercel

vercelBot commented Jan 18, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentReviewUpdated (UTC)
scripts-docsReadyReadyPreview, CommentJan 18, 2026 4:00am
scripts-playgroundReadyReadyPreview, CommentJan 18, 2026 4:00am

@pkg-pr-new

pkg-pr-newBot commented Jan 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nuxt/scripts/@nuxt/scripts@587

commit: b8cac43

Comment threadsrc/runtime/components/GoogleMaps/ScriptGoogleMaps.vue
- Add googleStaticMapsProxy config for CORS fixes and caching (#380, #83)
- API key stored server-side only (not exposed to client)
- Referer validation to prevent external abuse
- Add mapIds prop for light/dark color mode support (#539)
- Fix MarkerClusterer optional peer dep with inline types (#540)
- Add PinElement cleanup on unmount
- Fix importLibrary cache to retry on failure
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment on lines +31 to +35
const refererUrl = new URL(referer).host
if (refererUrl !== host) {
throw createError({
statusCode: 403,
statusMessage: 'Invalid referer',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constrefererUrl=newURL(referer).host
if(refererUrl!==host){
throwcreateError({
statusCode: 403,
statusMessage: 'Invalid referer',
try{
constrefererUrl=newURL(referer).host
if(refererUrl!==host){
throwcreateError({
statusCode: 403,
statusMessage: 'Invalid referer',
})
}
}catch(error){
// Re-throw Nuxt errors as-is
if(error&&typeoferror==='object'&&'statusCode'inerror){
throwerror
}
// Handle URL parsing errors
throwcreateError({
statusCode: 400,
statusMessage: 'Invalid referer URL',

The referer header URL parsing can throw an uncaught error if the referer is malformed, causing an unhandled exception instead of a proper HTTP error response.

View Details

Analysis

Unhandled URL parsing error in Google Static Maps proxy referer validation

What fails: The google-static-maps-proxy.ts event handler crashes with an unhandled TypeError when the referer header contains a malformed URL.

How to reproduce:

# Send a request with a malformed referer header
curl -H "Referer: this-is-not-a-valid-url" http://localhost:3000/api/google-static-maps

Result: Returns 500 Internal Server Error due to unhandled exception from new URL() constructor throwing TypeError: Invalid URL

Expected: Should return 400 Bad Request with proper error message, consistent with other validation errors in the function that use createError() for HTTP error responses

Details: The referer header can contain any string value from the HTTP request. When new URL(referer) is called without try-catch wrapping (line 31), it throws a TypeError for malformed URLs. According to JavaScript best practices, the new URL() constructor should be wrapped in error handling when parsing untrusted input.

@harlan-zw
harlan-zw merged commit 2f8ad9b into mainJan 18, 2026
10 checks passed
@harlan-zw
harlan-zw deleted the fix/google-maps-improvements branch January 18, 2026 05:38
@harlan-zwharlan-zw mentioned this pull request Jan 23, 2026
zizzfizzix pushed a commit to zizzfizzix/nuxt-scripts that referenced this pull request Mar 5, 2026
)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google maps static image and crossOriginEmbedderPolicy: "require-corp",

1 participant

@harlan-zw