From c2b173ce89c82dd1566474191691bb5d62d01e67 Mon Sep 17 00:00:00 2001 From: Marco Jakob Date: Sun, 19 May 2024 22:57:11 +0200 Subject: [PATCH] Fix city header encoding (RFC3986) (#789) --- .changeset/city-header-encoding.md | 5 +++++ packages/next-on-pages/templates/_worker.js/utils/request.ts | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/city-header-encoding.md 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',