diff --git a/.changeset/city-header-encoding.md b/.changeset/city-header-encoding.md new file mode 100644 index 000000000..410e98916 --- /dev/null +++ b/.changeset/city-header-encoding.md @@ -0,0 +1,5 @@ +--- +'@cloudflare/next-on-pages': minor +--- + +Fix: The city name for the location of the requester's public IP address must be encoded according to RFC3986. diff --git a/packages/next-on-pages/templates/_worker.js/utils/request.ts b/packages/next-on-pages/templates/_worker.js/utils/request.ts index 7138aac35..778b72733 100644 --- a/packages/next-on-pages/templates/_worker.js/utils/request.ts +++ b/packages/next-on-pages/templates/_worker.js/utils/request.ts @@ -10,7 +10,10 @@ export function adjustRequestForVercel(request: Request): Request { const adjustedHeaders = new Headers(request.headers); if (request.cf) { - adjustedHeaders.set('x-vercel-ip-city', request.cf.city as string); + adjustedHeaders.set( + 'x-vercel-ip-city', + encodeURIComponent(request.cf.city as string), + ); adjustedHeaders.set('x-vercel-ip-country', request.cf.country as string); adjustedHeaders.set( 'x-vercel-ip-country-region',